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.

Read SIM 1st massage and display it in a 20x4 LCD

Status
Not open for further replies.

Loosha

Newbie level 4
Joined
Apr 26, 2012
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,291
Location
Dhaka
Activity points
1,322
Hello every one.

I am trying to read SIM 1st massage and display it in a 20x4 LCD
I am using PIC18F2550,20x4 LCD and wavecom-gsm-gprs-modem-q2303a.
When I send this command .The reply is as below…

Code:
AT+CMGR=1
AT+CMGR=1

.+CMGR: "REC READ","+8801678715550",,"13/12/05,18:54:31+24"
.Hello Love Loo.This is a test massage.
OK

But when I try to display it in a LCD .It display only….

+CMGR: “RE

I want to display the whole massage
“Hello Love Loo.This is a test massage.”

LCD.gif

Can anyone help me out…

My Code......

Code:
'*******************************************************************
  #CONFIG
    __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_ON_2L
    __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L

  #ENDCONFIG
'****************************************************************
'Define OSC 48           ' Core is running at 48MHz
'******************** Definitions *******************************
'DEFINE OSC 4			'for 4 Mhz
DEFINE OSC 8			'for 8 Mhz

DEFINE HSER_TXSTA 20h	'I wonder shall I define as DEFINE HSER_TXSTA 24h???
DEFINE HSER_RCSTA 90h	'same for all

'DEFINE HSER_BAUD 2400	'for 2400 Baud rate
'DEFINE HSER_BAUD 4800	'for 4800 Baud rate
DEFINE HSER_BAUD 9600	'for 9600 Baud rate

'DEFINE HSER_SPBRG 25		'for 4Mhz/2400 & 8Mhz/4800 with an error %0.16
DEFINE HSER_SPBRG 12	'for 4Mhz/4800 & 8Mhz/9600 with an error %0.16

DEFINE HSER_CLROERR 1	'same for all

    DEFINE NO_CLRWDT               '// Saves 17 words code space   


'**************** Allocate variables ***************************
'****************  define variables  ***************************

    Sedata  var byte[40]
    TELNO   var byte[11]  ' array for phone number
    i       var byte      ' Define loop variable
    Sta     var bit
    Line    var byte    'LCD line address
    K       VAR BYTE    'counter
    KC      VAR BYTE    'counter

'******************* Initialization ****************************
    TRISA=%00000111    ' Set PORTD to all output
    TRISB=%00000000    ' Set PORTD to all output
    TRISC=%10000001    ' Set PORTD to all output

'    ansel=%00000011
    CMCON = 7
     

    PORTB=%00000000
    PORTA=%00000000
    Sta=0
    ADCON1 = 15          ' Set PORTA and PORTE to digital   

        Line = $80          'LCD 1st line
        K = 0
        KC = 0
'----------------- Define LCD pins ------------------------------  
    define  LCD_DREG    PORTB           ' LCD Data port
    define  LCD_DBIT    0               ' starting Data bit (0 or 4) if 4-bit bus
    define  LCD_RSREG   PORTB           ' LCD Register Select port
    define  LCD_RSBIT   5               ' LCD Register Select bit
    define  LCD_EREG    PORTB           ' LCD Enable port
    define  LCD_EBIT    4               ' LCD Enable bit
    define  LCD_LINES   4               ' Number of lines on LCD

'------------------------ End of Declare LCD -----------------------------  
    lcdout  $FE,$80,"GSM SMS Center V1.0 "  ' Display Key board V1.0
    Pause   1000                            ' Delay 1 Sec
    lcdout  $fe,$1                          ' Clear Screen
'--------------------------- mainloop -----------------------------------
GSM_CHECK:
    HSEROUT ["AT",13]                    'Send AT to modem followed by a CR
    HSERIN 5000, GSM_CHECK, [WAIT("OK")] 'Check OK reply, wait 5sec max.
    lcdout  $FE,$80," Step 1 "  ' Display Key board V1.0
    PAUSE 1000

    HSEROUT ["AT+IPR=9600",13]      'Set transfer speed
    HSERIN 5000, GSM_CHECK, [WAIT("OK")]'Check OK reply, wait 5sec max.
    lcdout  $FE,$80," Step 2 "  ' Display Key board V1.0
    PAUSE 1000

    HSEROUT ["AT+CMGF=1",13]            'send AT to modem followed by a CR and line feed
    HSERIN 5000, GSM_CHECK, [WAIT("OK")]'Check OK reply, wait 5sec max.
    lcdout  $FE,$80," Step 3 "  ' Display Key board V1.0 
    PAUSE 1000

BEGIN:
    if PORTC.0 = 0 & Sta=0 then
      goto SEND_SMS
     else
      goto READ_SMS
    endif
    PAUSE 1000

    GOTO BEGIN


