Co0LėT♥
Hydroelectric
 
Pogi/Ganda Points: 368
Offline
Gender: 
Posts: 3330
|
 |
« on: December 18, 2009, 03:35:12 PM » |
|
As suggested by Tita Marce here it is... medyo pag me time lang po.. wag po makulet kasi ako lang ang ma-c0♂Lėt dito  "Sim900D code at page 20, post #390" i was thinking the same thing... sis coolet, kung may e-gizmo gsm modem ka, paggawa naman... post mo schematic. then gawa ka ng simple interfacing program using BASIC. i will take care of CCS C (or hitech kung kayanin ng powers) equivalent program. kokonvert ko based sa gawa mo  E-GIZMO BenQ GSM Ito connection kung 3.3v ang supply Ito naman pag 5v ang supply Ito naman ang command na mostly kailanganSET DATE AT$TIME=HH,MM,SS
READ GSM MODULE MANUFACTURER AT+GMI
READ ALL MESSAGES AT+CMGL="ALL"
READ MESSAGE AT MEMORY LOCATION 1 AT+CMGR=1
DELETE MEMORY LOCATION 1 AT+CMGD=1
FORMAT (Text Mode/PDU Mode) AT+CMGF=<?>
SEND MESSAGE AT+CMGS=" PHONE NUMBER " <CR> HELLO <CTRL+Z>
WRITE PHONEBOOK MEMORY 1 AT+CPBW=1,"123456789",129,"UNOK"
DELETE MEMORY 1 OF PHONEBOOK AT+CPBW=1
READ PHONEBOOK AT MEMORY 1 AT+CPBR=1 Ito ang unfiltered message Text Mode CR = carriage return = 13 LF = line feed = 10 Ito ang filtered message Text Mode Ito naman ang PDU mode (unfiltered/filtered) Code will follow soon! BTW don't ask me if in case merong error pag-compile nyo... I am using the latest Proton Compiler V3.4.0.8 at wala akong basag nyan... me usb key po ako Here is the code for Sim900DCode was tested with Sim900D via TeamViewer Thanks to: sis m@r & sis debz - partner in crime  sis gigz for teamviewer  PART 1/2 '**************************************************************** '* Name : Simcon.BAS * '* Author : Coolet * '* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 02/17/2010 * '* Version : 1.0 * '* Notes : Proton V3.5.0.6 * '* : IDE V 2.0.0.5 * '****************************************************************
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' Device Programming Options ' -------------------------- ' Device 16F877A ' We are using a PIC16F877A (40PIN PIL) Declare Xtal = 20 ' And a 20MHz crystal Declare Reminders OFF Config HS_OSC,WDT_OFF,PWRTE_ON,BODEN_OFF,LVP_OFF,CP_OFF,DEBUG_OFF Declare Reminders On ADCON1 = 7 ; make all analog input to digital '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' Hardware Assignments ' -------------------- ' RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $24 ' Enable transmit, BRGH = 1 SPBRG = 129 ' 9600 Baud @ 20MHz, 0.16% Hserial_Clear=On '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' RAM Assignments and Variables ' ----------------------------- ' Dim Reply As Bit ' Phone Reply status Dim Compare As Bit ' Use for 8byte data comparison Dim ArmedFlag As Bit ' Use to inform micro is Alarm is Armed or Disarmed Dim VarX As Byte ' Global variable Dim SMSLength As Byte ' Length of sms Dim VarY As Byte ' Global variable Dim VarZ As Byte ' Global variable Dim Address As Byte ' Onboard eeprom Address Dim DataLength As Byte ' Use for tracking 1st character Dim DataBuffer[8] As Byte ' Extracted 8 byte storage Dim MobileBuffer[13] As Byte ' Mobile phone storage Dim GlobalBuffer[120] As Byte ' Sms storage & General storage ' PIN assignment Symbol Sensor1 = PORTA.1 ' Any Sensor and any port you like Symbol Relay1 = PORTB.0 ' Any Port you like Symbol PWON = PORTA.2 ' Any port you like ' ' Program Constants ' ----------------- ' Symbol CR = 13 ' Carriage Return Symbol LF = 10 ' Line Feed Symbol CTRL_Z = 26 ' Control + Z key Symbol Err = 0 ' As in Error Symbol OK = 1 ' I'm fine Symbol Equal = 1 ' As in Equal Symbol NotEqual = 0 ' As in not Equal Symbol NoMessage = 0 ' No Message in Memory Location 1
DelayMS 500 ' Half seconds delay for Pic to initialized Clear Str DataBuffer = "AT+CNMI=" ' Load AT command '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ------------------ added code --------------------------------- ' ' ' Stored Data to onboard Eeprom at program time ' ' 00 TO 11 ................ 12 BYTES USER MOBILE PHONE NUMBER STORAGE ' 12 TO 19 ..."9359A402"... 8 BYTES USER COMMAND ID IN PDU MODE "COOLET" DEFAULT PASSWORD ' 20 TO 27 ..."33286D02"... 8 BYTES USER COMMAND ID IN PDU MODE "DISARMED ALARM" ' 28 TO 35 ..."99416913"... 8 BYTES USER COMMAND ID IN PDU MODE "ARMED ALARM" ' 36 TO 43 ..."053D8D46"... 8 BYTES USER COMMAND ID IN PDU MODE "RELAY OFF" ' 44 TO 51 ..."98053D9D"... 8 BYTES USER COMMAND ID IN PDU MODE "RELAY ON" EData 0,0,0,0,0,0,0,0,0,0,0,0,"9359A402","33286D02","99416913","053D8D46","98053D9D" ; ------------------ added code ---------------------------------
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~MAIN PROGRAM~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ START: High PWON ' Turn on Sim340DZ (Via transistor) DelayMS 200 ' Sim340DZ needs at least >150mS pulse to power on, Lets give it 200mS Low PWON ' Set to low For VarX = 0 To 6 ; wait 6 secs DelayMS 1000 Next HSerOut [Str DataBuffer,"1",44,"0",44,"0",44,"0",44,"0",CR] CONNECT: GoSub SEND_AT_COMMAND ' Check for Phone activity If Reply = OK Then ' Yes! Phone found! Inc VarX ' Let's check again to be sure connector... If VarX > 3 Then ' ... is properly fixed! Try 3x GoSub DELETE_IT ' Delete 1st 2 memory location Clear VarX ' Reset counter DelayMS 3000 ' Wait orig 1000 GoSub PDU_MODE ' Set to PDU Mode GoTo MAIN_LOOP ' Bye! Ready for action EndIf ' End of statement Else ' Otherwise DelayMS 3000 ' Rest for 3Secs EndIf ' End of statement GoTo CONNECT ' Check the phone again
MAIN_LOOP: ' ' Let's see if a new message arrive ' ' Phone reply if no message(ONLINE): +CMS ERROR: 321 (without "OK") ' Variable REPLY always contains ERR. It will change only ' when it detects "OK". ' ' GoSub READ_GSM ' Check Inbox for new message ' ' No message or message too long ' this is one method of filtering incomming messages specially ' when the networth send you a promotional messages ' ' If Reply = Err Then SCAN_SENSOR ' Check Sensor activity If SMSLength > 118 Then ' If message too long then... GoSub DELETE_IT ' ... delete it. EndIf ' End of statement
' ' Extract last 8 byte of recieved message in pdu format ' and store it in DataBuffer ' DataLength = 16 ' Set the Data Lenght GoSub TRACK_1ST_CHAR ' Find it! ; Now VarX has the location of 1st character Clear VarY ' Clear counter Repeat ' Make another loop DataBuffer[VarY]=GlobalBuffer[VarX] ' Store data Inc VarY : Inc VarX ' Increment array counter Until VarY = 8 ' Finish the job GoSub COMPARE_8BYTE_DATA ' Compare Data for posible command GoSub PDU_MODE ' Set Phone to PDU Mode GoTo MAIN_LOOP ' Go back to main loop
SCAN_SENSOR: ' ' Your sensor monitoring here ' DelayMS 5000 GoTo MAIN_LOOP '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BEGIN_COMPARE: 'RETRIEVE_EEPROM_DATA: ' ' First we will check the sender mobile number if valid ' if not valid go direct to delete-it and go back to main_loop ' Clear VarX ' Point to Address 0 of onboard eeprom Repeat ' Make a loop as dictated by VarX If ERead VarX <> MobileBuffer[VarX] Then ' Compare Mobile number GoTo DELETE_IT ' Delete message if not valid EndIf ' End of statement Inc VarX ' Increment counter Until VarX = 12 ' Finish The Job RETRIEVE_EEPROM_DATA: ' ' Next we will retrieve the eeprom data and store it to GlobalBuffer for comparison ' GoSub READ_EEPROM ' ' Then let's Compare the extracted last 8byte (PDU FORMAT) which was previously ' stored in DataBuffer to GlobalBuffer (Now holding the eeprom data) ' Compare = Equal : Clear VarX ' Set Initial value Repeat ' Make a loop as dictated by VarX If GlobalBuffer[VarX] <> DataBuffer[VarX] Then ' Compare data Compare = NotEqual ' Clear if not Equal Return ' Bye! EndIf ' End of statement Inc VarX ' Increment counter Until VarX = 8 ' Finish the job ' ' Here the result Comparison is Equal ' So lets clear the GlobalBuffer for acknowledgement ' GoSub CLEAR_BUFFER ' Clear GlobalBuffer Return
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ COMPARE_8BYTE_DATA: ' ' This lines are in text mode except when commented ' ' Lets extract first the sender mobile number in text mode ' and store it to MobileBuffer ' ' Here is the received message in text mode after executing HSEROUT ["AT+CMGR=1",CR] ' HSERIN 1000,MESSAGE_TIMEOUT,[WAIT(CR,CR,LF),STR GlobalBuffer] ' CR = CARRIAGE RETURN - LF = LINE FEED ' ' 111111111122222222223333333333444444444455555555 5 566666666 6 6 7 777 7 777.. ' 0123456789012345678901234567890123456789012345678901234567 8 901234567 8 9 0 123 4 567.. ' +CMGR: "REC READ","944502414110","BONI SATO","10/02/18,13:56:53+18",145,4,0,0,"966505031999",145,6 ' ' We can then see the exact location of phone number starting at array 20 ' GoSub TEXT_MODE ' Set Phone to TEXT Mode GoSub READ_GSM ' Read Phone Memory 1 Clear VarY ' Clear the counter VarX = 19 ' Point to 1st number Repeat ' Make a loop as dictated by SMSLength MobileBuffer[VarY]=GlobalBuffer[VarX] ' Store it to MobileBuffer Inc VarX:Inc VarY ' Increment counters Until VarY = 13 ' Finish the job
"Sim900D code at page 20, post #390"
|
|
|
|
|
Logged
|
Simpler designs are usually better.
|
|
|
|
The Philippine Electronics and Technology Forum
|
 |
