PDA

View Full Version : Need Help



PVBiljon
- 29th May 2009, 11:36
Need help with the following

define LOADER_USED 1
Define Lcd_dreg Portc
Define Lcd_dbit 0
Define Lcd_rsreg Portc
Define Lcd_rsbit 4
Define Lcd_ereg Portc
Define Lcd_ebit 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
DEFINE LCD_DATAUS 50
Define Osc 4 ' We're using a 4 MHz oscillator

RELAY1 VAR PORTB.0 ' RELAY 1
RELAY2 VAR PORTB.1 ' RELAY 2
RELAY3 VAR PORTB.2 ' RELAY 3
RELAY4 VAR PORTB.3 ' RELAY 4
RELAY5 VAR PORTB.4 ' RELAY 5
RELAY6 VAR PORTB.5 ' RELAY 6
RELAY7 VAR PORTB.6 ' RELAY 7
RELAY8 VAR PORTB.7 ' RELAY 8

'RELAY VAR BYTE ' RELAY NUMBER
MYDATA VAR byte [2] ' GENERAL PURPOSE DATA VARIABLE
INDEX VAR byte ' SMS INDEX NUMBER
'I VAR BYTE
Trisa = %00000000 ' SETS ALL PORTA PINS TO OUTPUT
Trisb = %00000000 ' ALL OUTPUT
adcon1 = 7
trisc = %00000000

Pause 50'0 ' Wait .5 second


Lcdout $fe,1, "SMS CONTROL" ' Send to LCD
Lcdout $fe,$C0, "SMS TEST C5" ' Second Line
PAUSE 20'00


LOOP:
mydata=0
Lcdout $fe, 1, "WAITING 4 SMS" ' Send to LCD
Pause 50'00
hserout ["AT+CMGL=",34,"REC UNREAD",34,13]
hserin 2000,loop,[WAIT("+CMGL:"), SKIP 1 , DEC INDEX] 'From Modem
Lcdout $fe, $C0, "SMS RX: " ,dec index' Second Line
PAUSE 50'00
Lcdout $fe, 1, "READ MSG: " ' Send to LCD
hserout ["AT+CMGR=",dec index,13]
hserin [WAIT("+CMGR:"),SKIP 55,str MYDATA\2]
pause 20
hserout [str MYDATA\2,13]
pause 20
Lcdout $fe, 1,"MYDATA:",str mydata\2 ' Send to LCD
pause 20


SELECT CASE mydata

CASE 33

Lcdout $fe, 1, "RELAY 2"
Lcdout $fe, $C0, "ON"
pause 20
CASE 44
Lcdout $fe, 1, "RELAY 2"
Lcdout $fe, $C0, "OFF"
pause 20
CASE 11
Lcdout $fe, 1, "RELAY 1"
Lcdout $fe, $C0, "ON"
pause 20
CASE 22
Lcdout $fe, 1, "RELAY 1"
Lcdout $fe, $C0, "OFF"

pause 20
CASE 55
Lcdout $fe, 1, "RELAY 3"
Lcdout $fe, $C0, "ON"
pause 20
CASE 66
Lcdout $fe, 1, "RELAY 3"
Lcdout $fe, $C0, "OFF"
pause 20
CASE 77
Lcdout $fe, 1, "RELAY 4"
Lcdout $fe, $C0, "ON"
pause 20
CASE 88
Lcdout $fe, 1, "RELAY 4"
Lcdout $fe, $C0, "OFF"
pause 20
end select



PAUSE 80'00
Lcdout $fe, 1, "DELETE SMS MSG"
Lcdout $fe, $C0, "#:" ,dec index
hserout ["AT+CMGD=",dec index, 13]
PAUSE 30'00

GOTO LOOP

END

Program does not excecute the CASE statements
HELP PLEASE

sayzer
- 29th May 2009, 13:29
" MYDATA VAR byte [2] " is an array.


You have "mydata" in your Select case statement.

Chose one element from mydata elements.


------------------------------------

PVBiljon
- 29th May 2009, 15:24
To make it an Array was the only way I could read the value of Mydata

If I make it a normal variable this command does not work

hserin [WAIT("+CMGR:"),SKIP 55,str MYDATA]

does not get last of SMS message fot instance if I say message is 22 to switch on relay 22

Have played around with skip value's from 49 to 56

Thanks

PVBiljon
- 29th May 2009, 15:26
hserin [WAIT("+CMGR:"),SKIP 55, DEC MYDATA]
correction to above

ScaleRobotics
- 29th May 2009, 17:04
Then you will have to figure out if it is mydata[0] or mydata[1] that stores the variable you want. Change your mydata= 0 and select case mydata to mydata[0]=0 or mydata[1]=0 and select case mydata[0] or select case mydata[1]