READ_SMS:
    HSEROUT ["AT+CMGR=1",13]            'send AT to modem followed by a CR and line feed
    HSERIN 5000,READ_SMS,[WAIT("AT+CMGR=1"),STR Sedata\13]'Check OK reply, wait 5sec max.
'    Sedata = Sedata << 3
'   SKIP 10,
loo:
    lcdout $fe,Line+KC,Sedata[K]
        PAUSE 1000

        K = K+1
        KC = KC+1
        
        if K < 19 then goto loo
        
          KC = 0
          Line = $C0
         if K < 39 then goto loo

Looop:
    PAUSE 1000
        GOTO Looop

SEND_SMS:

    lcdout  $FE,$80," SMS Send >  > "  ' Display Key board V1.0 
    GOTO BEGIN

    
ERROR_SMS:
        LCDOut $fe,1,"NO RESPONS!",$fe,$c0,"CHECK SIM/PHONE"
        Pause 3000
        GOTO BEGIN

end
 
Last edited by a moderator:

Please post code in syntax tags. Syntax tags =

Code C - [expand]
1
2
3
code here [/syntax ] remove the spaces inside the tags. Mention the compiler used. Is it PBP 3.0.7 or PDS 3.5.5.5 code?
 
Use ISR to read data. dump to whole data into a array and terminate it with a dilimiter. Now parse the data for CMGR. If CMRG was found then loop until quotes count is 6. After that increment index twice so that index points to first character of message. Now read each character into another array till the end using delimiter check. Terminate the array with string terminator. Print string to LCD. Only read data into array in ISR when CMGR command is sent.

 
Last edited:

Hello Jayanth devareyanadurga

Thank for your help. I am not so much expert in programming and I am using the compiler PBP 3.0.6.0
Will you kindly edit my code and post
 

Your code is not compiling. It is giving 4 errors. Please post code which compiles. I am using PBP 3.0.7.1



Edit: Sorry, I can't help you with PBP. I haven't used it much. I use mikroC. If you want I can write code in mikroC or mikroBasic.


https://www.edaboard.com/threads/289454/
 
Last edited:

Hi

I need to know when SMS is sent in order to write a code. I need to know for why USB and ADC are used? I see you use LM35. Do you want to send LM35 data on SMS? Explain in detail so that I can write a sample code.
 

HI.

In this circuit I don't use the USB and LM35(ADC).
I just want to read the 1st massage in SIM and display it in a 20x4 line LCD.
 

I use C for programming. I have written a code in C and Basic version. If it works then post the screenshot and video of your project. See the Basic code below. If you want a better code then post AT+CMGR=x response for 10 random messages.


