Inmiddels draait de onweer detector alweer een tijdje.
Hij hangt op zolder met een stukje draad verticaal als antenne. Het bereik is ca 50km. Ik heb de software uitgebreid met een aflezing per minuut en het totale aantal strikes. Het totale aan strikes word opgeslagen in het eeprom van de pic. Op portb.1 kun je een speaker aansluiten, zodra er meer dan 25strikes zijn per 5 minuten hoor je een piepje elke minuut. Tevens wordt de data draadloos verstuurd. Hier de source.
Device 16F628A
Xtal 4
LCD_DTPin PORTA.0
LCD_ENPin PORTB.3
LCD_RSPin PORTB.4
TRISB=000001 ' PortB.0 as input
'ANSEL = 0 ' all Portb.7 digital
CMCON = 7
PORTB.7 = 0
Dim teller As Byte
Dim zendtel As Byte
Dim mantel As Byte
Dim strikes[5] As Word
Dim strikes5m As Word
Dim strikestotal As Dword
Dim strikesmc As Word
Dim manchestin As Byte
Dim manchestout As Word
Dim tempdata As Bit
Dim manchestsl As Word
Dim manchestsh As Word
Dim manchests5h As Word
Dim manchests5l As Word
Dim manchestst0 As Word
Dim manchestst1 As Word
Dim manchestst2 As Word
Dim manchestst3 As Word
Dim manchestck As Word
Dim manchestzd As Word
Dim checksum As Byte
Symbol zender = 2
Symbol adres = 1
Symbol zendout = PORTB.7
Symbol startman = $55
Symbol dataman = $aa
Clear
manchestin = zender
Call manchesterdata
manchestzd = manchestout
strikestotal = ERead adres
Cls
DelayMS 100
Print At 1,1,"Lightning"
Print At 2,1,"Detector 1.0"
main:
For teller = 0 To 4
strikes[teller] = Counter PORTB.0,60000
strikes5m = strikes[0] + strikes[1] + strikes[2] + strikes[3] + strikes[4]
Print At 1,1,Dec3 strikes[teller]," S/m ",Dec3 strikes5m," S/5m"
If strikes5m > 25 Then Sound PORTB.1,[122,25]
If strikes[teller] > 2 Then strikestotal = strikestotal+strikes[teller]
Print At 2,1,Dec6 strikestotal," Tstrikes"
strikesmc = strikes[teller]
manchestin = strikesmc.HighByte
Call manchesterdata
manchestsh = manchestout
manchestin = strikesmc.LowByte
Call manchesterdata
manchestsl = manchestout
manchestin = strikes5m.HighByte
Call manchesterdata
manchests5h = manchestout
manchestin = strikes5m.LowByte
Call manchesterdata
manchests5l = manchestout
manchestin = strikestotal.Byte0
Call manchesterdata
manchestst0 = manchestout
manchestin = strikestotal.Byte1
Call manchesterdata
manchestst1 = manchestout
manchestin = strikestotal.Byte2
Call manchesterdata
manchestst2 = manchestout
manchestin = strikestotal.Byte3
Call manchesterdata
manchestst3 = manchestout
checksum = zender + strikes[teller] + strikes5m + strikestotal.Byte0 + strikestotal.Byte1 + strikestotal.Byte2 + strikestotal.Byte3 - 1
manchestin = checksum
Call manchesterdata
manchestck = manchestout
For zendtel = 1 To 3
SerOut zendout, 49965,[startman,dataman,manchestzd.HighByte,manchestzd.LowByte,manchestsh.HighByte,manchestsh.LowByte,manchestsl.HighByte,manchestsl.LowByte,manchests5h.HighByte,manchests5h.LowByte,manchests5l.HighByte,manchests5l.LowByte]
SerOut zendout, 49965,[manchestst0.HighByte,manchestst0.LowByte,manchestst1.HighByte,manchestst1.LowByte,manchestst2.HighByte,manchestst2.LowByte,manchestst3.HighByte,manchestst3.LowByte,manchestck.HighByte,manchestck.LowByte]
DelayMS 10
Next zendtel
Next teller
EWrite adres,[strikestotal]
GoTo main
manchesterdata:
For mantel = 0 To 7
tempdata = GetBit manchestin,mantel
If tempdata = 0 Then
ClearBit manchestout,(mantel*2)
SetBit manchestout,(mantel*2+1)
Else
SetBit manchestout,(mantel*2)
ClearBit manchestout,(mantel*2+1)
EndIf
Next mantel
Return
End
Geen opmerkingen:
Een reactie posten