sorry did I make someone mad or is this not possably
It's definitely possible, but not quite the way you are trying it.
Take a look at your loops "CHECK" and "THR". After a 1mS pause you go right into the first one and you will wait there FOREVER if CT never happens. Same for the second one.
Your counter "For A =" is NOT incrementing while you are stuck in those nested loops. Remember that those instructions don't multitask. Only one instruction will happen at a time.
You aren't too far off, but things are not in the right sequence. Try doing a flowchart of your code first.
P.S. The PIC does not need 20 seconds to "stabilize"! Heavens to Mergatroid! Only your grandpa's TV ever needed that kind of warm-up. LOL.
I haven't tested it, and it can surely be done more elegantly, but this should be a little closer to what you are attempting....I did not check to see if you are initializing the registers correctly.
SYMBOL HORN = GPIO.0 'FAULT HORN
SYMBOL CT = GPIO.2 'CT PIN 5 (TRIPS LOW)
SYMBOL LED = GPIO.5 'LED PIN 2
A VAR WORD
EVENT VAR BYTE
HORN =0
LED =0
EVENT =0
MONTIOR:
IF CT = 0 Then FAULT
GoTo MONTIOR
FAULT:
LED = 1
Pause 5000
LED = 0
CHECK:
For A = 0 TO 60000
Pause 1
IF CT = 0
GOSUB FAULT_AGAIN
ENDIF
Next A
EVENT = 0
GOTO MONITOR
FAULT_AGAIN:
EVENT = EVENT + 1
IF EVENT = 2 THEN THR
SEC:
LED = 1
Pause 5000
LED = 0
RETURN
THR:
HORN = 1
Pause 5000
HORN = 0
EVENT = 0
GoTo MONTIOR
Although I haven't tried it, the following code should work.
It uses no pauses whatsoever.
' Set up timer1 for /8 prescaler
T1CON = %00110001
TOP:
IF PIR1.0 = 1 THEN
PIR1.0 = 0
TMR1H = $D
TMR1L = $CF
Hcounter = Hcounter + 1
IF Hcounter.0 = 0
GOSUB DOTHEWORK
ENDIF
ENDIF
If Button1 = 0 THEN SecCounter = 60
IF Button2 = 0 THEN BTN2 = 1
IF Button3 = 0 THEN BTN3 = 1
GOTO TOP
DOTHEWORK: ' Gets here exactly once per second
IF BTN2 = 1 AND SecCounter > 0 THEN
LEDFLAG = 1
ENDIF
IF BTN3 = 1 AND BTN2 = 1 AND SecCounter > 0 THEN
HORN = 1
ENDIF
IF LEDFLAG = 1 THEN
TOGGLE LED
ENDIF
IF SecCounter > 0
SecCounter = SecCounter -1
ENDIF
Return
Bookmarks