« on: December 18, 2009, 03:35:12 PM » |
|
|
|
|
|
|
Logged
|
|
|
|
Kaizer03
Nuclear Reactor
  
Pogi/Ganda Points: 219
Offline
Posts: 4624
C#<-->Android<-->Java
|
 |
« Reply #1 on: December 18, 2009, 04:21:14 PM » |
|
points for you tita kulet...
ayun even basic ito at di ko alam yan.. medjo luminaw na din saken yung kailangan ko=) yung sa CR at LF filter=)
thanks... apply ko ito sa sunday(hopefully)=)
|
|
|
|
|
Logged
|
Lend a hand for those who are in need!=) Stop Hijacking!=) More Technical Posts!=) DataSheets are enough to answer your questions! Kaizer Killer EX Pre-Alpha
|
|
|
|
The Philippine Electronics and Technology Forum
|
 |
« Reply #1 on: December 18, 2009, 04:21:14 PM » |
|
|
|
|
|
|
Logged
|
|
|
|
waterbender
Size AA Battery
  
Pogi/Ganda Points: 17
Offline
Posts: 125
:)
|
 |
« Reply #2 on: December 18, 2009, 05:01:37 PM » |
|
+1  , now i can learn how to do this sa ibang MCU. haha nice master coolet. 
|
|
|
|
|
Logged
|
SELECT love FROM definition_of_things_in_my_life WHERE life = 'Happy' AND sadness_level = 0 AND when_with_you = '  ' AND when_without_you = '  '; -> ♥MyrEnE♥
|
|
|
|
The Philippine Electronics and Technology Forum
|
 |
