Full Version : Vasilis Remote Contol via Cell Phone (ASM)
avr >>COMMUNICATIONS & WEB PROJECTS >>Vasilis Remote Contol via Cell Phone (ASM)


<< Prev | Next >>

Admin3- 04-19-2006

Control up to 8 devices ( On/Off ) by sending a SMS message from any mobile phone, to ericsson T10s, of our circuit.

Designed by: Serasidis Vasilis

Introduction:

With this circuit we can controll up to 8 devices by sending a specific SMS message with any mobile phone. Its very usefull at the cases that, at the place we have the devices, we have not a wired telephone line. If you have an old ericsson mobile phone and you are not using it, its the time to build some useful with that. The controlling that we can do to the devices, its only ON or OFF.





The circuit:



The hardware of the circuit its very very simple, because the communication port of ericsson mobile its working at the 5 volts with AT commands ( like the modem commands, but for mobile phones).

The firmware of the AT90S2313 its very complicated because, we have to convert the 'septets' of the phone to 'octets' because the AVR need bytes with 8 bits length ( The 'septet' is 1 byte with 7 bits length and 'octet' is 1 byte with 8 bits length). All this proccess its necessary to decode the message from SMS.





Schematic of the circuit



When you finish the circuit connect it to the mobile phone, turn on the phone and then power on the circuit, not before . The AVR now its trying to read the message from the 1st memory location of the phone, for that i suggest to delete all SMS messages from the phone before connect it to the circuit. If there is no message to the 1st memory location, the AVR its trying again until you sent any.



The format of the message must be only '1' or '0'. '1' to enable, or '0' to disable the device. The message must have only 8 numbers, '1' or '0' , alone or mixed .

Example: if you send the message 11000100 then you enable, starting from the right, the devices 3,7,8 ('1') and disabling the devices 1,2,4,5,6 ('0') .

If you want to send a new message and you don't want to change some device, must send the same number as the old message.

Example: If you want to enable only the 5th device, you must send a new message like 11010100 to keep the other devices as there are (we send the same message as the old ( 11000100 ) and we change only the 5th bit from '0' to '1' to enable the device ).





Attention !!!



You sould write only '1' or '0' characters to your SMS message with NOT any letter or symbol like 'A' , 'B' , '$' or '@' etc . At this case the AVR will disable the device of this message potition. If you send the message 10111$00 , then except the device 1 and 2, the AVR will disable the 3th device too.

If you want to protect your devices from other person's messages, modify the source code, to read the AVR, your telephone number before execute any message. In the source code i have some part of code, to read the telephone number, the service center number, the date and the time of the received message.

The project its based on the Greek mobile phone network of ' Telestet ' and i don't know if the SMS message in other country, have the same syntax ( I mean the form of the septets that the GSM receiving from the GSM network ).



After the GSM receive the message, the AVR execute it, delete it from the phone memory, to release the 1st memory location and start again to search for a new message.

If you connect the pin 1 (PD0) of the AVR to MAX 232 chip and this to computer, you will see at the terminal window software, all the data that the GSM is send to the AVR (Sender's number, service center number, date, time and the AT commands ) . Setup the COM port to 9600 bps 8n1.







Troubleshoot



I have -*test*-('") it only with Greek sim cards and T10s mobile phone. I don't know if this circuit its working fine to other countries or other mobile phone models. You can build the diagnostic circuit that is in the dot frame of the schematic, and to connect the circuit with PC via RS232 port.



When you power-on the circuit and the phone, the AVR it will send the follow commands to the mobile phone:



1) AT+CPMS="ME" (Select the phone memory "ME")

and

2) AT+CMGR=1 (read the received message from memory possition 1)







If the mobile phone will response with:



AT+CMGR=1[CR][CR][LF] (this message its sended when there is no message in the phone memory)

+CMS ERROR: 500[CR][LF]



At this case the AVR it will send again the commands 1 & 2



If the mobile phone will response with:



AT+CMGR=1[CR][CR][LF] (this message its sended when a new message arrive in the phone memory)

+CMGR: 0,,26[CR][LF]

0791039624910000240C91xxxxxxxxxxxx00003001205151302108B1180C068BC162[CR][LF]

OK[CR][LF]

(xxxxxxxxxxxx is the phone number of the sender)



the AVR will decode the septets message to octets, execute it (arm or disarm the relays) and send the command



AT+CMGD=1 (delete the received message from memory possition 1)



to delete the message from the phone memory.





You can see the voltage of the PortB with any voltmeter if you have +5 or 0v voltage, to check if the command you send, for example"11001010", its executed.

Link: http://www.serasidis.gr/circuits/smscontro...scontroller.htm

CODE


;
;
; SMS REMOTE CONTROL, FOR ERICSSON T10 GSM MOBILE PHONE
;
; This circuit can handle 8 devices (ON/OFF) by sending SMS message with a mobile phone.
; 30-oct-2002 V1.0  --- I start it
; 04.10.2003  V1.01 --- I have change some routines to be more workable
; 03.07.2004 V2.00 --- I have rewrite the source code and i add more features.
;
; - Plug and play function added. There is no need to power on the mobile phone...
;   ...beffore the AVR. Just connect the devices (AVR & T10s) and turn them ON (power-ON).
;   The system communication will start immediately.
; - Response SMS to sender, added. Now the sender of the SMS command will be informed with return-SMS...
;     ... from the AVR, if SMS command is executed.
;
; writed with AVR studio 4.07
;
;
; by Serasidis Vasilis
;
; Home: http://www.serasidis.gr
; email: info@serasidis.gr , avrsite@yahoo.gr
;
;
; Target: AT90S2313 with 8 MHz crystal
; PD0= RxD
; PD1= TxD
; PB0-PB7= 8 bit output. You can drive with this port, 8 relays, 1 to each pin.
; Send SMS message to T10, like this format: 11100101
; That its mean, arm the relays No 1,3,6,7,8 and disarm the relays 2,4 and 5.
;
;
;


.nolist     ;Suppress listing of include file
.include "2313def.inc" ;Define chip particulars
.list

.equ BAUD  =51  ;9600 bps at 8.00 MHz.
.equ RamStart =96
.equ SMSC  =100;RAM address for SMS Service Center
.equ TPDA  =118;RAM address for Sender's number
.equ TimeDate =134;RAM address for Time and date of received SMS
.equ ASCII_HEX  =185;RAM address for ASCII to HEX conversion
.equ SMScommand =150;RAM address for encoded SMS command (11001010)


.def temp =R16 ;temporary storage register
.def interrupt=R17
.def Txbyte =R18 ;Data to be transmitted
.def Rxbyte =R19 ;Received data
.def temp2 =R20
.def temp3 =R21
.def temp4 =R22
.def temp5 =R23
.def temp6 =R24
.def output =R25 ;


.def delay1 =R26
.def delay2 =R27
.def YLramadr=R28
.def YHramadr=R29
.def delay3 =R29
.def ZLramadr=R30
.def ZHramadr=R31
.cseg
;========================================================================


.org 0
rjmp reset

.org OVF0addr  ; Timer/Counter0 Overflow

in   r0,SREG
inc  interrupt
cpi  interrupt,40
breq rst2
out  SREG,r0
reti


rst2:
pop  temp
pop  temp
rjmp timer_overflow

;*******************************************************************

cmd: .db "AT+CPMS=",'"',"ME",'"',0x0d,0;Select the phone memory ("ME")
cmd2: .db "AT+CMGR=1" ,0x0d, 0   ;read the received message(Memory possition 1)
cmd3: .db "AT+CMGD=1" ,0x0d, 0  ;delete the received message (Memory possition 1)


cmd4: .db "AT+CMGS=125",0x0d,0;Send SMS command
msg1: .db "000100",0
msg2: .db "7FC377BB1D769341",0; "Command "

