kevinyeandel
Joined: 11 Jun 2008 Posts: 4
|
is lack of INT_RDA the problem? |
Posted: Fri Jun 13, 2008 7:27 pm |
|
|
Hi
Been searching this forum and think my problem is that I don't fully understand how to handle the gets() properly. I am using the hw uart as can be seen. Basically the code below AT's a modem, turns off the echo back to the terminal and configs it to receive all messages, read or otherwise.
It is in the last while{}do as commented that the program will return 200 chars exactly of the data shown or nothing at all.
I wondered if I could ask for some dumbed-down pointers on how better to write the code around the gets maybe using INT_RDA? When I get the messages I want to extract a sequence and delete the message. So if anyone has the patience to help me past this bit I will be very grateful (and I have spent about 2 hours searching this forum, I hope I didn't miss anything!).
Many thanks in advance.
Kevin
Code: | #include <18F4520.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay (clock = 4000000)
#include <string.h>
char instr[600],search1[10];
// 160 for the sms message plus overhead, call it 200
#include "lcd.c"
#define LCD
//====================================
#using a picdem 2 plus Rev 6, RS232 DB9 4 and 6 connected together,
# 1,7,8,9 not connected. 2 3 5 are used. Null modem loop back connector
#between modem and picdem
#wired with:
# RX (2) to TX (3)
# TX (3) to RX (2)
# sig gnd (5) to (5)
# DTR (1) + CD (4) + DSR (6)
# DTR (1) + CD (4) + DSR (6)
# RTS (7) to CTS (8)
# CTS (8) to RTS (7)
#
int u;
void main()
{
#ifdef LCD
// output_high(MODEM_POWER);
output_high(LCD_POWER); // Turn on power to LCD
output_low(LCD_RW); // Set R/W pin on LCD to a low level
lcd_init(); // Always call this first.
#endif
//enable_interrupts(INT_RDA); // could do with an example
#USE RS232(BAUD=57600,XMIT=PIN_C6,RCV=PIN_C7,PARITY=N,STOP=1,BITS=8) /* xmit pin c6 rcv c7 */
delay_ms(500);
printf("ATE0");
putc(0x0d);
delay_ms(20);
// 0D 0D 0A 4F 4B 0D 0A ...OK.. (CR CR LF) OK (CR LF)
gets(instr);
gets(instr);
output_high(PIN_B0);
delay_ms(550);
printf(lcd_putc, "\f");
printf(lcd_putc,"ATE0 DONE");
// OD 0A 4F 4B 0D 0A ..OK..
output_low(PIN_B0);
delay_ms(500);
output_high(PIN_B0);
delay_ms(500);
printf("AT+CMGF=1"); //0D 0A 4F 4B 0D 0A ..OK..
putc(0x0d);
gets(instr);
gets(instr);
printf(lcd_putc,"\f");
printf(lcd_putc, "CMGF=1 DONE");
delay_ms(1000);
output_low(PIN_B0);
search1[0]=0x4F;
search1[1]=0x4B;
search1[2]=0x0D;
search1[3]=0x0A;
search1[4]=0x00; // terminate
printf("AT+CMGL=\"ALL\""); // get all messages
putc(0x0d);
delay_ms(1000);
printf(lcd_putc,"\f"); // clear screen
do{
output_high(PIN_B0);
gets(instr); // reads exactly 200 chars then stuck here
printf(lcd_putc,instr); delay_ms(1000);
u = strstr(instr,search1); //last line is OK<cr><lf><null>
output_low(PIN_B0);
}while (u==0);
}
0D 0A 2B 43 4D 47 4C 3A 20 32 2C 22 52 45 43 20 ..+CMGL: 2,"REC
52 45 41 44 22 2C 22 6B 65 76 69 6E 79 65 61 6E READ","kevinyean
64 65 22 2C 2C 22 30 38 2F 30 36 2F 31 30 2C 32 de",,"08/06/10,2
30 3A 31 32 3A 31 39 2B 30 34 22 0D 0A 41 4E 43 0:12:19+04"..ANC
51 20 24 65 32 34 39 63 64 66 34 39 64 64 35 33 Q $e249cdf49dd53
36 37 63 20 31 32 39 36 0D 0A 0D 0A 2B 43 4D 47 67c 1296....+CMG
4C 3A 20 33 2C 22 52 45 43 20 52 45 41 44 22 2C L: 3,"REC READ",
22 54 43 4F 22 2C 2C 22 30 38 2F 30 36 2F 31 30 "TCO",,"08/06/10
2C 32 31 3A 30 33 3A 31 37 2B 30 34 22 0D 0A 48 ,21:03:17+04"..H
65 6C 6C 6F 20 74 68 69 73 20 69 73 20 61 20 74 ello this is a t
65 73 74 20 77 69 74 68 20 61 6E 20 61 6D 70 65 est with an ampe
72 73 61 6E 64 20 28 26 29 20 61 6E 64 20 61 20 rsand (&) and a
35 20 6E 6F 74 65 0D 0A 0D 0A 2B 43 4D 47 4C 3A 5 note....+CMGL:
20 34 2C 22 52 45 43 20 52 45 41 44 22 2C 22 54 4,"REC READ","T
43 4F 22 2C 2C 22 30 38 2F 30 36 2F 31 30 2C 32 CO",,"08/06/10,2
31 3A 32 30 3A 33 36 2B 30 34 22 0D 0A 48 65 6C 1:20:36+04"..Hel
6C 6F 20 74 68 69 73 20 69 73 20 61 20 74 65 73 lo this is a tes
74 20 77 69 74 68 20 61 6E 20 61 6D 70 65 72 73 t with an ampers
61 6E 64 20 28 26 29 20 61 6E 64 20 61 20 35 20 and (&) and a 5
6E 6F 74 65 0D 0A 0D 0A 2B 43 4D 47 4C 3A 20 35 note....+CMGL: 5
2C 22 52 45 43 20 52 45 41 44 22 2C 22 54 43 4F ,"REC READ","TCO
|
|
|