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.

[PIC] GSM interfacing with PIC18f458

Status
Not open for further replies.

ateebakmal

Newbie level 1
Joined
Mar 7, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
12
hi
I want to interface gsm with PIC micro controller.. using MPLAB C18 compiler. Have any one code of it?? I write that code... Is it work ??

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
void main()
  {
 
        unsigned char L_bit,H_bit,TEMP,vol1,vol2,vol3,vol4,temp1,temp2,temp3,cur1,cur2,cur3,cur4,x,z,AT[]="AT\r";
         unsigned char ATCMGF[]="AT+CMGF=1\r";
         unsigned char ATCMGS[]="AT+CMGS=\"+923338409761\"\r";
         unsigned char msg[]="hi\r";
         unsigned char msgend=26;
         unsigned int vol_TEMP,TEMP_amp;
         float y,DIG_volt;
         float DIG_8bit,DIG_10bit;
         //**** gsm***///
         TXSTA=0x20;
         RCSTA=0x90;
         SPBRG=19;
         TRISD=0;
        TRISB=0;
 
        TXSTAbits.TXEN=1;
         RCSTAbits.SPEN=1;
          for(z=0;z<4;z++)
          {
            while(PIR1bits.TXIF==0);
            TXREG=AT[z];
          }
          for(z=0;z<11;z++)
          {
            while(PIR1bits.TXIF==0);
            TXREG=ATCMGF[z];
          }
          for(z=0;z<23;z++)
          {
            while(PIR1bits.TXIF==0);
            TXREG=ATCMGS[z];
          }
           for(z=0;z<4;z++)
          {
            while(PIR1bits.TXIF==0);
            TXREG=msg[z];
          }
          while(PIR1bits.TXIF==0);
            TXREG=msgend;
  }

 
Last edited by a moderator:

I suggest that you start with something a little simpler (*such as flashing a LED to make sure that you can get everything sorted out before you start on this project.
PIC devices do have power on defaults for the oscillator settings, Analog vs digital pin operations etc.. Many of these power on settings are set using the CONFIG setting s and you really need to include those in the code that you post for us.
For example, the power on default for the oscillator is to use the RC configuration - have you get the RC components attached and what frequency are they set to? This is be essential of you want to calculate the correct baud rate generator setting to have the UART communicate.
The UART uses RC6 for the Tx signal and RC7 for the Rx signal. For your device no either of these pins have an analog function and so the fact that you are not setting the analog capability is OK.
I strongly recommend that you do NOT enable the UART (either the Tx or the Rx) side until after you have it configured. The data sheet has the correct sequence for both the Rx and Tx sides and you really should follow these steps (and not simply set the registers with magic numbers - at least add a comment as to which bits you intend to set with your values such as "0x20").
Your main function simply ends. Embedded programs do not run under an operating system and therefore there is nothing for the 'main' function to return to. In some cases (and I think the C18 compiler does this) the runtime provides some protection for you in that if the main function finishes, then the runtime will perform a reset and then call the main function again. This is almost never a good think.
Embedded program are written as an infinite loop that executes whatever the program is supposed to do after the initialisation has been completed.
This is why I suggest you start with something simpler. There are many tutorial examples on the Internet that will show you how to get something a LED flashing at the correct speed that will provide you with a very basic framework to get the program running. Once that is workign, then you cab slowly add your own bits to make it work the way you want.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top