Thursday, January 15, 2009

All LED Blinking Program RA4 not Blinking solution .

Previous Tutorial

If you execute the previous program it will work fine except that RA4 wont blink .A quick search showed me that I need to make some extra register configurations with ADCON1 and COMCON registers .

ADCON1 = 0x06 makes all the pins of PORTA as Digital .
COMCON=0x07 disables the comparators

So the rectified program is below .
void main (){

ADCON1 =0x06 ; // Changes PORTA to digital
CMCON = 0x07 ; // Disable analog comparators
PORTA = 0x00 ;
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) ;
}
}
Now all this is rectified .The LED's should blink fine .If you think so you are fooled for the second time .Even this program wont make RA4 blink .You need to pull RA4 high in order to make it blink .I am sure you will run into this problem if you are using PORTA .Hope my post helped you .Please leave your valuable comments if you like my blog and a link back if you find it worthy .

4 comments:

janos said...

Hi there,

Great post, found what I am looking for, I'd just have a few questions.
First of all can you please tell me what compiler should I use in order to be able to compile your code fo a pic16f628 controller. I have Hi tech c and mplab installed, will these work?
Thanks and luts of luck,
Janos

Arun Vijay said...

Hi janos,
you can use Mikroc compiler. It can be downloaded from the following link

http://www.mikroe.com/en/compilers/mikroc/pic/

Just set the device as 16f628 and compile the code.

Anonymous said...

Интересно написано....но многое остается непонятнымb

Unknown said...

hi
i want to ask. can i use one pin from port A as an input analog pin, and the rest from port A as digital input?
if i can, what are the code to do that? thank you