Thursday, January 15, 2009

PIC16F877 All Led Blinking Program

Have you ever tried the Hello World of Embedded programming ,well I am talking about the LED Blinking program .Well if you have worked with PIC microcontrollers most probably it must have been your first program . My guess is you must have tried it in any 1 one of the pins .(I am talking all this assuming that you are either using PIC16F877,PIC16F877A or PIC16F874A they are all pretty much the same ) .


Only today when I was testing the PIC16f877/877A/874A Development board that I developed I was stuck up with a peculiar problem .I was trying LED blinking program in all the ports simultaneously .And everything worked fine except for RA4 .The LED connected to it didnt blink .It is the 6th pin and remember it iis an ADC outcast :P .Well being in PORTA where the rest of the pins have a inbuilt ADC this pin doesnt have one so I consider it as so .But it serves as a Vref to the comparator .

I wrote this simple program to make all the led's blink in My dev board .

void main (){
PORTA = 0; // Initialize PORTA
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
TRISA = 0x00; // Configure PORTA as output
TRISB = 0X00 ;
TRISC = 0X00 ;
TRISD = 0X00 ;
TRISE = 0X00 ;

while(1){
PORTA = 0XFF ;
PORTB = 0XFF ;
PORTC = 0XFF ;
PORTD = 0XFF ;
PORTE = 0Xff ;
Delay_ms(500) ;
PORTA = 0X00 ;
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
Delay_ms(500) ;
}
}

If you think this will work , you are in for a surprise .Check out the next post for the answer .


1 comment:

Anonymous said...

Please, post a example with ds1307 RTC and a example with ds1820 (dallas temperature sensor).
Very good work! Tanks from Brazil!