« Reply #2 on: December 18, 2009, 05:01:37 PM » |
|
|
|
|
|
|
Logged
|
|
|
|
maldihtah13
Technical People
Nuclear Reactor
   
Pogi/Ganda Points: 114
Offline
Gender: 
Posts: 4499
Everyday is a learning process so try to learn ;D
|
 |
« Reply #3 on: December 18, 2009, 09:42:11 PM » |
|
Nice one sis coolet.
The most important part of the message can be extracted in PDU mode. Usually yung mga password at keyword eh sa PDU ko kinukuha kasi mas fixed ang length nito compared sa text message.
|
|
|
|
|
Logged
|
|
|
|
Co0LėT♥
Hydroelectric
 
Pogi/Ganda Points: 368
Offline
Gender: 
Posts: 3330
|
 |
« Reply #4 on: December 18, 2009, 10:10:09 PM » |
|
uyy thanks sa points  sis malditah tama po kayo... sa mga susunod na post pakita natin kung pano butingtingin ang PDU  ito na ang code... '**************************************************************** '* Name : BenQ.BAS * '* Author : Coolet * '* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 12/18/2009 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' Device Programming Options ' -------------------------- ' Device 16F628 ' We are using a PIC16F628 (18PIN SMD) Declare Xtal = 20 ' And a 20MHz crystal Optimiser_Level = 2 ' 0 to 6 Declare Reminders OFF Config HS_OSC , WDT_OFF , PWRTE_ON , BODEN_OFF , LVP_OFF , CP_OFF , MCLRE_OFF Declare Reminders On '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' Hardware Assignments ' -------------------- ' Hserial_RCSTA=$90 Hserial_TXSTA=$24 Hserial_SPBRG=10 ' 115200 Bauds Hserial_Clear=On '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' RAM Assignments and Variables ' ----------------------------- ' Dim Reply As Bit ' Phone Reply status Dim VarX As Byte ' Global variable Dim VarY As Byte ' Global variable Dim VarZ As Byte ' Global variable Dim Address As Byte ' Onboard eeprom Address Dim GlobalBuffer[120] As Byte ' Sms storage & General storage ' PIN assignment Symbol Sensor1 = PORTA.1 ' Any Sensor and any port you like Symbol PWON = PORTA.2 ' Any port you like ' ' Program Constants ' ----------------- ' Symbol CR = 13 ' Carriage Return Symbol LF = 10 ' Line Feed Symbol CTRL_Z = 26 ' Control + Z key Symbol Err = 0 ' As in Error Symbol OK = 1 ' I'm fine Symbol Equal = 1 ' As in Equal Symbol NotEqual = 0 ' As in not Equal Symbol NoMessage = 0 ' No Message in Memory Location 1
DelayMS 500 ' Half seconds delay for Pic to initialized
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~MAIN PROGRAM~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ START: Clear ' Reset Ram High PWON ' Turn on BenQ DelayMS 200 ' BenQ needs at least >150mS pulse to power on, Lets give it 200mS Low PWON ' Set to low DelayMS 3000 ' Wait 3 seconds for Benq to initialized ' ' Mobile Auto Detection ' CONNECT: GoSub SEND_AT_COMMAND ' Check for Phone activity If Reply = OK Then ' Yes! Phone found! Inc VarX ' Let's check again to be sure connector... If VarX > 3 Then ' ... is properly fixed! Try 3x GoSub DELETE_IT ' Delete 1st 2 memory location Clear VarX ' Reset counter DelayMS 1000 ' Wait GoSub PDU_MODE ' Set to PDU Mode GoTo MAIN_LOOP ' Bye! Ready for action EndIf ' End of statement Else ' Otherwise DelayMS 3000 ' Rest for 3Secs EndIf ' End of statement GoTo CONNECT ' Check the phone again
MAIN_LOOP: ' ' Let's see if a new message arrive ' ' Phone reply if no message(ONLINE): +CMS ERROR: 321 (without "OK") ' Variable REPLY always contains ERR. It will change only ' when it detects "OK". ' ' GoSub READ_GSM ' Check Inbox for new message ' ' No message or message too long ' this is one method of filtering incomming messages specially ' when the networth send you a promotional messages ' ' If Reply = NoMessage Then ' No message GoTo SCAN_SENSOR ' Check Sensor activity EndIf ' End of statement If VarY > 118 Then ' If message too long then... GoSub DELETE_IT ' ... delete it. GoTo SCAN_SENSOR ' Check Sensor activity EndIf ' End of statement ' ' ' ' Here your code if BenQ receive a command message ' What action will it do? ' ' ' GoTo MAIN_LOOP SCAN_SENSOR: ' ' Your sensor monitoring here ' ' if any abnormalities then send a message If Sensor1 = 1 Then GoSub SEND_MESSAGE EndIf GoTo MAIN_LOOP
'~~~~~~~~~~~~~~~~~~~~~SUBROUTINES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' Check gms if present ' SEND_AT_COMMAND: GoSub CLEAR_BUFFER ' Prepare Array HSerOut ["AT",CR] ' Check ONLINE connection GoSub GET_REPLY ' Check the responce of Phone Return ' Bye!
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DELETE_IT: ' ' DELETE MEMORY LOCATION 1 TO 4 OF SM ' DelayMS 1000 ' Go and take a nap HSerOut ["AT+CMGD=1;+CMGD=2",CR] ' Delete Phone memory 1 & 2 DelayMS 2000 ' Wait Phone to finish the job Return ' Bye! '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PDU_MODE: ' ' Instruct the phone to use Text Mode ' ' CR = 13 CARRIAGE RETURN ' HSerOut["AT+CMGF=0",CR] ' Send AT COMMAND Return ' Bye!
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CLEAR_BUFFER: Clear Address ' Clear Address Repeat ' Make a loop as dictated by Address GlobalBuffer[Address]=" " ' Clear Array Inc Address ' Increment Address Until Address = 120 ' Finish the job! Return ' Bye!
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ READ_GSM: ' Let's Mask the GlobalBuffer first ' ' Insted of clearing the array, we will fill it with "#" character. ' This is one way of tracking the end of line and for tracking the "OK"... ' ... returned by the phone. ' ' Clear VarX ' Clear counter VarX Repeat ' Make a loop as dictated by VarX GlobalBuffer[VarX]="#" ' Fill array with "#" character Inc VarX ' Increment counter Until VarX = 120 ' Finish the job DelayMS 50 ' Wait ' ' ' Read memory location 1 of the phone sim card ' ' CR = 13 CARRIAGE RETURN ' HSerOut ["AT+CMGR=1",CR] ' Read memory location 1 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GET_REPLY: ' ' Wait for CR,CR & LF before storing data ' When no more data, exit to "TIMEOUT" label ' HSerIn 300,TIMEOUT,[Wait(CR,CR,LF),Str GlobalBuffer] TIMEOUT: ' ' Let's see now if a message is present at memory location 1 ' Phone will return "+CMS ERROR: 321" if no message and obviuosly "OK" ' if the memory is loaded. ' Reply = Err : Clear VarY ' Set Initial value Repeat ' Make a loop as dictated by VarY If GlobalBuffer[VarY]="O" Then ' Sort ASCII "O" If GlobalBuffer[VarY+1]="K" Then ' Sort ASCII "K" Reply = OK ' Set if True Return ' Bye if True EndIf ' End of 2nd statement EndIf ' End of 1st statement Inc VarY ' Increment Array pointer Until VarY = 120 ' Finish the job Return ' Bye! '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SEND_MESSAGE: ' AT+CMGS=" PHONE NUMBER " <CR> ' HELLO <CTRL+Z> ' ' CTRL_Z= Control + Z = 26 ' 34 is character " ' CR = 13 CARRIAGE RETURN HSerOut ["AT+CMGS=",34,"PHONE NUMBER",34,CR] ' Send phone number to BenQ DelayMS 2000 ' Wait 1 sec HSerOut ["SUNOG",26] ' Send the Message DelayMS 100 ' Wait Return ' go back
|
|
|
|
|
Logged
|
Simpler designs are usually better.
|
|
|
babytoybits
Size AA Battery
  