Code C - [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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Lcd pinout settings
sbit LCD_RS at LATB5_bit;
sbit LCD_EN at LATB4_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D4 at LATB0_bit;
 
// Pin direction
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
 
char gsmData[80];
unsigned int i = 0, j = 0;
 
void main() {
 
     TRISA = 0xFF;
     TRISB = 0x00;
     TRISC = 0x80;
     TRISD = 0x00;
     PORTA = 0x00;
     LATB = 0x00;
     PORTC = 0x00;
     PORTD = 0x00;
 
     LCD_Init();
     Lcd_Cmd(_LCD_CLEAR);
     Lcd_Cmd(_LCD_CURSOR_OFF);
     Lcd_Out(1,1,"GSM SMS Center V1.0");
 
     UART1_Init(9600);
     Delay_ms(500);
 
     INTCON = 0xC0;
 
 
     while(1) {
 
            i = 0;
            j = 0;
            
            UART_Write_Text("AT\r\n");
            UART1_Read_Text(gsmData, "OK", 10);
            LCD_Out(2,1,gsmData);
            
            UART_Write_Text("AT+CMFG=1\r\n");
            UART1_Read_Text(gsmData, "OK", 10);
            LCD_Out(2,1,gsmData);
 
            UART_Write_Text("AT+CMGR=185\r\n");
            UART1_Read_Text(gsmData, "OK", 40);
            while(gsmData[i] != '.')i++;
            i++;
            while(gsmData[i] != '.')i++;
            i++;
            while(gsmData[i]){
                    gsmData[j++] = gsmData[i++];
            }
            
            gsmData[j] = '\0';
            
            i = strlen(gsmData);
 
            for(j = 1; j < i; j++){
 
                    if((j >= 0) && (j < 20)){
                           LCD_Chr(1,j,gsmData[j-1]);
                    }
                    else if((j >= 20) && (j < 40)){
                           LCD_Chr(2,(j-20),gsmData[j-1]);
                    }
                    else if((j >= 40) && (j < 60)){
                           LCD_Chr(3,(j-40),gsmData[j-1]);
                    }
                    else if((j >= 60) && (j < 80)){
                           LCD_Chr(4,(j-60),gsmData[j-1]);
                    }
            }
            
            Delay_ms(5000);
 
     }
}




Code C - [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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
program gsmRead
 
' Declarations section
 
' Lcd module connections
dim LCD_RS as sbit at LATB5_bit
    LCD_EN as sbit at LATB4_bit
    LCD_D4 as sbit at LATB0_bit
    LCD_D5 as sbit at LATB1_bit
    LCD_D6 as sbit at LATB2_bit
    LCD_D7 as sbit at LATB3_bit
 
    LCD_RS_Direction as sbit at TRISB5_bit
    LCD_EN_Direction as sbit at TRISB4_bit
    LCD_D4_Direction as sbit at TRISB0_bit
    LCD_D5_Direction as sbit at TRISB1_bit
    LCD_D6_Direction as sbit at TRISB2_bit
    LCD_D7_Direction as sbit at TRISB3_bit
' End Lcd module connections
 
dim gsmData as char[80]
    i as word
    j as word
    
 
main:
'   Main program
 
    TRISA = $FF
    TRISB = $00
    TRISC = $80
    TRISD = $00
    PORTA = $00
    LATB = $00
    PORTC = $00
    PORTD = $00
 
    LCD_Init()
    Lcd_Cmd(_LCD_CLEAR)
    Lcd_Cmd(_LCD_CURSOR_OFF)
    Lcd_Out(1,1,"GSM SMS Center V1.0")
 
    UART1_Init(9600)
    Delay_ms(500)
 
    INTCON = $C0
    
    
    While(1)
    
            i = 0
            j = 0
 
            UART_Write_Text("AT")
            UART_Write(13)
            UART_Write(10)
            UART1_Read_Text(gsmData, "OK", 10)
            LCD_Out(2,1,gsmData)
 
            UART_Write_Text("AT+CMFG=1")
            UART_Write(13)
            UART_Write(10)
            UART1_Read_Text(gsmData, "OK", 10)
            LCD_Out(2,1,gsmData)
 
            UART_Write_Text("AT+CMGR=185")
            UART_Write(13)
            UART_Write(10)
            UART1_Read_Text(gsmData, "OK", 40)
            While(gsmData[i] <> ".")i = i + 1
            Wend
            i = i + 1
            While(gsmData[i] <> ".")i = i + 1
            Wend
            i = i + 1
            While(gsmData[i])
                    gsmData[j] = gsmData[i]
                    j = j + 1
                    i = i + 1
            Wend
 
            gsmData[j] = 0
 
            i = strlen(gsmData)
    
           j = 0
 
            While gsmData[j]
 
                    If((j >= 0) and (j < 20)) Then
                           LCD_Chr(1,(j+1),gsmData[j])
                    Else If((j >= 20) and (j < 40)) Then
                           LCD_Chr(2,(j-20),gsmData[j])
                    Else If((j >= 40) and (j < 60)) Then
                           LCD_Chr(3,(j-40),gsmData[j])
                    Else If((j >= 60) and (j < 80)) Then
                           LCD_Chr(4,(j-60),gsmData[j])
                    End If
                    End If
                    End If
                    End If
                 
                    j = j + 1
                    
            Wend
 
 
            Delay_ms(5000)
    
    Wend
 
end.



- - - Updated - - -

Here is another version of the code using interrupts but I wrote this in mikroC.


Code C - [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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Lcd pinout settings
sbit LCD_RS at LATB5_bit;
sbit LCD_EN at LATB4_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D4 at LATB0_bit;
 
// Pin direction
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
 
char gsmData[80];
unsigned int i = 0, j = 0;
 
void Interrupt(){
 
      if(RCIF_bit){
            gsmData[i++] = RCREG;
      }
      
      gsmData[i] = '\0';
}
 
void main() {
 
     TRISA = 0xFF;
     TRISB = 0x00;
     TRISC = 0x80;
     TRISD = 0x00;
     PORTA = 0x00;
     LATB = 0x00;
     PORTC = 0x00;
     PORTD = 0x00;
 
     LCD_Init();
     Lcd_Cmd(_LCD_CLEAR);
     Lcd_Cmd(_LCD_CURSOR_OFF);
     Lcd_Out(1,1,"GSM SMS Center V1.0");
 
     UART1_Init(9600);
     Delay_ms(500);
 
     INTCON = 0xC0;
     RCIE_bit = 1;
     
 
     while(1) {
 
            i = 0;
            j = 0;
            
            UART_Write_Text("AT\r\n");
            Delay_ms(2000);
            LCD_Out(2,1,gsmData);
            i = 0;
            UART_Write_Text("AT+CMGF=1\r\n");
            Delay_ms(2000);
            LCD_Out(2,1,gsmData);
            i = 0;
            UART_Write_Text("AT+CMGR=185\r\n");
            Delay_ms(4000);
            i = 0;
            while(gsmData[i] != '.')i++;
            i++;
            while(gsmData[i] != '.')i++;
            i++;
            while(gsmData[i]){
                    gsmData[j++] = gsmData[i++];
            }
            
            gsmData[j] = '\0';
            
            i = strlen(gsmData);
 
            for(j = 1; j < i; j++){
 
                    if((j >= 0) && (j < 20)){
                           LCD_Chr(1,j,gsmData[j-1]);
                    }
                    else if((j >= 20) && (j < 40)){
                           LCD_Chr(2,(j-20),gsmData[j-1]);
                    }
                    else if((j >= 40) && (j < 60)){
                           LCD_Chr(3,(j-40),gsmData[j-1]);
                    }
                    else if((j >= 60) && (j < 80)){
                           LCD_Chr(4,(j-60),gsmData[j-1]);
                    }
            }
            
            Delay_ms(5000);
 
     }
}




Working code for your micro


Code C - [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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
program gsmRead
 
' Declarations section
 
' Lcd module connections
dim LCD_RS as sbit at LATB5_bit
    LCD_EN as sbit at LATB4_bit
    LCD_D4 as sbit at LATB0_bit
    LCD_D5 as sbit at LATB1_bit
    LCD_D6 as sbit at LATB2_bit
    LCD_D7 as sbit at LATB3_bit
 
    LCD_RS_Direction as sbit at TRISB5_bit
    LCD_EN_Direction as sbit at TRISB4_bit
    LCD_D4_Direction as sbit at TRISB0_bit
    LCD_D5_Direction as sbit at TRISB1_bit
    LCD_D6_Direction as sbit at TRISB2_bit
    LCD_D7_Direction as sbit at TRISB3_bit
' End Lcd module connections
 
dim gsmData as char[80]
    i as word
    j as word
 
sub procedure interrupt
 
      If RCIF_bit Then
            gsmData[i] = RCREG
            i = i + 1
      End If
      
      gsmData[i] = 0
 
 
end sub
 
 
main:
'   Main program
 
    TRISA = $FF
    TRISB = $00
    TRISC = $80
    PORTA = $00
    LATB = $00
    PORTC = $00
 
    LCD_Init()
    Lcd_Cmd(_LCD_CLEAR)
    Lcd_Cmd(_LCD_CURSOR_OFF)
    Lcd_Out(1,1,"GSM SMS Center V1.0")
 
    UART1_Init(9600)
    Delay_ms(500)
 
    INTCON = $C0
    RCIE_bit = 1
    
    While(1)
    
            i = 0
            j = 0
 
            UART_Write_Text("AT")
            UART_Write(13)
            UART_Write(10)
            Delay_ms(1000)
            LCD_Out(2,1,gsmData)
            i = 0
            UART_Write_Text("AT+CMGF=1")
            UART_Write(13)
            UART_Write(10)
            Delay_ms(1000)
            LCD_Out(2,1,gsmData)
            i = 0
            UART_Write_Text("AT+CMGR=165")
            UART_Write(13)
            UART_Write(10)
            Delay_ms(2000)
            While(gsmData[i] <> ".")i = i + 1
            Wend
            i = i + 1
            While(gsmData[i] <> ".")i = i + 1
            Wend
            i = i + 1
            
            While(gsmData[i])
                    gsmData[j] = gsmData[i]
                    j = j + 1
                    i = i + 1
            Wend
 
            gsmData[j] = 0
 
            i = strlen(gsmData)
    
            j = 1
 
            While gsmData[j]
 
                    If((j >= 0) and (j < 20)) Then
                           LCD_Chr(1,j,gsmData[j-1])
                    Else If((j >= 20) and (j < 40)) Then
                           LCD_Chr(2,(j-19),gsmData[j-1])
                    Else If((j >= 40) and (j < 60)) Then
                           LCD_Chr(3,(j-39),gsmData[j-1])
                    Else If((j >= 60) and (j < 80)) Then
                           LCD_Chr(4,(j-59),gsmData[j-1])
                    End If
                    End If
                    End If
                    End If
                    
                    j = j + 1
                    
            Wend
 
 
            Delay_ms(5000)
    
    Wend
 
end.




99662d1386735040-readsms.png
 

Attachments

  • readSMS.png
    readSMS.png
    107.8 KB · Views: 122
Last edited:

I am not in town now for some work.I check your code when I come back.
Thank again for your help.

LOOSHA
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top