Hiển thị các bài đăng có nhãn PIC16F877A. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn PIC16F877A. Hiển thị tất cả bài đăng

Thứ Hai, 17 tháng 11, 2014

PIC16F877A I/O PORTs PROGRAMMING

I/O PORT PROGRAMMING IN PIC16F877A
    •  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.
PORT AND TRIS REGISTER
    •  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.
EXAMPLE TO OBSERVE THE STATUS OF OUTPUT PORT.
    •      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:



  • For detail description about PIC16F877A’s PORT & TRIS registers, please refer to its datasheet from Microchip webpage:
  • In next articles, we will practice about I/O programming by building more LED flashing programs with PIC MCU and push button..

  •