|
Remote control a heater for a car This application note was submitted by Matthias
Prill , DG5LM
It may not be used for commercial purposes.
Remote control a heater for a
car by calling from a authorized number. 'The program initializes a
Siemens S10/11 to communicate in simple form with the 89c2051.
After recognizing an incomming call it gets the number of the active call via the
AT^SCNI command.
The number will be compared with the given masternumber stored in the eeprom.
If the number is allowed the relais sitches on for a defined time (Relais_on_time)
For testmode pull down config0(p3.5).The relais will click endless. Useless but nice to see
that controller is working :-) !
Please fill out the default masternumber$ in the section Readnumber()!
If you want to learn another masternumber$, you have to pull down config1 (p3.4).
After calling the cellular the LED lights up and the new number is stored.
Leave the learning mode and reset.
Please feel free to use it for your own private use!
No commercial use of program and layout!
I2C routines are from other sample code.
Matthias Prill, DG5LM
Download source code in .BAS Dowload PCB file #1 Dowload PCB file #2
'$sim
'
'Remote control a heater for a car by calling from a
authorized number
'The program initializes a Siemens S10/11 to communicate
in simple form with the 89c2051
'After recognizing an incomming call it gets the number of
the active call via the
'AT^SCNI command.
'The number will be compared with the given masternumber
stored in the eeprom.
'If the number is allowed the relais sitches on for a
defined time (Relais_on_time)
'For testmode pull down config0(p3.5).The relais will
click endless. Useless but nice to see
'that controller is working :-) !
'Please fill out the default masternumber$ in the section
Readnumber()!
'If you want to learn another masternumber$, you have to
pull down config1 (p3.4).
'After calling the cellular the LED lights up and the new
number is stored.
'Leave the learning mode and reset.
'
'
'
'
'Please feel free to use it for your own private use!
'No commercial use of program and layout!
'I2C routines are from other sample code.
'
'Matthias Prill, DG5LM
'
'
'Heizungsfernschaltung Mit Siemens S10 / S11
'
'Matthias Prill
'23.03.2001
'
'05.03.2001 erste Versuche mit AT Kommandos am S11
'23.03.2001 nur numerische Modemmeldungen ->zahl+CR
anstelle von LF+OK+CR+LF
'29.11.2001 nummer extrahieren ab ermittelter position
(war vorher konstant ab 12.stelle des string)
'13.12.2001 entfernen lcd routinen
'14.12.2001 eeprom 24cxx für lernbare masternummer
'04.02.2002 prepare for bascom mailinglist
'05.02.2002 adding comments and so on
$crystal = 11059200 'frequency
$baud = 19200 'baudrate for communication
with Siemens S11
$timeout
Config Sda = P1.6 'eeprom 24lc01
Config Scl = P1.7 'eeprom 24lc01
Config I2cdelay = 2
Heater Alias P3.7 'relais via pnp transistor 0=relais
on 1 = relais off
Led_ok Alias P1.0 'led catode; anode via resistor at
vcc
Config0 Alias P3.5 'hardware check => endless click
click click
Config1 Alias P3.4 'learn the masternumber
Declare Sub Write_eeprom(adres As Byte , Value As Byte)
Declare Sub Read_eeprom(adres As Byte , Value As Byte)
Declare Sub Writenumber()
Declare Sub Readnumber()
Declare Sub Learn()
'declare constants for i2c 24lc01b
Dim Relais_on_time As Const 5
Dim Addressw As Const 160
Dim Addressr As Const 161
Dim Adres As Byte , Value As Byte
'declare general constants
Dim I As Byte , Count As Integer
Dim Masternumber$ As String * 16
Dim C$ As String * 1
Dim S$ As String * 35
Heater = 1
Led_ok = 1
Config0 = 1
Config1 = 1
For Count = 1 To 3 'just for fun blink the LED an 'o'
Led_ok = 0
Waitms 300
Led_ok = 1
Waitms 100
Next
If Config0 = 0 Then 'endless click the relay for test
purpose
Do
Heater = 0
Waitms 250
Heater = 1
Waitms 250
Loop
End If
Call Readnumber() 'reads the number
to trigger from the eeprom into masternumber$
Print "ate0" : Input S$ Timeout = 50 'echo off
Input S$ Timeout = 99 'capture echo ??
Waitms 50
Print "atv0" 'numeric responses only
Input S$ Timeout = 99
Wait 1
Do
If Scon.0 = 1 Then
Input S$
If S$ = "2" Then 'Code for "RING"
Print "at^scni" : Input S$ 'get the aktive Call
Input S$ 'modem response : ^SCNI: 1,2,01701234567,129
I = Instr(s$ , Masternumber$)
If I > 0 Then
Heater = 0
Wait Relais_on_time
Heater = 1
End If
If Config1 = 0 Then 'learning the masternumber!
Led_ok = 0 'switch on
LED_OK in learning mode
Call Learn()
Call Writenumber() 'write the new
masternumber into the eeprom
Wait Relais_on_time 'wait a few seconds
Led_ok = 1 'switch off
the led
End If
End If
End If
Loop
End
'
'
'
Sub Learn()
'
'Filter the modem response string
'modem response : ^SCNI: 1,2,01701234567,129
's$ after filtering 01701234567
Count = Len(s$) 'get the lenght
If Count > 12 Then 'only if number is transmitted
For I = 1 To Count
C$ = ","
Value = Instr(i , S$ , C$) '
If Value <> 0 Then
I = Value
Else
Exit For
End If
Next
I = I - 13
S$ = Mid(s$ , 12 , I)
End If
End Sub
Sub Writenumber()
'
'Writes the number of the active call into the eeprom
cells starting at adress 1!
'End of the number is represented by a zero value
'Example: 01701234567 will cause the following memory map:
'
' 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
'
' FF 30 31 37 30 31 32 33 34 35 36 37 00 FF FF FF
.01701234567...
Count = Len(s$)
For Adres = 1 To Count
C$ = Mid(s$ , Adres , 1)
Value = Asc(c$)
Call Write_eeprom(adres , Value)
Next Adres
Value = 0
Call Write_eeprom(adres , Value) 'write 0 after last number of
masternumber
End Sub
Sub Readnumber() 'reads
masternumber
'
'Reads the masternumber from eeprom cell 1 until reading a
0 or adresscounter reaches 16
'
'If there is a virgin eeprom installed so you can leave a
default masternumber$
'I didnt check out what is happen if you leave it blank.
Better put there a valid number from
'your cellular for initial purpose!
'
Masternumber$ = ""
For Adres = 1 To 16
Call Read_eeprom(adres , Value)
If Value = 255 Then
Masternumber$ = "01701234567" 'virgin eeprom no masternumber present => use this number to
configure a new number
Exit For
End If
If Value = 0 Then Exit For 'end of masternumber
C$ = Chr(value)
Masternumber$ = Masternumber$ + C$
Next Adres
End Sub
'writing a byte to eeprom 24LC01
Sub Write_eeprom(adres As Byte , Value As Byte)
I2cstart 'start condition
I2cwbyte Addressw 'slave address
I2cwbyte Adres 'asdress of EEPROM
I2cwbyte Value 'value to write
I2cstop 'stop condition
Waitms 10 'wait for 10 milliseconds
End Sub
'reading a byte from eeprom 24LC01
Sub Read_eeprom(adres As Byte , Value As Byte)
I2cstart 'generate start
I2cwbyte Addressw 'slave address
I2cwbyte Adres 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Addressr 'slave address (read)
I2crbyte Value , 9 'read byte
I2cstop 'generate stop
End Sub
|