PDA

View Full Version : Exsrtacting data



Andre_Pretorius
- 20th April 2008, 17:01
Can anyone please help
I am trying to exstract data from a string of serial data from a sms modem
THE string
^SMGL: 1,"REC UNREAD","+27829554322",,"08/04/20,17:12:09+08"
test

I need to exstract the cell number from this after reading some posts recomending debugin
i tried hserin the idea is to use a interupt and as soon as data comes in decode it, test the sell number and if it is a recognized number ecsecute the command in the message field
This is the command i thought would work but my program hangs
HSERIN [WAIT("SMGL:"), SKIP 18 , V5]

Any help would be appreciated

mister_e
- 20th April 2008, 17:11
so ^SMGL: 1,"REC UNREAD","+27829554322",,"08/04/20,17:12:09+08" is EXACTLY what you see in hyperterminal or else terminal?

27829554322 should be the number to extract number by number and then compare with a specific one or a table of?

Did you tried with STR and a BYTE array?

Did you tried your hardware with a PC to PIC communication (with MAX232)?

Andre_Pretorius
- 21st April 2008, 20:39
Hi there,
I am using a serial port on my pc sending the data via an rs232 chip to a 16f913
Below is my code that shoed reply with the message number and the cell number but nothing happens any suggestions
[CODE]
INCLUDE "MODEDEFS.BAS"

DEFINE OSC 20 ' Define crystal as 20Mhz

'*Serial port Setup 9600 8N1*
DEFINE HSER_BAUD 9600 ; 9600 Baud
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ; Clear overflow automatically

'*ADC setup*
DEFINE ADC_BITS 10 'SETS NUMBER OF BITS IN RESULTS 8,10,12
DEFINE ADC_CLOCK 3 'SETS CLOCK SOURCE (RC = 3)
DEFINE ADC_SAMPLEUS 50 'SETS SAMPLING TIME IN MICROSECONDS

'This Part set PORTA 0-5 an analog inputs
ADCON1 = %01110000 'FRC (clock derived from a dedicated internal oscillator = 500 kHz max)
ANSEL = %00011111 'The ANSEL (91h) and CMCON0 (9Ch)registers must be initialized to configure an
CMCON0 = %00000111 'analog channel as a digital input. Pins configured as analog inputs will read ‘0’.
TRISA = %00011111 'set PORTA 0-5 as inputs
ADCON0.7 = 1 'Right justify output of ADC datasheet P145 of 16F913

TRISC = %10000000 'Set PORTC for serial coms and pins as output
TRISB = %00000000 'Sert PORTb as outputs and for use with the ICD2

INTCON = 0 ;Disable interrupts


V1 var WORD
ID var byte[28]

PORTC = 0

loop:
'ADCIN 0,V1
HSERIN [WAIT("^SMGL:"),SKIP 1 ,str ID\28]
HSEROUT ["MES NO:",dec ID[0],10,13]
HSEROUT ["CELL NO:",dec ID[17],dec ID[18],dec ID[19],dec ID[20],dec ID[21],dec ID[22],dec ID[23],dec ID[24],dec ID[25],dec ID[26],10,13]

goto loop

END
[END CODE]

Ioannis
- 22nd April 2008, 07:00
Do you have a level translator between PIC-Phone? Like a MAX232?

Ioannis

Andre_Pretorius
- 22nd April 2008, 16:44
A this stage i use my PC to send the data to the pic via a SP232ACP chip

mister_e
- 22nd April 2008, 17:50
it works here using...


loop:
'ADCIN 0,V1
HSERIN [WAIT("^SMGL:"),SKIP 1 ,str ID\28]
HSEROUT ["MES NO:",ID[0],10,13]
HSEROUT ["CELL NO:",_
ID[17],iD[18],ID[19],ID[20],ID[21],ID[22],_
ID[23],ID[24],ID[25],ID[26],ID[27],10,13]

goto loop
<img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2533&stc=1&d=1208883003">
Check your Config fuses setting, make sure you have HS_OSC enabled.

Andre_Pretorius
- 22nd April 2008, 19:18
Thanks got it working ,needs to remember to copy all include files next time i format my pc