Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] how to get specific string?

Status
Not open for further replies.

saesaria

Member level 1
Joined
Jun 13, 2011
Messages
41
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Indonesia
Activity points
1,578
Hi!
I'm trying to get ONLY "+628987654321" (without quotes) from sequence string below

Code ASM - [expand]
1
+CMGR: "REC UNREAD","+628987654321",,"11/07/10,18:25:40+28"



I tried code below

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// LCD module connections
sbit LCD_RS at PORTD6_bit;
sbit LCD_EN at PORTD7_bit;
sbit LCD_D4 at PORTD2_bit;
sbit LCD_D5 at PORTD3_bit;
sbit LCD_D6 at PORTD4_bit;
sbit LCD_D7 at PORTD5_bit;
 
sbit LCD_RS_Direction at DDD6_bit;
sbit LCD_EN_Direction at DDD7_bit;
sbit LCD_D4_Direction at DDD2_bit;
sbit LCD_D5_Direction at DDD3_bit;
sbit LCD_D6_Direction at DDD4_bit;
sbit LCD_D7_Direction at DDD5_bit;
// End LCD module connections
 
char *output;
int res;
char txt_sub[] = "+CMGR: \"REC UNREAD\",\"";
 
void delay() {                  // Function untuk delay
  Delay_ms(10);                // delay 500 mili detik
}
 
void main() {
 
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  delay();                        // Wait for UART module to stabilize
  
  lcd_init();
  lcd_cmd(_lcd_clear);
  lcd_cmd(_lcd_cursor_off);
 
  lcd_out(1,1,"Read Data");
  uart1_write_text("AT+CMGR=1\r\n");
  delay();
 
  while (1) {
  if (UART1_Data_Ready() == 1) {          // if data is received
    UART1_Read_Text(output, "\",,\"", 255);    // reads text until '",,"' is found
    res = strcmp(output,txt_sub);
    uart1_write(res);
    res = '\x0';
    lcd_out(2,1,res);
     }
}
}



the code above gives me only "+" as the first occurrence character after string compare is match,
I want to get "+628987654321" complete string.
anyone here can share me the knowledge?
thanks.

---------- Post added at 20:41 ---------- Previous post was at 20:36 ----------

And actually I have implicit conversion of INT to PTR issue in

Code ASM - [expand]
1
lcd_out(2,1,res);

 
Last edited:

Hi nikhilele!
thanks for the reply, I tried it but still gives me implicit issue on the message list when I compile the code.
 

you want phone no correct,
for that use
char *mob_no
mob_no = strstr(output,"+");
now try to print the mob_no upto n-1 char it will give your no

---------- Post added at 15:12 ---------- Previous post was at 15:10 ----------

lcd_out(x,y,mob_no);
 

ups I forgot to close this thread, thanks to you nikhilele, you helped me. here I post the code

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// LCD module connections
sbit LCD_RS at PORTD6_bit;
sbit LCD_EN at PORTD7_bit;
sbit LCD_D4 at PORTD2_bit;
sbit LCD_D5 at PORTD3_bit;
sbit LCD_D6 at PORTD4_bit;
sbit LCD_D7 at PORTD5_bit;
 
sbit LCD_RS_Direction at DDD6_bit;
sbit LCD_EN_Direction at DDD7_bit;
sbit LCD_D4_Direction at DDD2_bit;
sbit LCD_D5_Direction at DDD3_bit;
sbit LCD_D6_Direction at DDD4_bit;
sbit LCD_D7_Direction at DDD5_bit;
// End LCD module connections
 
char output[255];
char txt_sub[] = "+62";
char *res;
char nomor[20];
char i=0;
char terima;
 
void delay() { // Fungsi untuk delay
Delay_ms(500); // delay 500 mili detik
}
 
void main() {
 
UART1_Init(9600); // Initialize UART module at 9600 bps
delay(); // Wait for UART module to stabilize
 
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_lcd_cursor_off);
 
lcd_out(1,1,"Read Data");
uart1_write_text("AT+CMGR=1");
UART1_Write(13);UART1_Write(10);
 
  while(1){
    while (terima == 0) {
      if (uart1_data_ready ()){
      UART1_Read_Text(output, "OK", 255);    // reads text until 'OK' is found
      terima = 1;
      }
   }
  lcd_cmd(_lcd_clear);
  lcd_out(1,1,"ada OK");
  terima = 0;
  delay();
  res = strstr(output,txt_sub);
  for(i=0; i<=12; i++)
  nomor[i] = *(res+i);
  nomor[i] = '\x0';
  lcd_out(2,1,nomor);
  }
}

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top