Pages

Monday, 23 March 2015

Programming with PIC Microcontroller: Chapter-1

INTRODUCTION

EMBEDDED SYSTEMS

PIC16F877A

Overview:

The PIC 16F877A PIC microcontroller is one of the most popular general purpose microcontrollers. It is of 8-bit which means the most available operations are limited to 8-bits.It is a 40-pin IC.


Ports:

There is one 6-bit ports: A , 3 8-bit ports: B ,C,D and one 3 bit port:E.

PORTA (Pin 2 to 7)and TRISA register :

PORTA is a 6-bit wide, bidirectional port. The corresponding data direction register is TRISA. Setting a TRISA bit ( = 1) will make the corresponding. PORTA pin an input (i.e., put the corresponding output driver in a High-Impedance mode).Clearing a TRISAbit (= 0) will make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the selected pin).Reading the PORTA register reads the status of the pins,whereas writing to it will write to the port latch.All write operations are read-modify write operations.Therefore, a write to a port implies that the port pins are read,the value is modified and then written to the port data latch.

PORTB(Pin 33 to 40)and TRISB register: 

PORTB is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISB. Setting aTRISB bit (= 1)will make the corresponding PORTB pin an input(i.e., put the corresponding output driver in a High-Impedance mode). Clearing a TRISB bit (= 0)will make the corresponding PORTB pin an output (i.e.,put the contents of the output latch on the selected pin).Three pins of PORTB are multiplexed with the In-Circuit.Debugger and Low-Voltage Programming function:RB3/PGM,RB6/PGC and RB7/PGD.


PORTC(pin 15 to 18 and pin 24 to 26)and TRISC register:

PORTC is an 8-bit wide,bidirectional port. The corresponding data direction register is TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input (i.e., put the corresponding output driver in a High-Impedance mode). Clearing a TRISC bit (= 0)will make the corresponding PORTC pin an output (i.e.put the contents of the output latch on the selected pin).PORTC is multiplexed with several peripheral functions PORTC pins have Schmitt Trigger input buffers. When the I2C module is enabled, the PORTC<4:3>pins can be configured with normal I2C levels, or with SMBus levels, by using the CKE bit (SSPSTAT<6>).When enabling peripheral functions, care should be taken in defining TRIS bits for each PORTC pin. Some peripherals override the TRIS  bit to make a pin an output, while other peripherals override the TRIS bit to make a pin an input.Since the TRIS bit override is in effect while the peripheral is enabled, read-modify writeinstructions (BSF, BCF, XORWF) with TRISC as the destination, should be avoided. The user should refer to corresponding peripheral section for the correct TRIS bit settings.



PORTD(Pin 19to22 and pin 27to30)and TRISD register:
 
PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output.PORTD can be configured as an 8-bit wide microprocessor port (Parallel Slave Port) by setting control bit, PSPMODE (TRISE<4>). In this mode, the input buffers are TTL.

PORTE(Pin8 to 10)and TRISE register: 

 
PORTE has three pins (RE0/RD/AN5,RE1/WR/AN6 and RE2/CS/AN7) which are individually configurable as inputs or outputs.These pins have Schmitt Trigger input buffers.The PORTE pins become the I/O control inputs for the microprocessor port when bit PSPMODE (TRISE<4>) is set. In this mode, the user must make certain that the TRISE<2:0> bits are set and that the pins are configured as digital inputs.Also, ensure that ADCON1 is configured for digital I/O. In this mode, the input buffers are TTL.PORTE pins are multiplexed with analog inputs. When selected for analog input, these pins will read as ‘0’s.