Page 1 of 1

Switch not working!!

PostPosted: Thu Mar 06, 2014 1:58 pm
by hokelvin66
it a silly question and this is pretty annoying to me.i wish to light up led on SK28 using PIC182550 using button (RB0) on the board,however there didn't show any output.

the code:
CODE: SELECT_ALL_CODE
//Turn on LED using button using PIC18f2550 using SK28

#include <p18f2550.h>

#pragma config FOSC=HS             
#pragma config WDT=OFF             
#pragma config MCLRE=ON             
#pragma config BOR=OFF               
#pragma config PWRT=ON             
#pragma config LVP=OFF

#define LED  RB1
#define SW   RB0

void main (void)
{
  PORTB=0;
  TRISB=0x01;

  if(SW==0) LED=1;
  else      LED=0;
}

Re: Switch not working!!

PostPosted: Thu Mar 06, 2014 5:16 pm
by ober
Have you test the LED blinking with your program? Just curious, what type of compiler are you using?

Re: Switch not working!!

PostPosted: Thu Mar 06, 2014 5:23 pm
by yonghui
try put a forever loop in main program loop.

void main (void)
{
PORTB=0;
TRISB=0x01;

while(1)
{
if(SW==0) LED=1;
else LED=0;
}
}

Re: Switch not working!!

PostPosted: Thu Mar 06, 2014 6:18 pm
by hokelvin66
thx for the reply :D
1)i using C18-compiler and the LED blink
2)i had try the loop but doesn't work either.

Re: Switch not working!!

PostPosted: Fri Mar 07, 2014 9:50 am
by yonghui
u compiled and load the hex to the board using pickit2 and pickit2 GUI?

Re: Switch not working!!

PostPosted: Fri Mar 07, 2014 10:18 am
by hokelvin66
yea,i using PICKIT2 (UIC00B) :D

Re: Switch not working!!

PostPosted: Fri Mar 07, 2014 12:50 pm
by hokelvin66
ok,now i had solve my problem by adding "ADCON1=0xFF" and it's work.Thx for the reply ^^ :lol: