djzbor
Junior Member level 2
sample code ascii septet conversion
I am in trouble of understanding how the following code works .can any one explain in detail and come up with the flow chart?
;
;
; 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: https://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
I am in trouble of understanding how the following code works .can any one explain in detail and come up with the flow chart?
;
;
; 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: https://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