- PIC 116F877A has 40 pins, 33 pins are set as 5 Input/Output ports: PORTA, PORTB, PORTC, PORTD and PORTE.
- PORTA has 6 pins, PORTB/PORTC/PORTD has 8 bins while PORTE has 3 pins.
- Each port of PIC16F877A has some others functions, such as ADC, Interrupts, Timers, Serial Communication…
- Each port can be configured as input or output by setting to its corresponding TRIS register.
- In this article, I will talk about PIC16F877A Digital I/O function first.
- The data direction is depended on TRIS register. Each Port has its corresponding TRIS, i.e: PORTA & TRISA, PORTB & TRISB…
- Setting an TRIS bit to logic 1 will make the corresponding PORT pin an Input.
- Setting a TRIS bit to logic 0 will make the corresponding PORT pin an Output.
- Reading the PORT register reads the status of that PORT (pins), whereas writing to it will write to the port latch.
- In this example, we will build a simple circuit to test the output function of PIC16F877A’s PORT. Please refer the following schematic:
- Now we set RB0 as an output, then send the logic 1 to turn on the LED and toggle it after every 500ms. The code below is writing in C language. After compiled, we send the Hex file to PIC via ICSP port (by any programmer you have).
- Turn on/off the LEDs after 500ms:
- LED "running" effect:
- Let's combine 3 programs above into one and see the result:
0 nhận xét:
Đăng nhận xét
Xin để lại bình luận của bạn về bài viết này.
Please give me your comment for this post.