PDA

View Full Version : What code should add if the "state" is no longer 0 and 1 (control intensity of lamp)



kojiyumii
- 18th September 2012, 15:34
DEFINE LOADER_USED 1 ‘ For Bootloader downloading
DEFINE LCD_DREG PORTb ' Set LCD Data port to Port B of MCU
DEFINE LCD_DBIT 4 ' Set starting Data bit (0)
DEFINE LCD_RSREG PORTb ' Set LCD Register Select port
DEFINE LCD_RSBIT 0 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTb ' Set LCD Enable port
DEFINE LCD_EBIT 1 ' Set LCD Enable bit.
DEFINE LCD_BITS 4 ' Set LCD bus size (4 bits)
'Declaration
CALLER var byte[12] 'store the string for caller ID (phone no.)
cl var byte ' For button function
INDEX var byte ' SMS INDEX NUMBER
DEVICE var byte
STAT var byte
'Initialisation
ADCON1 = 7 'All digital input for Port A
TrisA = %11111111 ' which used for pushbutton
index = 0 : DEVICE = 0 : STATUS = 0

Main: 'Label. Main program starts here
'Waiting for the arrival of SMS message
'Read GSM Modem for new message. If found, then read and perform action
'Or else loop back Main.
LCDOUT $FE, 1, "((WAIT FOR SMS))" ' Send to LCD
'Check for any new message.
'If new message found, the perform further action OR ELSE go back to the loop
SERIN2 portc.7,84,1000,Main,[WAIT("+CMTI:"), SKIP 6 , DEC INDEX]
LCDOUT $FE, 1, "NEW SMS ARRIVED!" ' Send to LCD
LCDOUT $FE, $C0, "SMS RX NO.: ",DEC INDEX ' Second Line
pause 1000
'Read the content of SMS and perform action accordingly. Delete the message when complete.
GOSUB READ_SMS
GOSUB DELE_SMS
goto Main


'Read SMS and perform the action
READ_SMS:
Serout portC.6, 2,["AT+CMGR=",#INDEX,10,13] 'read messaage at SIM location at #INDEX
SERIN2 portc.7,84,1000,main,[wait("READ"),SKIP 3,str CALLER\12,skip 27,str
DEVICE\1,wait(","),str STAT\1]
'Read the message and perform action
LCDOUT $FE, 1, "DEVICE = ", DEVICE
LCDOUT $FE, $c0," STAT = ", STAT
pause 1000
SELECT CASE DEVICE
CASE "1"
LCDOUT $FE, 1, "RELAY 1"
LCDOUT $FE, $C0, "STATE"
pause 1000
if STAT = "1" then
high portc.0
LCDOUT $FE, $C0, "ON "
else
low portc.0
LCDOUT $FE, $C0, "OFF "
endif
CASE "2"
LCDOUT $FE, 1, "RELAY 2"
LCDOUT $FE, $C0, "STATE"
pause 1000
if STAT = "1" then
high portc.1
LCDOUT $FE, $C0, "ON "
else
low portc.1
LCDOUT $FE, $C0, "OFF "
endif
END SELECT
pause 1000