How would I program and wire a circuit to use a toggle switch on RA5? I've been unable to get it to work.
~ Dave
How would I program and wire a circuit to use a toggle switch on RA5? I've been unable to get it to work.
~ Dave
Hi Dave, . . . use a toggle switch . . . do you mean as an input or toggle as an output ? This chip will not output on RA5, so I will assume as an input. A simple if then loop to check port status will do fine. Schmitt trigger has higher and lower readings than TTL to switch say 1volt and 4 volt as opposed to about 1/2 supply voltage.
Code:IF PortA.5 THEN
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
I haven't tried this yet. Does this look like it will work?
Code:@ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off TRISA = %00000100 ' Make all port a pins inputs except for 5 TRISB = %00000000 ' Make port b pins outputs B15 VAR PORTB.7 switch: if porta.5 = 0 then cal if porta.5 = 1 then main goto switch cal: low B15 pause 3000 ' pause 3 seconds HIGH B15 pause 3000 if porta.5 = 0 then cal goto switch main: IC performs main routine
I would probably do as follows:
I would change the pauses in case you need to interrupt the code,Code:@ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off PortA = %00000000 ' set ports to known state PortB = %00000000 ' outputs will initialize in low state TRISA = %00100000 ' Make all port a pins outputs except for 5 TRISB = %00000000 ' Change PortB from HI Q to Outputs that will initialize low i VAR BYTE ' counter variable cmcon = 7 ' disable comparators Switch: IF PortA.5 = 1 THEN Main PortB.7 = 0 FOR i = 1 TO 30 pause 100 ' pause 100 ms 30 times NEXT i PortB.7 = 1 FOR i = 1 TO 30 pause 100 NEXT i GOTO Switch main: ' do your main stuff here goto switch ' go back to switch and check end
and remove redundant loops
Last edited by Archangel; - 12th March 2009 at 17:05.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Thanks Joe! That worked really slick. Now, I just have to figure out why your code works so well. I could definitely use a code for Dummies book. I'm not understanding the "FOR i = 1 TO 30."
~ Dave
Bookmarks