Hello Melanie,
you are very right. I have looked into the datasheet after my reply.
I was too overhasty - sorry!
Hello Melanie,
you are very right. I have looked into the datasheet after my reply.
I was too overhasty - sorry!
Appologies are unnescessary.
flotulopex reported that his LED blinks when he pushes the button, that's because there's only a 100mS Pause in the loop and you toggle the LED-ON, and with your finger still on the button, 100mS later you toggle it OFF, and with your finger still on the button, the LED toggles again 100mS later... etc etc until the end of time.
You need to ensure that once the LED toggles, it doesn't do so again until the Button is pressed anew. There are MANY, MANY ways of doing this. The example I posted simply waits for the user to remove his finger from the button before proceeding further.
Thank you Melanie,
Actually, it still doesn't work.
Each time I press the button, the Led lights up and as soon as I release the button, the Led switches off. At least, it doesn't blink anymore while the button is pressed.
It just doesn't want to toggle!
To make sure my button is correctly connected, is this schematic okay?
> Vdd-R10k-PORTB.3 and the button (normally open) is derived from PORTB.3 to Vss.
Since I can't make it work with this simple program, my last guess would be that my PIC is defect. I tried with other ports but there is no change. I shall receive another PIC tomorrow.
By the way, is there any utility tool to check the PIC's health?
Roger
MyButton var PortB.3
LED var PortB.4
TRISB = %00001000
Loop:
If MyButton=0 then
Toggle LED
While MyButton=0:Pause 100:Wend
endif
Goto Loop
End
Try the above and report back what the result is...
'PIC 16F84A
DEFINE OSC 4
TRISA = %000001
TRISB = %11111100
I VAR BYTE
PAUSE 200
MAIN:
IF PORTA.0 = 1 then SWITCH_LED
goto main
SWITCH_LED: IF PORTA.0 = 0 THEN SWITCH_LED_INSTANT
FOR I = 0 TO 10
IF I < 10 AND PORTA.0 = 0 THEN SWITCH_LED_INSTANT
PAUSE 100
NEXT I
IF PORTA.0 = 1 THEN SWITCH_LED_DELAY
goto main
SWITCH_LED_DELAY: TOGGLE PORTB.0
PAUSE 10
AVOID_LED_BLINK: IF PORTA.0 = 1 THEN AVOID_LED_BLINK
PAUSE 10
GOTO MAIN
SWITCH_LED_INSTANT: TOGGLE PORTB.1
PAUSE 10
GOTO MAIN
I'm also a new one with de pic chips, can I use this also for a 16F628A chip??
grz Jan
Hello Melanie,
Your piece of code didn't work until I... grounded PORTB.2.
So I tried my code and it worked well too.
I didn't expect this component to be so sensible to the electric field around the pins.
I won't forget this lesson, for sure ;-)
Roger
If you are meaning "can you use the button command with the 16f628a chip, then the answer is yesOriginally Posted by JARI NETWORKS
![]()
Bookmarks