msg3: .db   "A0F41C54C697C7" ; " is exec"
 .db   "757A991C02A1C6"     ; "uted! (c"
 .db   "29190C460389F3" ; ")2004 by"
 .db   "A069591E9EA7C9" ; " Serasid"
 .db   "E939C81A9EA7D9" ; "is Vasil"
 .db   "E939084DA7C375" ; "is http:"
 .db   "AFD7FD7E77CDCB" ; "//www.se"
 .db   "F2F03C4D4ECF5D" ; "rasidis."
 .db   "673988556E87D3" ; "gr ,emai"
 .db   "EC3928ED36BF01" ; "ls info@"
 .db   "F3B23C3C4F93D3" ; "serasidi"
 .db   "73D7590E6281C2"  ; "s.gr , a"
 .db   "76F93C4D2F03F2" ; "vrsite@y"
 .db   "61F4FBED3ACB01",0 ; "ahoo.gr"  
           

reset:

; Setup buffers and pointers


ldi  temp,RAMEND
out  SPL,temp  ;Init Stack Pointer


ldi  temp,0b11111111
out  DDRB,temp
ldi  temp,0b11111010
out  DDRD,temp
ldi  temp,0b00000101
out  portD,temp

ldi  temp,(1<<CS02)+(0<<CS01)+(1<<CS00)
out  TCCR0,temp  ; Set clock to count on CK/1024
ldi  temp,(1<<TOIE0)
out  TIMSK,temp  ; enable timer 0 overflow interrupt

ldi  temp,BAUD
out  UBRR,temp  ;Set baud rate generator


;===========   Set UART, as Transmiter   ======================

ldi  temp,0b00011000
out  UCR,temp  ;Enable UART Tx and Rx
;==============================================================

sbic pinD,2  ;pressed PD2?
rjmp timer_overflow
ser  temp
out  portb,temp

;==============================================================
;  Send AT+CPMS="ME" command
;==============================================================
timer_overflow:
rcall long_delay
rcall Set_Mem

;==============================================================
;  Send AT+CMGR=1 command
;==============================================================

Start:
clr  interrupt
rcall long_delay

load:
rcall Read_Mem1
rcall delay   ;delay some time beffore read the T10s

ldi  YL,RamStart  ;It is the first byte of RAM
clr  YHramadr
clr  ZHramadr
ldi  temp2,5   ;write 5 bytes from UART to ram

again:

rcall receive
cpi  rxbyte,'+'  ;wait for start byte '+' ( +CMGR:0,,... )
brne again   ;

uart2ram:
rcall receive   ;call receive routine. Read the <CMS E> or <CMGR:> text.
st  Y+,rxbyte  ;store data to RAM and increase RAM address
dec  temp2   ;Is temp2 zero ?
brne uart2ram  ;if not, read next byte.

;--------------------------------------------------------

ldi  YL,98   ;Memory potition for character 'G' in ram
ld  txbyte,Y  ;load the contain of selected potition
cpi  txbyte,'G'  ;Look if its 'G' letter ( G from CMGR:)
breq read_message ;If yes, go to read all message from the phone
rjmp Start   ;if not, go to read the 1st message again (if there is one).


read_message:

rcall long_delay  ;delay some time
rcall Read_Mem1  ;Send the Read_memory1 command again.
load2:

ldi  YLramadr,RamStart ;The first byte of RAM
ldi  temp2,68  ;use 68 bytes of ram

again2:
rcall receive   ;Receive byte
cpi  rxbyte,'0'  ; it is '0' ? ( 0 is the first character of the message data 07910396249100002...)
brne again2   ; if not, read next byte.

uart2ram2:
st  Y+,rxbyte  ;store data to RAM
rcall receive   ;call receive routine
dec  temp2
brne uart2ram2  ;if not done, loop more



rcall nextline  ;\
ldi  txbyte,'+'  ; \
rcall b_transmit  ;  \
ldi  YLramadr,SMSC  ;  / Print the service center number
ldi  temp3,6   ; /
rcall read   ;/

