PIC18F452- First time with development board

Thread Starter

AustinCann

Joined Jan 30, 2011
12
I had been using only the software debugging mode in the past. Today it was the first day on the development board. I got the board LEDS blinking. However when I wanted to make them blink on button input on development board, it simply did not work. I think I am probably not setting all registers. Here is the simple program I used:

void main(void)
{
TRISA=0XFF;
TRISC=0X00;
while (1)
{
if (PORTA==1)
{
delay_ms(10);
PORTC=0XFF;
delay_ms(1000);
PORTC=0X00;
}
}
}
Does it have to do something with ADCON0 and ADCON1 register?- I used RA4 (digital input on POR) and PORT D, but never got the LEDS blinking on input.
Thanks
 

Markd77

Joined Sep 7, 2009
2,806
I don't know much C but I think this line
if (PORTA==1)
is checking for 00000001 on PORTA.
If there is anything connected to any of the pins apart from RA0 that could be the problem.
 

Thread Starter

AustinCann

Joined Jan 30, 2011
12
I am doing it on the development board and all port pins are connected to buttons as active low. Without state of change, I reckon it wont make difference.
 

Tahmid

Joined Jul 2, 2008
343
Hi,
This is because PORTA is multiplexed to ADC as well. By default, the pins are analogue. To check for switch, the pin has to be digital. To make it digital add the line:
Rich (BB code):
ADCON1=7;
or
Rich (BB code):
ADCON1=6;
This tells the microcontroller to make all ADC-multiplexed inputs digital.
You can place this before or after you set the direction of the port by writing to TRIS. Just write this before you use the pin.

Hope this helps.
Tahmid.
 
Top