[PIC] uart communication between PIC16F877A AND GSM MODEM SIM300

Status
Not open for further replies.

aparna_ece

Newbie level 3
Joined
Feb 23, 2014
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
33
I use hitech c compiler 9.70 and pic16f877a microcontroller , the following code compiled successfully but shows warning [359] illegal conversion between pointer types how can I clear this warning ,what is wrong with my code?



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
#include<pic.h>
#include<htc.h>
#include<string.h>
#define XTAL_FREQ 4e6
__CONFIG (0x3F3A);
void gsm_init();
void str_2_ch(char* str);
void main()
{
TRISC=0x80;
TRISD=0;
PORTC=PORTD=0x00;
    
while(1)
    {
    gsm_init();
    str_2_ch("AT");
    TXREG=0x0D;
    PORTD=0x01;
    
    str_2_ch("AT+CPIN?");
    TXREG=0x0D;
    PORTD=0x03;
 
    
    str_2_ch("ATD9xxxxxxxxx;");
    TXREG=0x0D;
    PORTD=0x07;
 
    
    str_2_ch("AT+CMGF=1");
    TXREG=0x0D;
    PORTD=0x0F;
 
    
    str_2_ch("AT+CMGS=");
    TXREG=0x22;
    PORTD=0x1F;
    str_2_ch("+919xxxxxxxxx");
    TXREG=0x22;
    PORTD=0x3F;
    TXREG=0x0D;
 
    str_2_ch("HI");
    TXREG=0x1A;
    TXREG=0x0D;
    PORTD=0x1F;
    }
}
 
void gsm_init()
{
    SPBRG=25;
    SYNC=0;
    SPEN=1;
}
 
 
void str_2_ch(char *str)
{
    int i;
    for(i=0;i<strlen(str);i++)
    {
        unsigned char data;
        data=str[i];
        if(TXIF==1)
        {
            TXREG=data;
            TXEN=1;
            while(str[i]!='\0');
        }
    }
}

 
Last edited by a moderator:

Your code will not work as UART is not properly configured. Also you need to test the response from modem before sending next AT command.

See this link for UART code. https://saeedsolutions.blogspot.in/2012/11/pic16f877-uart-code-proteus-simulation.html


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
#include<pic.h>
#include<htc.h>
#include<string.h>
 
#define XTAL_FREQ 4e6
 
    __CONFIG (0x3F3A);
 
void gsm_init();
void str_2_ch(char* str);
 
void gsm_init()
{
    SPBRG = 25;
    SYNC = 0;
    SPEN = 1;
}
 
void UARTSend(char dat)
{
    
    while(!TXIF);
    TXREG = dat;
}
 
void UARTSendString(char *str)
{
    while(*str)UARTSend(*str++);
 
}
 
void main()
{
    TRISC =0x80;
    TRISD = PORTC = PORTD = 0x00;
 
    gsm_init();
 
    while(1)
    {
    
        
        /*Code required for dialling
 
        {
            UARTSendString("AT+CPIN?\r");
            PORTD = 0x03;
 
 
            UARTSendString("ATD9xxxxxxxxx;\r");
            PORTD = 0x07;
        }
        */
 
        //Code t send SMS
 
        UARTSendString("AT\r");
        //delay of 1 sec
        UARTSendString("AT+CMGF=1\r");
        //delay of 1 sec
        UARTSendString("AT+CMGS=\"+919xxxxxxxxx\"\r");
        //delay of 3 sec    
        UARTSendString("HI");
        UARTSend(0x1A);
        UARTSend(0x0D);
 
        //delay of 5 sec
        
    }
}

 

How to code for receiving sms from a specific mobile number and storing it in a string variable for using it in the program
 

I don't know whether you can do that or not but you can do something like this.

Configure GSM modem to indicate new message received using CNMI at command. Then when ever CMTI response is received (which indicates new msg received) then read message by sending AT+CMGR=x command. Then parse the buffer and extract the Originating number and compare this with a number hard-coded. If numbers match then format and display SMS else send AT+CMGD=x command and delete the number.
 

found these links useful

HTML:
http://microcontrollerprojects00.blogspot.in/2012/03/pic-serial-communication-tutorial-uart.html

HTML:
http://microcontrollerprojects00.blogspot.in/2012/06/extra-uart-for-your-pic.html
 

The codes at the links you posted are mikroC codes. They have Compiled libraries for UART and Soft UART. They don't provide code for library functions. You can try mikroC demo compiler. It has a limit of 2 KB code size. Go to mikroe.com and download mikroC PRO PIC Compiler. In its help file search for UART1 and see the example code.
 

So do you mean to say that these cdes will not help me program in hitech c compiler??

how can i code in hitec c

- - - Updated - - -

I don't have proteus for simulation is there any other way to simulate my pic code ?? please suggest
 

Hello everybody, i also need help with this bit. I want 4 pics to communicate with each other. actually, it is 3 pic16f877s to send data to 1 pic16f877. i want the receiver to be able to receieve the individual messages from the 3 senders through the same RX pin since all the rf radios are 433MHz. please help me with this coding of the UART port. id there a way the receiver can read like an address system or something?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…