#rem Alarm_Receiver2019.BAS This is for the wood cube with the speaker
The Receiver gets a 433 Mhz signal from the gate transmitter or the 6-button Transmitter
The main loop of 1/10 sec times LED on duration, blinking and flashing
The command codes accepted are in Rcvr_Val and have correspondinf OpCodes as inteces to the parameter tables in EEPROM:
e:0 Lights blue LED
D:1 Lights green LED
A;2 Lights red LED
H:3 Turns off the LEDs
Q:4 Lights red LED and plays Gate Open tun
B:5 Lights green LED and plays Gate Closed tune
h:6 Flashes red LED and plays Siren tune
s: A message has been received from the Solar Transmitter an Current is valid
If current exceeds MinCurrent then these OpCodes are set:
7: Battery is high, green LED
8: Battery is standard, blue LED
9: Battery is low. red LED
These are OpCodes not producing results:
z:122 Invalid interrupt
11 Idle
John Saunders1/12/2019
#endrem
#PICAXE 14M2
'Input Ports
symbol Rcvr_In = B.1 'Idle low
symbol Batt_Mon = B.2 '1/2 of the battery voltage
symbol Chg_Mon = B.3 '1/4 of the charging voltage
symbol Reg_Err = pinC.3 'Goes low if the 5V regulator drops below 5V
'Output Ports
symbol Outport = B.0
symbol Aud_Cont = B.4
symbol Aud_Tune = B.5
symbol Red_LED = C.1
symbol Green_LED = C.2
symbol Blue_LED = C.4
'Variables
'Interrupt variables
symbol Temp = b1
symbol Chcksum = b2
symbol ChckHex = b3
symbol LenCode = b4
symbol Current = b5
symbol Rcvr_Val = b6
symbol RcvrCnt = b7
'Specific variables
symbol SolarEvent = bit0 'Current greater than MimCurrent
symbol State = b10
symbol Loop_Cnt = b11 'Count of main loop of 1/10 sec
symbol DataAddr = b12
symbol Tune_Indx = b13 'Index into the tune branch table; 0 - 9
symbol OpCode = b14 'Index into parameter tables
symbol Batt_Mv = w13 'ADC output
symbol BattVolts = w12
'General variables
symbol Scratch = b17
'Constants
symbol Ref_Volts = 750 '1.2 volts/cell
symbol Lo_Volts = 719 '1.15 V/cell
symbol Min_Volts = 563 '0.9 volts/cell
symbol MinCurrent = 5 'Received MA to flash
symbol Idle = "O"
symbol Invalid = "z"
symbol OpcodeMax = 9
rem EEPROM tables:
rem Blue,green,red LED.1 is lit
DATA 0,(1,0,0,0,0,0,0,0,1,0)
DATA 20,(0,1,0,0,0,1,0,1,0,0)
DATA 40,(0,0,1,0,1,0,1,0,0,1)
rem LED on duration in loops:
DATA 60,(50,50,65,0,199,100,100,4,3,4)
rem Tune index , 0 is no tune
DATA 80,(0,0,0,0,2,5,4 ,0,0,0)Init:
Init:
SETFREQ m8
LOW Aud_Cont
LOW Aud_Tune
LOW Outport
LET Rcvr_Val = "e"
LET State = 0
LET SolarEvent = 0
SETINT %00000001,%00000001 'Interrupt when Rcvr_Int high
Main:
SELECT State
CASE 0
rem Solar transmission received
IF SolarEvent = 1 THEN
FVRSETUP FVR4096 '1000 count at battery 8V
ADCCONFIG $03 'Use fixed internal reference
READADC10 Batt_Mon,Batt_mv 'Battery tap 1/2, scale is 8 mv/count
LET OpCode =8
IF Batt_Mv >= Ref_Volts THEN
LET OpCode = 7
ENDIF
IF Batt_Mv < Min_Volts THEN
LET OpCode = 9
ENDIF
ENDIF
LET SolarEvent = 0
LET Tune_Indx = 0
IF OpCode <= OpCodeMax THEN
SERTXD (",OpCcde=",#OpCode,13,10)
rem LED control
LET DataAddr = OpCode
READ DataAddr, Scratch
IF Scratch = 1 THEN
LOW Blue_LED
ELSE
HIGH Blue_LED
ENDIF
LET DataAddr = OpCode + 20
READ DataAddr, Scratch
IF Scratch = 1 THEN
LOW Green_LED
ELSE
HIGH Green_LED
ENDIF
LET DataAddr = OpCode + 40
READ DataAddr, Scratch
IF Scratch = 1 THEN
LOW Red_LED
ELSE
HIGH Red_LED
ENDIF
LET DataAddr = OpCode + 60
READ DataAddr, Loop_Cnt
LET DataAddr = OpCode +80
READ DataAddr, Tune_Indx
LET DataAddr = OpCode + 100
IF Tune_Indx = 0 THEN
LET State = 2
ELSE
LET State = 1
ENDIF
ENDIF
LET OpCode = 11
CASE 1
IF Tune_Indx > 0 THEN
HIGH Aud_Cont
PAUSE 250 'Time for the audio amp to stabilize
ENDIF
SETINT OFF
BRANCH Tune_Indx,(NoMore,Acquarious,Chime,Tone4,Siren,ShortTune,Tone2,Tone3,BaBa,Okay)
Tone3:
TUNE Aud_tune,6,($40,$40,$40,$40,$40,$40,$77,$77,$75,$77,$72,$72,$74,$70,$70,$40,$40,$40,$40,$40,$40,$77,$77,$75,$77,$72,$72,$74,$70,$70)
GOTO NoMore
Chime:
TUNE Aud_tune,2,($04,$07,$05,$AB)
GOTO NoMore
ShortTune:
TUNE Aud_tune,5,($40,$05,$49,$05,$40,$2BC7,$45,$04,$47,$04,$64,$29,$C5,$40,$05,$49,$05,$40,$2B,$C7,$45,$04)
GOTO NoMore
Tone2:
TUNE Aud_tune,5,($40,$02,$44,$85,$40,$42,$44,$45,$AC,$42,$44,$46,$47,$AC,2,$44,$46,$47,$2C,$42,$44,$46,$47,$2C,$00,$44,$85)
GOTO NoMore
Acquarious:
TUNE Aud_tune,2,($34,$36,$B7,$39,$37,$76,$34,$32,$B4,$32,$74,$36,$F6,$34,$74,$32,$72,$B4)'Aquarious
GOTO NoMore
Tone4:
TUNE Aud_tune,8,($30,$75,$75,$35,$77,$79,$79,$39,$79,$77,$79,$3A,$34,$37,$35,$7C,$40,$40,$79,$02,$40,$40,$7A,$3A,$7A,$7A,$77,$00,$7A,$7A,$79,$39,$7C,$70,$75,$75,$35,$77,$79,$79,$39,$79,$77,$79,$3A,$34,$37,$35,$3C) 'boom
GOTO NoMore
BaBa:
TUNE Aud_tune,2,($30,$30,$37,$37,$79,$7B,$40,$79,$37,$3C,$35,$35,$34,$34,$32,$32,$30) 'Ba Ba
GOTO NoMore
Siren:
SOUND Aud_Tune,(86,300,95,300,86,300,95,300,86,300,95,300,86,300,95,300,86,300,95,300,86,300,95,300,86,300,95,300)
GOTO NoMore
Okay:
SOUND Aud_Tune,(25,30)
NoMore:
LOW Aud_cont
LET Tune_Indx = 0
SETINT %00000001,%00000001 'Interrupt when Rcvr_Int high
LET State = 2
CASE 2
IF Loop_Cnt > 0 THEN
DEC Loop_Cnt
IF OpCode <= OpCodeMax THEN
LET State = 3
ENDIF
ELSE
LET State = 3
ENDIF
CASE 3
HIGH Blue_LED
HIGH Green_LED
HIGH Red_LED
LET State = 0
ENDSELECT
PAUSE 124
GOTO Main
Interrupt:
LET Rcvr_Val = "z"
LET LenCode = "x"
LET temp = 0
DO WHILE PinC.0 = 1
LET temp = temp + 1 'Twice as fast as INC Usual count is 15
LOOP
IF temp < 10 THEN End_Interrupt 'Minimises the time to recover from a noise interrupt
LET bptr = 28
's message: Key Code| , | Msg Len| , | temperature | , | humidity | , | solar current | , | batt volts | , | hex checksum | CR | LF
SERIN [40],Rcvr_In,N2400_8,("14L1776"),Rcvr_Val,temp,LenCode,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc, @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptr
IF Rcvr_Val = "O" OR Rcvr_Val = "z" THEN End_Interrupt
IF Rcvr_Val < "p" AND LenCode <> 10 THEN End_Interrupt
SERTXD ("Temp=",#temp,",Key=",rcvr_Val,13,10)
LET Current = 0
IF Rcvr_Val = "s" AND LenCode = "K" THEN 'Check solar message
LET Chcksum = 0
FOR bptr = 29 TO 43
PEEK bptr, temp
LET Chcksum = Chcksum + temp
LET temp = temp - "0"
SELECT bptr
CASE 37
LET Current = 100 * temp
CASE 38
LET Current = 10 * temp + Current
CASE 39
LET Current = Current + temp
ENDSELECT
NEXT
LET ChckHex = ChckSum / 16
IF ChckHex < 10 THEN
LET ChckHex = ChckHex+ "0"
ELSE
LET ChckHex = ChckHex + "7"
ENDIF
PEEK 45,temp
IF ChckHex <> temp THEN End_Interrupt
LET ChckHex = ChckSum & $F
IF ChckHex < 10 THEN
LET ChckHex = ChckHex + "0"
ELSE
LET ChckHex = ChckHex + "7"
ENDIF
PEEK 46,temp
IF ChckHex <> temp THEN End_Interrupt 'Else current is valid
IF Current >= MinCurrent THEN
LET SolarEvent = 1
ENDIF
SERTXD ("Current=",#Current,",Volts=",#Batt_mv)
ENDIF
LOOKDOWN Rcvr_Val,("e","D","A","H","Q","B","h"),OpCode
End_Interrupt:
SETINT %00000001,%00000001 'Interrupt when Rcvr_Int high
RETURN