Pogi/Ganda Points: 2
Offline
Gender: 
Posts: 138
|
 |
« Reply #5 on: December 18, 2009, 11:04:16 PM » |
|
uyy thanks sa points  sis malditah tama po kayo... sa mga susunod na post pakita natin kung pano butingtingin ang PDU  ito na ang code... '**************************************************************** '* Name : BenQ.BAS * '* Author : Coolet * '* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 12/18/2009 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' Device Programming Options ' -------------------------- ' Device 16F628 ' We are using a PIC16F628 (18PIN SMD) Declare Xtal = 20 ' And a 20MHz crystal Optimiser_Level = 2 ' 0 to 6 Declare Reminders OFF Config HS_OSC , WDT_OFF , PWRTE_ON , BODEN_OFF , LVP_OFF , CP_OFF , MCLRE_OFF Declare Reminders On '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' Hardware Assignments ' -------------------- ' Hserial_RCSTA=$90 Hserial_TXSTA=$24 Hserial_SPBRG=10 ' 115200 Bauds Hserial_Clear=On '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' RAM Assignments and Variables ' ----------------------------- ' Dim Reply As Bit ' Phone Reply status Dim VarX As Byte ' Global variable Dim VarY As Byte ' Global variable Dim VarZ As Byte ' Global variable Dim Address As Byte ' Onboard eeprom Address Dim GlobalBuffer[120] As Byte ' Sms storage & General storage ' PIN assignment Symbol Sensor1 = PORTA.1 ' Any Sensor and any port you like Symbol PWON = PORTA.2 ' Any port you like ' ' Program Constants ' ----------------- ' Symbol CR = 13 ' Carriage Return Symbol LF = 10 ' Line Feed Symbol CTRL_Z = 26 ' Control + Z key Symbol Err = 0 ' As in Error Symbol OK = 1 ' I'm fine Symbol Equal = 1 ' As in Equal Symbol NotEqual = 0 ' As in not Equal Symbol NoMessage = 0 ' No Message in Memory Location 1
DelayMS 500 ' Half seconds delay for Pic to initialized
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~MAIN PROGRAM~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ START: Clear ' Reset Ram High PWON ' Turn on BenQ DelayMS 200 ' BenQ needs at least >150mS pulse to power on, Lets give it 200mS Low PWON ' Set to low DelayMS 3000 ' Wait 3 seconds for Benq to initialized ' ' Mobile Auto Detection ' CONNECT: GoSub SEND_AT_COMMAND ' Check for Phone activity If Reply = OK Then ' Yes! Phone found! Inc VarX ' Let's check again to be sure connector... If VarX > 3 Then ' ... is properly fixed! Try 3x GoSub DELETE_IT ' Delete 1st 2 memory location Clear VarX ' Reset counter DelayMS 1000 ' Wait GoSub PDU_MODE ' Set to PDU Mode GoTo MAIN_LOOP ' Bye! Ready for action EndIf ' End of statement Else ' Otherwise DelayMS 3000 ' Rest for 3Secs EndIf ' End of statement GoTo CONNECT ' Check the phone again
MAIN_LOOP: ' ' Let's see if a new message arrive ' ' Phone reply if no message(ONLINE): +CMS ERROR: 321 (without "OK") ' Variable REPLY always contains ERR. It will change only ' when it detects "OK". ' ' GoSub READ_GSM ' Check Inbox for new message ' ' No message or message too long ' this is one method of filtering incomming messages specially ' when the networth send you a promotional messages ' ' If Reply = NoMessage Then ' No message GoTo SCAN_SENSOR ' Check Sensor activity EndIf ' End of statement If VarY > 118 Then ' If message too long then... GoSub DELETE_IT ' ... delete it. GoTo SCAN_SENSOR ' Check Sensor activity EndIf ' End of statement ' ' ' ' Here your code if BenQ receive a command message ' What action will it do? ' ' ' GoTo MAIN_LOOP SCAN_SENSOR: ' ' Your sensor monitoring here ' ' if any abnormalities then send a message If Sensor1 = 1 Then GoSub SEND_MESSAGE EndIf GoTo MAIN_LOOP
'~~~~~~~~~~~~~~~~~~~~~SUBROUTINES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ' Check gms if present ' SEND_AT_COMMAND: GoSub CLEAR_BUFFER ' Prepare Array HSerOut ["AT",CR] ' Check ONLINE connection GoSub GET_REPLY ' Check the responce of Phone Return ' Bye!
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DELETE_IT: ' ' DELETE MEMORY LOCATION 1 TO 4 OF SM ' DelayMS 1000 ' Go and take a nap HSerOut ["AT+CMGD=1;+CMGD=2",CR] ' Delete Phone memory 1 & 2 DelayMS 2000 ' Wait Phone to finish the job Return ' Bye! '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PDU_MODE: ' ' Instruct the phone to use Text Mode ' ' CR = 13 CARRIAGE RETURN ' HSerOut["AT+CMGF=0",CR] ' Send AT COMMAND Return ' Bye!
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CLEAR_BUFFER: Clear Address ' Clear Address Repeat ' Make a loop as dictated by Address GlobalBuffer[Address]=" " ' Clear Array Inc Address ' Increment Address Until Address = 120 ' Finish the job! Return ' Bye!
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ READ_GSM: ' Let's Mask the GlobalBuffer first ' ' Insted of clearing the array, we will fill it with "#" character. ' This is one way of tracking the end of line and for tracking the "OK"... ' ... returned by the phone. ' ' Clear VarX ' Clear counter VarX Repeat ' Make a loop as dictated by VarX GlobalBuffer[VarX]="#" ' Fill array with "#" character Inc VarX ' Increment counter Until VarX = 120 ' Finish the job DelayMS 50 ' Wait ' ' ' Read memory location 1 of the phone sim card ' ' CR = 13 CARRIAGE RETURN ' HSerOut ["AT+CMGR=1",CR] ' Read memory location 1 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GET_REPLY: ' ' Wait for CR,CR & LF before storing data ' When no more data, exit to "TIMEOUT" label ' HSerIn 300,TIMEOUT,[Wait(CR,CR,LF),Str GlobalBuffer] TIMEOUT: ' ' Let's see now if a message is present at memory location 1 ' Phone will return "+CMS ERROR: 321" if no message and obviuosly "OK" ' if the memory is loaded. ' Reply = Err : Clear VarY ' Set Initial value Repeat ' Make a loop as dictated by VarY If GlobalBuffer[VarY]="O" Then ' Sort ASCII "O" If GlobalBuffer[VarY+1]="K" Then ' Sort ASCII "K" Reply = OK ' Set if True Return ' Bye if True EndIf ' End of 2nd statement EndIf ' End of 1st statement Inc VarY ' Increment Array pointer Until VarY = 120 ' Finish the job Return ' Bye! '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SEND_MESSAGE: ' AT+CMGS=" PHONE NUMBER " <CR> ' HELLO <CTRL+Z> ' ' CTRL_Z= Control + Z = 26 ' 34 is character " ' CR = 13 CARRIAGE RETURN HSerOut ["AT+CMGS=",34,"PHONE NUMBER",34,CR] ' Send phone number to BenQ DelayMS 2000 ' Wait 1 sec HSerOut ["SUNOG",26] ' Send the Message DelayMS 100 ' Wait Return ' go back
wow...makikiss kita coolet!  e2 ang kailangan namin...  +1 ulit
|
|
|
|
|
Logged
|
Music is my passion but engineering will be my profession...^_^!
|
|
|
Co0LėT♥
Hydroelectric
 
Pogi/Ganda Points: 368
Offline
Gender: 
Posts: 3330
|
 |
« Reply #6 on: December 20, 2009, 01:06:28 PM » |
|
Why PDU MODE?The PDU format is quite complex, it contains many subfields packed together using different encodings. It holds service centre numbers, sender numbers, nation codes, a time stamp, and user data (text message).  For our tutorial, it is sufficient to know that the user data (text message) are on the rightmost position. Storing a "signature" from the last 8 byte of the message, the micro will be able to recognize incoming messages. How to convert Text Mode to PDU mode? This proved to be the more difficult part, and to avoid making PDU in scratc the trick is to send a message manually. In this way, the GSM will complete the PDU with all required fields, it will pack the text and numbers, and it will store it in the sent messages memory. Now using the hyperterminal you can then extract the PDU code. Example: sending "ARMED ALARM" to the GSM will produce a User Data as below. Take note that the produce user data is case sensitive and even space is computed to form a packed PDU. 41 69 B3 48 04 05 99 41 69 13 By extracting the last 8 byte of the User Data you can produce a signature which you can use as a command. Last 8 byte = 99 41 69 13. Storing this command to the onboard eeprom of the micro will be quite usefull since the micro will just compare it when the user send a command message to GSM. Next we will do the coding! Happy Reading! he he he
|
|
|
|
|
Logged
|
Simpler designs are usually better.
|
|
|
Co0LėT♥
Hydroelectric
 
Pogi/Ganda Points: 368
Offline
Gender: 
Posts: 3330
|
 |
« Reply #7 on: December 20, 2009, 10:45:58 PM » |
|
Here we go again  The procedure is straight forward. You don't have to enter data once the Micro is programmed. What u have to do is send "COOLET" to the system (default password), once the micro recognized the command it will save your mobile number to the onboard eeprom of the micro. Once your number is save, other mobile cannot access the GSM. Sending "ARMED ALARM" will set AlarmFlag to 1, if your mobile number is valid. Sending "DISARMED ALARM" will set AlarmFlag to 0, if your mobile number is valid. Sending "RELAY OFF" will set Relay1 to OFF, if your mobile number is valid. Sending "RELAY ON" will set Relay1 to ON, if your mobile number is valid. Sending "COOLET" will store your mobile number to onboard eeprom of the micro. So keep your password, any mobile can access the system if they know the password. You may want to change the password before programming, then be sure to enter the correct PDU code to the program. I had omitted some features including the change password routine on this program to let you practice your own programming skill. My main purpose for this thread is to give a starting point for a programmer to be. Any damage to your Mobile or GSM is not my fault. Do it at your own risk! Maraming salamat po at Maligayang Pasko sa lahat.Here is the code: 1D96b^S=@GR?8E8.*B*S,?2T,?42.DS'^aU[_^h/<@1'B#.39<*
|
|
|
|
|
Logged
|
Simpler designs are usually better.
|
|
|
Kaizer03
Nuclear Reactor
  
Pogi/Ganda Points: 219
Offline
Posts: 4624
C#<-->Android<-->Java
|
 |
« Reply #8 on: December 27, 2009, 08:13:27 PM » |
|
Question po=) heheh first time eh..=) im using PDU mode=) di naman ako nahirapan iconvert ehhehe =) galing ni google eh=) sa address length sender po ba ay laging 0C / 12? kasi di ba minsan sa phone eh 091xxxxxx ang nagreregister instead of 6391xxxxxx ? hehe=) and ask ko na din kasama ba talaga sa pagreply ng GSM module through TX pin nya yung +CMGR something +CMGR: 1,"Kaizer",21 0791361907002004040C91361926932525000090217281602523024132
like this =) kasama ba yung +CMGR: 1,"Kaizer",21 hehe parang ewan lang eh no? heheh atfirst kasi kala ko octet lang yung papadala nya kaya nadisregard ko sa code ko  ayan anjan na yung globe number ko.. hehe text nyo ko  wak nyo na idecode yung message kasi 'Ad' lang heheh=) eheh =) nasa filtering na ko ng incoming message kasi gusto ko na magtest 
|
|
|
|
|
Logged
|
Lend a hand for those who are in need!=) Stop Hijacking!=) More Technical Posts!=) DataSheets are enough to answer your questions! Kaizer Killer EX Pre-Alpha
|
|
|
Co0LėT♥
Hydroelectric
 
