
Originally Posted by
yankee
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:
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
I would change the pauses in case you need to interrupt the code,
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.
Bookmarks