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.

Sms receiving from gsm

Status
Not open for further replies.

aasimzee

Junior Member level 1
Joined
Aug 5, 2016
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
184
Here is the code i am using to read string and display it on lcd but its not working, i recieve the data and lcd starts printing last character continiously. can u help ??

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
#define BAUDRATE 9600
void InitUART(void);
void SendByteSerially(unsigned char);
unsigned char ReceiveByteSerially(void);
void SendStringSerially(const unsigned char*);
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void lcdready(void);
#define ldata PORTB
#define rs PORTCbits.RC0
#define rw PORTCbits.RC1
#define en PORTCbits.RC2
#define busy PORTBbits.RB7
volatile char val;
int index;
 int i,j;
char data[5];
int z;
char key[] = "apple";
char uart_buff[21];
 
void main(void)
{
    TRISB=0;
    TRISC=0;
    TRISA=1;
    unsigned char cmd[]={0x38,0x0E,0x01,0x06,0x80};
    unsigned char z=0;
        for(z=0; z<25; z++)
    {
    __delay_ms(15);
    }
    for(z=0; z<6; z++)
    {
 
        lcdcmd(cmd[z]);
        lcdready();
 
 
    }
 
        InitUART();   // Intialize UART
  
    
  GIE  = 1;                                                          // Enable global interrupts
    PEIE = 1;                              // Enable Peripheral Interrupts
    while(1)
    {
        for(i=0;i<22;i++)
    {
        lcddata(uart_buff[i]);
        lcdready();
    
        }
       
        }
}
void SendByteSerially(unsigned char Byte)  // Writes a character to the serial port
{
        while(!TXIF);  // wait for previous transmission to finish
        TXREG = Byte;
        TXIF=0;
 
}
 
unsigned char ReceiveByteSerially(void)   // Reads a character from the serial port
{
        if(OERR) // If over run error, then reset the receiver
        {
                CREN = 0;
                CREN = 1;
        }
 
        while(!RCIF);  // Wait for transmission to receive
 
        return RCREG;
 
}
 
void SendStringSerially(const unsigned char* st)
{
        while(*st)
                SendByteSerially(*st++);
}
 
void InitUART(void)
{
        TRISC6 = 0;                                           // TX Pin
        TRISC7 = 1;                                           // RX Pin
 
        SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) - 1;
        BRGH  = 1;                           // Fast baudrate
        SYNC  = 0;                                                // Asynchronous
        SPEN  = 1;                                                // Enable serial port pins
        CREN  = 1;                                                // Enable reception
        SREN  = 0;                                                // No effect
        TXIE  = 0;                                                // Disable tx interrupts
        RCIE  = 1;                                                // Enable rx interrupts
        TX9   = 0;                                                // 8-bit transmission
        RX9   = 0;                                                // 8-bit reception
        TXEN  = 1;                                                // Reset transmitter
}
 
void lcdcmd(unsigned char value) 
{
    ldata=value;
    rs=0;
    rw=0;
    en=1;
    __delay_ms(3);
    en=0;
}
void lcddata(unsigned char value)
{
    ldata=value;
    rs=1;
    rw=0;
    en=1;
    __delay_ms(3);
    en=0;
}
 
void lcdready(void)
{
    TRISB=0xFF;
    rs=0;
    rw=1;
    do
    {
     en=1;
     __delay_ms(3);
     en=0;
    }while(busy==1);
    TRISB=0;
}
void interrupt isr()
{
    for(i=0;i<20;i++)
       {
        if (PIR1bits.RCIF)
        {
       uart_buff[i] = RCREG;
        }
 
      }
    uart_buff[i+1] ='\0';
    
}

 
Last edited by a moderator:

hello,

Code:
void interrupt isr()
{
    for(i=0;i<20;i++)
       {
        if (PIR1bits.RCIF)
        {
       uart_buff[i] = RCREG;
        }
 
      }
    uart_buff[i+1] ='\0';
    
}

It is a not usual code for UART interrupt !
the FOR loop is to much speedy to have any chance to get any char !

Code:
void interrupt isr()
{
   if (PIR1bits.RCIF)  // on char arrives into the RCreg buffer
   {
    uart_buff[i] =RCREG;  // RAZ RCIF bit
    index++;
    if (index>21)
    {
      FlagRx=1
      uart_buff[index] ='\0;
      index=0;
    }
  }
 // place here othe sources of interrupts
}

volatile int index;
volatile int FlagRX;


...into  main programm
    index=0;
    FlagRx=0;
    GIE  = 1;                              // Enable global interrupts
    PEIE = 1;                              // Enable Peripheral Interrupts
   
   while(1)
   {
     if (FlagRX==1)
     {
       // add seting LCD position to line 1, col 1
        for(i=0;i<22;i++)
       {
        lcddata(uart_buff[i]);
        lcdready();
        } // for
      } // if
    else
    {
    // .. code to  develop :display string on LCD  
    LCD_Write_Text(1,1,"waiting data..");
    }
   } //while
}
 
Dear i am making a project to continiously monitor the data of green house like humidity, temperature and intensity from sensor and print it on LCD. i have succesfully done that but other part of the project is that user will send a text using gsm and in return he will receive the temperature and other sensors value in sms. i need to compare user text with some preset text and if text matches microcontroller sends message to user but when i use if command to compare strings it get struck and i lose continious monitoring that i was doing on lcd... i wanna know is this project possible?
 

hello,


yes ,it is possible, i used this to send command from a gsm -> PIC ,
check internaly , if command is available;
do the commande,
and send feed back PIC status -> GSM if the commande is successfull

show you code ...

you need to use string comparaison like stncmp .. receiveid string to compare to preset text
 

Do u have code. If tes dates please send. Thanks
 

hello,
this litle portion of code to show how i treat commande send by distant phone
nota: UART1 used for displayng exchange and debugging...
UART2 connected to GSM click


Data On demand
Survey On (ou Off)
Sommeil
Cde Led1 0n (ou Off)
Cde Led2 0n (ou Off)
MAH=15/09/29,16:45:00+04
MCP1=00000000



Demande et effectue l'envoi des donnees de la carte BP1,BP2,EA&,EA2,MCP
Active ou non la surveillance des alarmes
Mets le GSM en mode sommeil, seul un evenement peut le reveiller
Commande led 1 locale sur la carte
Commande led 2 locale sur la carte
reMise A l'Heure en respectant ce format
Positionnement des 8 bits du MCP xxxxxxxx avec 0 ou 1

p=strstr(buffer2,"Survey On") ;
if (p>0) // demande de surveillance SMS
{
Drapeaux.Dialogue=1;
UART1_Write_CText(" Dialogue SMS retablit \r\n");
RAZ_UART2();
}
// *************************
p=strstr(buffer2,"Data On Demand");
if (p>0) // demande de renvoi datas
{
UART1_Write_CText("\r\nEnvoi Datas demandées \r\n");
k= Compose_Message(txt);
Envoi_SMS(txt);
RAZ_UART2();
}
// ********************
// syntaxe : Cde Led1 On ou Cde Led2 Off
p=strstr(buffer2,"Cde Led");
if (p>0)
{
if(*(p+7)=='1')
{
p=strstr(p+8," On");
if (p>0) LD1=1;
p=strstr(p+8," Off");
if (p>0) LD1=0;
}
if(*(p+7)=='2')
{
p=strstr(p+8," On");
if (p>0) LD2=1;
p=strstr(p+8," Off");
if (p>0) LD2=0;
}
UART1_Write_CText(" Retour d'ordre cde Leds \r\n");
strConstRamCpy(txt,"\r\nRetour Led1= Led2= \r");
*(txt+14)=48+LD1;
*(txt+21)=48+LD2;
Envoi_SMS(txt);
RAZ_UART2();
}
// *** cde mise en sommeil ***
p=strstr(buffer2,"Sommeil");
if ((p>0) && (Drapeaux.Sommeil==0))
{
UART1_Write_CText(" Mise en sommeil \r\n");
strConstRamCpy(txt,"\r\nOK mode miminum x\r");
Envoi_SMS(txt);
UART1_Write_CText("Go in SLEEP mode(AT+QSCLK=2) \r\n");
Send_Cde_display_response("AT+QSCLK=2\r", Drapeaux.Visible);
UART1_Write_CText("DTR=1\r\n");
Cde_DTR=1;
Drapeaux.Sommeil=1;
}
// *** cde Help ***
p=strstr(buffer2,"Help");
if (p>0)
{
UART1_Write_CText(" Help demandée \r\n");
txt=&TEXTE[0];
strConstRamCpy(txt,"\r\nCdes dispo:\r\n"
" Data On demand \r\n"
" Survey On (ou Off)\r\n"
" Sommeil\r\n"
" Cde Led1 0n (ou Off)\r\n"
" MAH=15/09/29,16:45:00+04\r\n"
" MCP1=00000000\r\n" );
// UART1_Write_Text(txt);
Envoi_SMS(txt);
RAZ_UART2();
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top