rcall nextline  ;\
ldi  txbyte,'+'  ; \
rcall b_transmit  ;  \
ldi  YLramadr,TPDA  ;  / Print the sender`s number
ldi  temp3,6   ; /
rcall read   ;/

rcall nextline  ;\
ldi  YLramadr,TimeDate ; \
ldi  temp3,1   ;  \
rcall read   ;   \
ldi  txbyte,'-'  ;    \  
rcall b_transmit  ;     \
ldi  temp3,1   ;      \
rcall read   ;  |
ldi  txbyte,'-'  ;  |
rcall b_transmit  ;  |
ldi  temp3,1   ;  |
rcall read   ;  \
ldi  txbyte,' '  ;  / Print the date and the time of the received message.
rcall b_transmit  ;  |
ldi  temp3,1   ;  |
rcall read   ;  |
ldi  txbyte,':'  ;  |
rcall b_transmit  ;      /
ldi  temp3,1   ;     /
rcall read   ;    /
ldi  txbyte,':'  ;   /
rcall b_transmit  ;  /
ldi  temp3,1   ; /
rcall read   ;/


; ldi  temp3,26
; ldi  YL,144
;moree:
; ld  txbyte,Y+
; rcall b_transmit
; dec  temp3
; brne moree
;=================================================================================
; Here its the routine for convert the ASCII to HEX and stored to RAM address 185
;=================================================================================

ldi  ZLramadr,ASCII_HEX
clr  ZHramadr  ;
ldi  temp3,7   ;7 bits length
clr  YHramadr
ldi  YLramadr,SMScommand;First byte of the message in the RAM (message like this 11001101)


septet:


ld  txbyte,Y+  ;Load byte from RAM
cpi  txbyte,0x41  ;compare it with 0x41 ("a" hex)
brlo number   ; if it is lower, it is a number, not letter. So, go to number address.

ldi  temp4,9   ;
add  txbyte,temp4 ;add 9 to txbyte
cbr  txbyte,0b11110000;clear bits 7,6,5,4 of txbyte
swap txbyte   ; swap nibles
mov  temp,txbyte  ;copy txbyte to temp
rjmp sec_ascii  ;go to sec_ascii (second ASCII)

number:
cbr  txbyte,0b11110000;If 1st byte is number, clear bits 7,6,5,4 of txbyte
swap txbyte   ;swap nibles
mov  temp,txbyte  ;copy txbyte to temp


sec_ascii:

ld  txbyte,Y+  ;Load 2nd byte to txbyte
cpi  txbyte,0x41  ; compare it with 0x41
brlo number2   ;if it is lower than 0x41, go to "number2"

ldi  temp4,9   ;
add  txbyte,temp4 ;add 9 to txbyte
cbr  txbyte,0b11110000;clear bits 7,6,5,4 of txbytes
add  txbyte,temp  ;add  temp to txbyte
rjmp store_in_ram ;go to "store_in_ram"

number2:
cbr  txbyte,0b11110000
add  txbyte,temp

store_in_ram:

st  Z+,txbyte  ;Save the txbyte to RAM
dec  temp3   ;decrease temp3
brne septet   ;if it is nit '0', go to "septet"

;==============================================================
;  convert the HEX values to septets
;==============================================================

rcall nextline;
ldi  temp3,7 ;
ldi  temp4,1
ldi  YLramadr,ASCII_HEX;
clr  output

ld  txbyte,Y+
mov  temp,txbyte
cbr  txbyte,0b10000000
rcall b_transmit
cpi  txbyte,0x31
brne loopp
sbr  output,0b00000001

loopp:
lsl  output
mov  temp5,temp4
ld  txbyte,Y+
mov  temp6,txbyte
aaaa:
lsl  temp
rol  txbyte
dec  temp5
brne aaaa

cbr  txbyte,0b10000000
rcall b_transmit
cpi  txbyte,0x31
brne zero
sbr  output,0b00000001
 
zero:

mov  temp,temp6
inc  temp4
dec  temp3
brne loopp

out  PortB,output
rcall delete_mem1
rcall delay

rjmp response_sms

;===========================================================
; Read 2 ASCII characters, swap them and send them to T10s
;===========================================================

read:
inc  YLramadr
ld  txbyte,Y
rcall b_transmit
dec  YLramadr
ld  txbyte,Y
rcall b_transmit
inc  YLramadr
inc  YLramadr
dec  temp3
brne read

ret

;=============================================================
;  <Change line> and <Enter> ASCII commands
;=============================================================
nextline:
ldi  txbyte,0x0d
rcall b_transmit
ldi  txbyte,0x0a
rcall b_transmit

ret

;***************************************************************************
; Transmiting routine (The data from the eeprom through the AVR are going to
; the PC computer)        
;***************************************************************************
b_transmit:
sbis USR,UDRE;is UART transmitter ready?
rjmp b_transmit
out  UDR,txbyte;sent out char
ret

;*************************************************************************
; Receiving routine (The data from PC computer through to the AVR are going
; to the eeprom)  
;*************************************************************************
receive:
sei ;Set Enable Interrupts
rec_loop:
sbis USR,RXC
rjmp rec_loop
cli ;Clear Interrupts
in  Rxbyte,UDR
clr  interrupt
ret


;*******************************************************************
;                   Stop and Delay routines
;*******************************************************************
long_delay:
ldi  delay3,40
waitmore2:
rcall delay
dec  delay3
brne waitmore2
ret



delay:
ldi  delay2,0xff
waitsome:
ldi  delay1,0xff  

waitmore:
dec  delay1
brne waitmore
dec  delay2
brne waitsome

ret

;*******************************************************************
Set_Mem: ldi  zl,low(cmd*2);set pointer to
  ldi  zh,high(cmd*2);the text
  rjmp send_command

Read_Mem1: ldi  zl,low(cmd2*2);set pointer to
  ldi  zh,high(cmd2*2);the text
  rjmp send_command

Delete_Mem1:
  ldi  zl,low(cmd3*2);set pointer to
  ldi  zh,high(cmd3*2);the text
  rjmp send_command

send_command:
  lpm
  tst  r0   ;check if its the last character (the zero)
  breq return  ;if yes, return.
  mov  txbyte,r0
  rcall b_transmit ;
  adiw zl,1  ;increase zl
  rjmp send_command;read next character from flash memory

return:  ret

;===========================================================
; Response to sender, that the SMS command is executed.
;===========================================================
response_sms:

ldi  zl,low(cmd4*2);
ldi  zh,high(cmd4*2);
rcall send_command;Send AT+CMGS=xxx
rcall delay

ldi  zl,low(msg1*2);
ldi  zh,high(msg1*2);
rcall send_command;Send "000100" ASCII
ldi  temp,16  ;Read 16 bytes of RAM
ldi  YL,114  ;"0C" Sender Address length
Read_more:
ld  txbyte,Y+
rcall b_transmit ;Send the Sender number
dec  temp
brne Read_more

ldi  txbyte,'0'
rcall b_transmit ;0
rcall b_transmit ;0
rcall b_transmit ;0
rcall b_transmit ;0

ldi  zl,low(msg2*2);
ldi  zh,high(msg2*2);
rcall send_command;Send "7FC377BB1D769341" PDU text "Command"

ldi  temp,14  ;Read 14 bytes of RAM
ldi  YL,SMScommand;11001010 area.
Read_more2:
ld  txbyte,Y+
rcall b_transmit ;Send the command (like 11001100)
dec  temp
brne Read_more2

ldi  zl,low(msg3*2);
ldi  zh,high(msg3*2);
rcall send_command;Send  PDU text " is executed!"

ldi  txbyte,26 ;<Ctrl-Z> key
rcall b_transmit

ldi  delay3,255
rcall waitmore2
ldi  delay3,255
rcall waitmore2

ldi  txbyte,27 ;<ESC> key
rcall b_transmit ;Cancel the "send SMS" (AT+CMGS) command for sure.
rcall delay

;===========================================================
; Clear entire RAM, 128 bytes
;===========================================================
ldi  YLramadr,RamStart
ser  temp
clr_ram:
st  Y+,temp
cpi  YL,223
brne clr_ram

rjmp start





Free Forum Hosting by Forumer.comTM!