PICMicrocontroller

16F877A

Input/Output
• Pins can be assigned as analog input, digital input or digital output

Pinout

Port A

Port A
Has 6 pins RegisterAbit0 to RegisterAbit5 (RA0-RA5) AnalogInput0 to AnalogInput4 (AN0-AN4) RA0-RA5 can be used as digital inputs RA0-RA5 can be used as digital outputs AN0-AN4 can be used as analog inputs

Port B

Port B
Has 8 pins RB0-RB7 can be used as digital inputs RB0-RB7 can be used as digital outputs External interrupt pin on RB0 External port interrupt on RB4-RB7

Port C

Port C
Has 8 pins RC0-RC7 can be used as digital inputs RC0-RC7 can be used as digital outputs PWM (Pulse Width Modulation) is possible on RC1 AND RC2 Port C contains USART (Universal Synchronous - Asynchronous Receiver Transmitter) for serial communication

Port D

Port D
Has 8 pins RD0-RD7 can be used as digital inputs RD0-RD7 can be used as digital outputs

Port E

Port E
Has 3 pins RE0-RE2 can be used as digital inputs RE0-RE2 can be used as digital outputs AN5-AN7 can be used as analogue inputs

Port Map

Internal Connection

EPROM
The memory where the program you write is stored in. The program you write is 'compiled' by your computer to binary code and then downloaded into the Flash memory of the PICmicro. The Flash memory of the 16F877 can store up to 8000 program commands.

RAM
RAM is the memory where the 'variables' you declare are stored in. This memory is of the RAM-type. It is erased every time the power gets cut or a reset occurs. The RAM of the 16F877A can store up to 368 bytes of data.

EEPROM
Sometimes referred to as 'Flash' memory. EEPROM is the memory where the variables can be permanently stored This memory is of the PROM-type. It is preserved every time the power gets cut or a reset occurs. The EEPROM of the 16F877A can store up to 256 bytes of data.

ALU
The ALU (Arithmetic Logic Unit) is the heart of the PICmicro. Everything passes through this unit. The program in the Flash memory tells the ALU what to do. The ALU can send data to, and fetch data from all the separate blocks and Ports in the PICmicro by the 8-bit wide data-bus. The ALU needs 4 external oscillator clock pulses to execute one whole instruction.

TMR1
This timer interrupt is used to provide the PICmicro with exact timing info. It is clocked by the system clock or by an external clock on RC0. This system clock runs exactly 4 times slower than the external oscillator clock. Either the external clock or the system clock can be divided by 1, 2, 4 or 8 by configuring the Prescaler of TMR1 in Flowcode. This divided clock triggers the TMR1 to increment the TMR1 register. This TMR1 register is an 8-bit register and will have an overflow when it reaches 256. he exact moment when this overflow occurs, TMR1 generates an interrupt and the TMR1 register is set back to 0. This TMR1 Interrupt will stop the main program immediately and start up the TMR1 Macro. After the TMR1 Macro is finished, the main program goes further where it had left before.

Example
External clock oscillator = XTAL : 19.660.800Hz System Clock = /4 : 4.915.200 Hz Set prescaler to 8 = /8 : 614.400 Hz Overflow when TMR1 = 256 = /256 : 2400 Hz Conclusion: In this situation, TMR1 will interrupt the main program and execute the TMR1 Macro 2400 times per second.

TMR0
This timer interrupt is used to provide the PICmicro with exact timing info. It is clocked by the system clock or by an external clock on RA4. This system clock runs exactly 4 times slower than the external oscillator clock. Either the external clock or the system clock can be divided by 1, 2, 4 or 8, 16, 32, 64, 128, or by 256 by configuring the Prescaler of TMR0 in Flowcode. This divided clock triggers TMR0 to increment the TMR0 register. This TMR0 register is an 8-bit register and will have an overflow when it reaches 256. he exact moment when this overflow occurs, TMR0 generates an interrupt and the TMR0 register is set back to 0. This TMR0 Interrupt will stop the main program immediately and start up the TMR0 Macro. After the TMR0 Macro is finished, the main program goes further where it had left before.

Example
Example: External clock oscillator = XTAL : 19.660.800Hz System Clock = /4 : 4.915.200 Hz Set prescaler to 256 = /256 : 19200 Hz Overflow when TMR0 = 256 = /256 : 75 Hz

RB0 External Interrupt
A logic level change on RB0 can be configured to generate an interrupt. It can be configured in Flowcode to react to a rising or to a falling edge on RB0. When it is set to react to a rising edge and a rising edge occurs at RB0 then:
This will immediately stop the main program The RB0 related macro is executed After this RBO macro is executed, the main program goes further where it had left before.

This will happen every time a rising edge is detected at pin RB0

PORT B External Interrupt
A logic level change on either RB4 or RB5 or RB6 or RB7 can be configured to generate one and the same single interrupt. It can not be configured to react to a rising or to a falling edge. It is triggered by both rising and falling edges. When it is configured in Flowcode and a level change occurs on either of these 4 input pins of Port B:
This will immediately stop the main program The PORTB related macro is executed After this PORTB macro is executed, the main program goes further where it had left before.

This will happen every time a level change is detected on one of the 4 MSB's of PORTB

A/D Conversion
This 16F877A PICmicro Microcontroller has 8 pins that have an extra A/D function. This PICmicro controller has only one single 10-bit A/D converter. This implies that these 8 Analogue inputs can't all be read at the same time. A built in analogue switch is the answer to this problem. In Flowcode you can select witch of the 8 analogue inputs you want to sample. After this 'sample' instruction, the analogue switch is set to the correct input and this analogue input is converted to a 10-bit binary value. In Flowcode, you can select to only use the 8 MSB's of this 10-bit value by using the 'ReadAsByte' instruction, or you can select to use the full 10 bits by selecting the 'ReadAsInt' instruction. The 10 bits will fill up the 10 LSB's of the selected 16-bit integer variable. After this, you can select an other analogue input that needs to be read.

Busses
A PICmicro is a typical Harvard-type Microcontroller. This means that there is a separate bus for Instructions and one for Data. The data bus is 8-bit wide and connects every block and port together. The instruction bus is 14 bit wide and transports 14 bit long instructions from the program memory to the ALU.

Sign up to vote on this title
UsefulNot useful