I'm a beginner too. I had also problems to query PORTA. The tip with CMON=7 was the solution. Steve, thank you very much!Originally Posted by mister_e
_______________
Regards
Johann
I'm a beginner too. I had also problems to query PORTA. The tip with CMON=7 was the solution. Steve, thank you very much!Originally Posted by mister_e
_______________
Regards
Johann
Last edited by homebrewer; - 22nd August 2006 at 00:00.
Attention fellow newbies:
Here's what I learned the hard way, twice!
When your button code calls a LABEL,
put that labeled code in the very next line after your button code,
or you get nasty error codes assuring you that it is not really a label.
I ran into this in a program with several sub routines and several buttons
and the only way it would compile was if I put the subs directly after the button.
I can't make it work with the BUTTON command.
So I tried the other way and use the simple IF..THEN command.
But again, I have the same unexpected result. The Led starts to blink when I press the button. As I release the button, it never "toggles" as I want it to do.
Since this program behavior is the same in both cases (BUTTON and IF..THEN commands), I assume something is wrong with some register settings.
I was thinking about a bouncing problem, but I'm not sure about that.
Here is my code; where do I miss something?
'PIC 16F88
'Button is on PORTB.3 (Pin 9) Pressed = 0V
'Led is on PORTB.4 (Pin 10)
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISB = %00001000 'RB3 is an Input, all others are Outputs
'----------------------------------------------------------------
' IF..THEN
MAIN:
IF PORTB.3 = 0 then SWITCH_LED
goto main
SWITCH_LED:
pause 100 'Debounce
toggle PORTB.4
goto main
end
'----------------------------------------------------------------
' BUTTON
'BVar var byte
'BVar = 0
'
'MAIN:
' BUTTON 9, 0, 255, 255, BVar, 0, SWITCH_LED
' goto main
'
'SWITCH_LED:
' pause 100 'Debounce
' toggle PORTB.4
' goto main
END
Roger
MAIN:
IF PORTB.3 = 0 then SWITCH_LED
goto main
SWITCH_LED:
pause 100 'Debounce
toggle PORTB.4
goto main
So what happens above when you keep your finger pressed on the button for longer than 100mS? Your LED will keep toggling every 100mS...
Try this...
MAIN:
IF PORTB.3 = 0 then SWITCH_LED
goto main
SWITCH_LED:
pause 100 'Debounce
toggle PORTB.4
While PortB.3=0:Wend ' Wait here for Button to be released
goto main
' Try CMCON=7 as mister_e has stated in reply#3
' now you can query input pins
' from this point it's up to you, how your led should work
CMCON=7
MAIN:
IF PORTB.3 = 0 then SWITCH_LED
goto main
SWITCH_LED:
pause 100 'Debounce
toggle PORTB.4
goto main
end
' Regards
' Johann
Hello Melanie,
you are very right. I have looked into the datasheet after my reply.
I was too overhasty - sorry!
Bookmarks