Pogi/Ganda Points: 368
Offline
Gender: 
Posts: 3330
|
 |
« Reply #9 on: December 27, 2009, 09:22:37 PM » |
|
Question po=) heheh first time eh..=) im using PDU mode=) di naman ako nahirapan iconvert ehhehe =) galing ni google eh=) sa address length sender po ba ay laging 0C / 12? kasi di ba minsan sa phone eh 091xxxxxx ang nagreregister instead of 6391xxxxxx ? hehe=) and ask ko na din kasama ba talaga sa pagreply ng GSM module through TX pin nya yung +CMGR something like this =) kasama ba yung +CMGR: 1,"Kaizer",21 hehe parang ewan lang eh no? heheh atfirst kasi kala ko octet lang yung papadala nya kaya nadisregard ko sa code ko  ayan anjan na yung globe number ko.. hehe text nyo ko  wak nyo na idecode yung message kasi 'Ad' lang heheh=) eheh =) nasa filtering na ko ng incoming message kasi gusto ko na magtest  yes kasama ang +CMGR: 1 ... you can see the colon, that means galing ng GSM. then yung OC i think hindi nababago yun sis. pwera na lang kung mahaba or maikli ang cp number.. napi-filter na sa provider yung 0 at 63... bali binabasihan ata eh yung 91 = international.. d rin ako cgurado... pero d ko pa yan naencounter he he he 
|
|
|
|
|
Logged
|
Simpler designs are usually better.
|
|
|
Kaizer03
Nuclear Reactor
  
Pogi/Ganda Points: 219
Offline
Posts: 4624
C#<-->Android<-->Java
|
 |
« Reply #10 on: December 28, 2009, 01:08:31 AM » |
|
yes kasama ang +CMGR: 1 ... you can see the colon, that means galing ng GSM. then yung OC i think hindi nababago yun sis. pwera na lang kung mahaba or maikli ang cp number.. napi-filter na sa provider yung 0 at 63... bali binabasihan ata eh yung 91 = international.. d rin ako cgurado... pero d ko pa yan naencounter he he he  ayun thanks.. kasi kokonsider ko sana yung 12 or 11 if 63 or 9 eh.. disregard ko na lang sya.. .ayun about dun sa + na yun.. hehe konting usog ko pa pala=) point for you!=)
|
|
|
|
|
Logged
|
Lend a hand for those who are in need!=) Stop Hijacking!=) More Technical Posts!=) DataSheets are enough to answer your questions! Kaizer Killer EX Pre-Alpha
|
|
|
Kaizer03
Nuclear Reactor
  
Pogi/Ganda Points: 219
Offline
Posts: 4624
C#<-->Android<-->Java
|
 |
« Reply #11 on: December 30, 2009, 04:07:32 PM » |
|
heheh ngayon ko lang napansin.. yung GSM na gamit ko 6pins ang JP6 ko=)
pero probably
1-VDD 2-TX 3-RX 4-PWON 5-THRU 6-GND
hehe double check ko..haha wala sa Datasheet yung M33A eh
|
|
|
|
|
Logged
|
Lend a hand for those who are in need!=) Stop Hijacking!=) More Technical Posts!=) DataSheets are enough to answer your questions! Kaizer Killer EX Pre-Alpha
|
|
|
Co0LėT♥
Hydroelectric
 
Pogi/Ganda Points: 368
Offline
Gender: 
Posts: 3330
|
 |
« Reply #12 on: December 30, 2009, 04:25:58 PM » |
|
Di na daw availabale ang BenQ.. Meron silang mas mura http://e-gizmo.com/wordpress/?p=65 be release in 2010
|
|
|
|
|
Logged
|
Simpler designs are usually better.
|
|
|
Kaizer03
Nuclear Reactor
  
Pogi/Ganda Points: 219
Offline
Posts: 4624
C#<-->Android<-->Java
|
 |
« Reply #13 on: December 30, 2009, 04:36:08 PM » |
|
^
Qisda yung manufacturer nung nasa akin.. hehe di naman akin ito eh.. dun sa nagpapatulong saken =)
hehe anyway... trace ko na lang kung ano anong pin ito=)
|
|
|
|
|
Logged
|
Lend a hand for those who are in need!=) Stop Hijacking!=) More Technical Posts!=) DataSheets are enough to answer your questions! Kaizer Killer EX Pre-Alpha
|
|
|
Co0LėT♥
Hydroelectric
 
Pogi/Ganda Points: 368
Offline
Gender: 
Posts: 3330
|
 |
« Reply #14 on: December 30, 2009, 05:53:28 PM » |
|
|
|
|
|
|
Logged
|
Simpler designs are usually better.
|
|
|
Kaizer03
Nuclear Reactor
  
Pogi/Ganda Points: 219
Offline
Posts: 4624
C#<-->Android<-->Java
|
 |
