PDA

View Full Version : Simple problem?



FastEddie
- 2nd March 2007, 06:23
Hi,
I can't figure out what I'm sure is a simple solution to my problem. I have a NO button that I am trying to just turn on/off an led. I'm using PicBasic (not the pro version) and a 16F818 chip. I've attached my schematic and my code follows. My problem is: when I first power up LEDa and LEDb light up, and when I push the button LEDb turns off and LEDa stays on. My code has nothing to do with LEDb (B1), yet pushing the button affects it. And LEDa stays on constantly. Here's my code:

POKE $8F,%01100000 'SET CLOCK SPEED @4MHZ
SYMBOL TrisB=$86 'PortB data direction Address
SYMBOL PortB=$06 'PortB Pin Address
SYMBOL led=Pin0
SYMBOL pb=Pin7

Poke TrisB,128 'portB 0 to 6 outputs, 7 input

Poke PortB,0 'All off to start
Pause 1000

Start:
If pb=1 then light '??
LOW led 'LED off
GOTO Start 'Return to start

light:
High led 'LED on
GOTO Start 'Return to start

END

Thanks in advance,
Ed

paul borgmeier
- 2nd March 2007, 07:13
High Pin0 is not allowed (or in your case High led) – it must be
High 0 (see manual)

The same goes for Low command

Let us know ...

mister_e
- 2nd March 2007, 16:36
make sure of your config fuses setting, LVP mode must be disabled, and you must select the internal OSCillator as well.

once done, you must set the internal OSC to 4MHZ, by default it's 32KHz... pretty slow...

Poke $8F, $60

i don't know if PBC support the configuration fuse setting, but you could add the following at the top of your code to see if it return you any error..


@ DEVICE PIC16F818, INTRC_OSC_NOCLKOUT
@ DEVICE PIC16F818, WDT_OFF
@ DEVICE PIC16F818, MCLR_ON
@ DEVICE PIC16F818, BOD_ON
@ DEVICE PIC16F818, LVP_OFF
@ DEVICE PIC16F818, CPD_OFF
@ DEVICE PIC16F818, WRT_OFF
@ DEVICE PIC16F818, DEBUG_OFF
@ DEVICE PIC16F818, CCPMX_OFF
@ DEVICE PIC16F818, PROTECT_OFF

paul borgmeier
- 2nd March 2007, 17:44
He is all set with the Poke $8F, $60 (his first line of code is this)

You cannot use @ Device as Steve noted but the workaround is documented here in posts 34 and 35 here

http://www.picbasic.co.uk/forum/showthread.php?t=543

Best,

mister_e
- 2nd March 2007, 18:07
He is all set with the Poke $8F, $60 (his first line of code is this)

http://www.mister-e.org/Pics/DOH

FastEddie
- 3rd March 2007, 18:28
Thanks paul and mister e for answering. I did what paul said and it worked. I guess I thought when I used SYMBOL I could reference it using that. I should've read the book.

Thanks again,
Ed