PIC18F4550 problem, Please help!!!!

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Re: PIC18F4550 problem, Please help!!!!

Postby ABSF » Sun Jan 08, 2012 12:09 pm

CODE: SELECT_ALL_CODE
#define   sw1         PORTBbits.RB0   // sw1 defined as input for SW1 on MB00

void main(void)
{
TRISA=0xFF;
TRISB=0xFF;
TRISC=0x00;
TRISD=0x00;
LATC=0x00;
LATD=0x00;

for(;;)
{
   if(sw1==1)
{
LATC++;
}
   else if (PORTA!=0x00)
{
LATD++;
}
}          //for end
}          //main end


change to above and it will work. You also need a 10K resistor to GND at the junction of your switch and input port.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PIC18F4550 problem, Please help!!!!

Postby robosang » Sun Jan 08, 2012 9:31 pm

CODE: SELECT_ALL_CODE
TRISA=0x0FF;
TRISB=0x0FF;
TRISC=0x00;
TRISD=0x00;
PORTC=0x00;
PORTD=0x00;
for(;;)
{
if(PORTBbits.RB0==1)
{
PORTC++;
}
else if (PORTA!=0x00)
{
PORTD++;
}
}

Too fast! Put some delay in the if statement.

Also Port A is normally share with Analog input, by default they are analog input, so you will have problem using as digital input if it is not configured properly.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Previous

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 0 guests

cron