Switch not working!!

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

Switch not working!!

Postby hokelvin66 » Thu Mar 06, 2014 1:58 pm

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;
}
hokelvin66
Novice
 
Posts: 22
Joined: Mon Jan 14, 2013 7:49 pm

Re: Switch not working!!

Postby ober » Thu Mar 06, 2014 5:16 pm

Have you test the LED blinking with your program? Just curious, what type of compiler are you using?
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: Switch not working!!

Postby yonghui » Thu Mar 06, 2014 5:23 pm

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;
}
}
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Switch not working!!

Postby hokelvin66 » Thu Mar 06, 2014 6:18 pm

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.
hokelvin66
Novice
 
Posts: 22
Joined: Mon Jan 14, 2013 7:49 pm

Re: Switch not working!!

Postby yonghui » Fri Mar 07, 2014 9:50 am

u compiled and load the hex to the board using pickit2 and pickit2 GUI?
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Switch not working!!

Postby hokelvin66 » Fri Mar 07, 2014 10:18 am

yea,i using PICKIT2 (UIC00B) :D
hokelvin66
Novice
 
Posts: 22
Joined: Mon Jan 14, 2013 7:49 pm

Re: Switch not working!!

Postby hokelvin66 » Fri Mar 07, 2014 12:50 pm

ok,now i had solve my problem by adding "ADCON1=0xFF" and it's work.Thx for the reply ^^ :lol:
hokelvin66
Novice
 
Posts: 22
Joined: Mon Jan 14, 2013 7:49 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 2 guests