« Reply #15 on: December 30, 2009, 07:34:23 PM » |
|
^ thanks.. hehe ganun din magttrace pa rin ako  . kulang eh..pero ok lang=) carry naman ito =) hehehe
|
|
|
|
|
Logged
|
Lend a hand for those who are in need!=) Stop Hijacking!=) More Technical Posts!=) DataSheets are enough to answer your questions! Kaizer Killer EX Pre-Alpha
|
|
|
rayleigh
CR2032 Battery

Pogi/Ganda Points: 1
Offline
Posts: 17
kamotis
|
 |
« Reply #16 on: January 05, 2010, 10:52:58 AM » |
|
heheh ngayon ko lang napansin.. yung GSM na gamit ko 6pins ang JP6 ko=)
pero probably
1-VDD 2-TX 3-RX 4-PWON 5-THRU 6-GND
hehe double check ko..haha wala sa Datasheet yung M33A eh
6 pins din po ung sakin benq... ano po un ung nasa manual wala pong vdd 5 pins lng nakalagay...edi ung vdd po lagay ko po sa 5v o 3v? un pinost nyu po pin1 vdd pero sa manual ang pin1 TTL-TXD nakakalito na po T_T meron po ako ginawa program tinatrial and error ko lng po di pa po ako marunong pede po ba mag pa check sa inu? mikrobasic po to: program GSM
symbol CR = 13 ' Carriage Return Symbol CTRL_Z = 26 ' Control + Z key
dim count as byte main: trisb.3=0
portb.3=1 delay_ms(500) portb.3=0 delay_ms(3000)
'Usart_Read_Text(txt, delim) 'Usart_Write_Text(txt)
USART_init(9600) Usart_Write_Text("AT") delay_ms(3000) usart_write(CR) delay_ms(1000)
Usart_Write_Text("ATE1") delay_ms(1000) usart_write(CR) delay_ms(1000)
Usart_Write_Text("AT+CMGF=1") delay_ms(1000) usart_write(CR) delay_ms(1000)
Usart_Write_Text("AT+CFUN=1") delay_ms(1000) usart_write(CR) delay_ms(1000)
Usart_Write_Text("AT+CMGS=") delay_ms(1000) Usart_Write_Text("09274810123") delay_ms(1000) usart_write(CR) delay_ms(1000) Usart_Write_Text("kamotis") delay_ms(1000) usart_write(CTRL_Z) delay_ms(1000)
end. THANKS MASTERS 
|
|
|
|
|
Logged
|
How did you know that you cannot do it if you did not try...  $$
|
|
|
Kaizer03
Nuclear Reactor
  
Pogi/Ganda Points: 219
Offline
Posts: 4624
C#<-->Android<-->Java
|
 |
« Reply #17 on: January 05, 2010, 11:16:14 AM » |
|
6 pins din po ung sakin benq... ano po un ung nasa manual wala pong vdd 5 pins lng nakalagay...edi ung vdd po lagay ko po sa 5v o 3v? un pinost nyu po pin1 vdd pero sa manual ang pin1 TTL-TXD nakakalito na po T_T meron po ako ginawa program tinatrial and error ko lng po di pa po ako marunong pede po ba mag pa check sa inu? mikrobasic po to: program GSM
symbol CR = 13 ' Carriage Return Symbol CTRL_Z = 26 ' Control + Z key
dim count as byte main: trisb.3=0
portb.3=1 delay_ms(500) portb.3=0 delay_ms(3000)
'Usart_Read_Text(txt, delim) 'Usart_Write_Text(txt)
USART_init(9600) Usart_Write_Text("AT") delay_ms(3000) usart_write(CR) delay_ms(1000)
Usart_Write_Text("ATE1") delay_ms(1000) usart_write(CR) delay_ms(1000)
Usart_Write_Text("AT+CMGF=1") delay_ms(1000) usart_write(CR) delay_ms(1000)
Usart_Write_Text("AT+CFUN=1") delay_ms(1000) usart_write(CR) delay_ms(1000)
Usart_Write_Text("AT+CMGS=") delay_ms(1000) Usart_Write_Text("09274810123") delay_ms(1000) usart_write(CR) delay_ms(1000) Usart_Write_Text("kamotis") delay_ms(1000) usart_write(CTRL_Z) delay_ms(1000)
end. THANKS MASTERS  di ko pa sya nadodouble check... busy pa=) yeah probably yung pin 1 sa 6pins eh VDD.. wag kang malito..itrace mo lang kung san connected yung pins sa JP5=)
|
|
|
|
|
Logged
|
Lend a hand for those who are in need!=) Stop Hijacking!=) More Technical Posts!=) DataSheets are enough to answer your questions! Kaizer Killer EX Pre-Alpha
|
|
|
rayleigh
CR2032 Battery

Pogi/Ganda Points: 1
Offline
Posts: 17
kamotis
|
 |
« Reply #18 on: January 05, 2010, 02:48:26 PM » |
|
|
|
|
|
|
Logged
|
How did you know that you cannot do it if you did not try...  $$
|
|
|
Co0LėT♥
Hydroelectric
 
Pogi/Ganda Points: 368
Offline
Gender: 
Posts: 3330
|
 |
« Reply #19 on: January 05, 2010, 02:54:28 PM » |
|
nice!  share mo naman dito ang na-experience mo at code mo para makatulong din sa iba  EDIT: ano ba ang tamang pinpout ng modem mo?
|
|
|
|
|
Logged
|
Simpler designs are usually better.
|
|
|
|
The Philippine Electronics and Technology Forum
|
|
|
|
|
|
Logged
|
|
|
|
|