Wednesday, August 3, 2011

PIC Programs 02: Accessing individual pins in a port

In most programs we are performing port I/O as a whole i.e. we used to read or write to an entire port. This definitely a very efficient practice and is also fast. But is some simple programs with no speed and efficiency constraints, it is better to access individual I/O pins. This will reduce the coding time considerably. The program given below illustrates the use individual I/O pin accessing.


The program is written for PIC16F877A and is to be compiled with HI-TECH C compiler. The program does the function of input/output mapping. The state of portb.6 is made same as that of the input at portb.7. It is recommended that you  build PIC essential circuit for testing this program.





#include <htc.h>


main()
{
    TRISB= 0b10000000 ; // declare portb.7 as input pin and potb.6 to portb.0 as output pins
    
     while(1)
        RB6=RB7;    // input output mapping
        
}




Download the program file

1 comments:

Anil said...

For proper functioning set the configuration bits to 3F7A.

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes