include <P18F1320.INC>
cblock 0x80 ;start of general purpose registers
buffer:128
endc
cblock 0x0
count
Pointer
endc
ResetVector org 0x00
call SendAT ;resets pointer
movlw low buffer
movwf FSR0L
movlw high buffer
movwf FSR0H
Loop call Get232 ;reads from Mess
movwf INDF0
incf FSR0L,f
xorlw 0x0a
btfss STATUS,Z
goto Loop
call Search
hang goto hang
Search movlw upper mess
movwf TBLPTRU
movlw high mess
movwf TBLPTRH
movlw low mess
movwf TBLPTRL
clrf count
loop tblrd*
infsnz TABLAT,w ;test for end of table
goto done
movf TABLAT,W ;skip any zeros
bnz NotZero
tblrd*+
bra loop
NotZero movlw low buffer
movwf FSR0L
movlw high buffer
movwf FSR0H
Compare tblrd*+
tstfsz TABLAT
goto Contin
;found match
incf count,w
done return
Contin movf POSTINC0,W
xorwf TABLAT,W
bz Compare
;no match
skip tblrd*+
tstfsz TABLAT ;test for end of message
goto skip
incf count,F
goto loop
mess db "on motor1",0
db "off motor1",0
db "on motor2",0
db "off motor2",0
db 0xff
SendAT clrf Pointer
return
Get232 movlw low(Message)
addwf Pointer,w
movwf TBLPTRL
movlw high(Message)
btfsc STATUS,C
addlw 1
movwf TBLPTRH
movlw upper(Message)
btfsc STATUS,C
addlw 1
movwf TBLPTRU
tblrd*
movf TABLAT,w
incf Pointer,f
return
Message db "on motor2 and somert else",0x0d,0x0a
db 0
END