EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / problem while compiling program of pic 18f4550 interfacing with gsm

problem while compiling program of pic 18f4550 interfacing with gsm

|

Microcontroller › PIC › problem while compiling program of pic 18f4550 interfacing with gsm

  • This topic has 7 replies, 5 voices, and was last updated 12 years, 1 month ago by Ian.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • October 30, 2012 at 11:48 am #3908
    evening
    Participant

     

    #include<p18f4550.h>
    #define FREQ 12000000
    #define baud 9600
    #define spbrg_value (((FREQ/64)/baud)-1)
    #define rs LATA.F0
    #define rw LATA.F1
    #define en LATA.F2
    #define lcdport LATB
    void tx_data(unsigned char);
    unsigned char rx_data();
    void lcd_ini();
    void lcdcmd(unsigned char);
    void lcddata(unsigned char);
    void gsm_cmd(unsigned char *);
    void output(void);
    unsigned char value=0;
    int i=0,j,k,temp,flag,choice;
    unsigned char *starting_text="Enter choice=";
    unsigned char *dial_text="Dialing…";
    unsigned char *at_cmd="AT";
    unsigned char *imei_cmd="AT+GSN";
    unsigned char *call_cmd="ATD9xxxxxxxxx;";   // Provide a 10-Digit Mobile Number
    unsigned char *sms_format="AT+CMGF=1";
    unsigned char *sms_write="AT+CMGS="xxxxxxxxxx"";  // 10-Digit Mobile Number
    unsigned char *sms="Hello";
    unsigned char *sms_report="SMS Sent…";
    unsigned char sms_terminate=0x1A;
    unsigned char enter=0x0D;
    unsigned char *data;
    void main()
    {
    TRISB=0; // Set Port B as output port
    LATB=0;
    TRISA=0;
    LATA=0;
    TRISD=0xFF;
    LATD=0;
    SPBRG=spbrg_value; // Fill SPBRG register to set the baud rate
    RCSTA.SPEN=1; // To activate serial port (Tx and Rx pins)
    TXSTA.TXEN=1; // Activate Transmissiom
    RCSTA.CREN=1; // Activate Reception
    PIE1.RCIE=1; // Enable Reception interrupt
    INTCON.GIE=1; // Enable Global interrupt
    INTCON.PEIE=1; // Enable Peripheral interrupt
     
    lcd_ini();
    while(1)
    {
    k=0;
    lcdcmd(0x80);
    while(starting_text[k]!='')
    {
    lcddata(starting_text[k]);
    k++;
    }
     
    //Check inputs
    //Choice 1
    if(PORTD.F0)
    {
    gsm_cmd(at_cmd);
    output();
    Delay_ms(1000);
    }
     
    //Choice 2
    if(PORTD.F1)
    {
    gsm_cmd(imei_cmd);
    output();
    Delay_ms(1000);
    }
                                    
    //Choice 3
    if(PORTD.F2)
    {
    gsm_cmd(call_cmd);
    output();
    Delay_ms(1000);
    }
    //Choice 4
    if(PORTD.F3)
    {
    gsm_cmd(sms_format);
    output();
    Delay_ms(1000);
    gsm_cmd(sms_write);
    output();
    Delay_ms(1000);
    gsm_cmd(sms);
    output();
    tx_data(0x1A);
    Delay_ms(1000);
    }
    }
    }
    void gsm_cmd(unsigned char *string)
    {
    i=0;j=0;
    while(string!='')
    {
    temp=0;
    if(string==0x5C) // Not to send '' cahracter
    i++;
    tx_data(string); // Send by serial communication
    i++;
    while(temp!=1);
    }
    temp=0;
    tx_data(enter); // Send ASCII code for 'Enter' key
    while(temp!=1);
    }
    void output(void) // To print data on LCD
    {
    lcdcmd(0x01);
    i=-1;flag=0;
    while(i<j)
    {
    if(flag>1)
    {
    flag=0;
    Delay_ms(500);
    lcdcmd(0x01);
    lcdcmd(0x80);
    }
    if(data==0x0A) // This condition is to avoid double Enter
    // during execution of a command
    {
    flag++;
    lcdcmd(0xc0);
    }
    if(data=='>'||data=='"') // Not to print this character
    {
    i++;
    lcdcmd(0xc0);
    }
    if(data!=0x0D&&data!=0x0A&&data!=0x1A)  // Condition to print the data 
    // except 'Enter','New line' and 'Submit'
     
    {
    lcddata(data);
    i++;
    }
    else
    i++;
    Delay_ms(300);
    }
    lcdcmd(0x01);
    }
    void tx_data(unsigned char serial_data) // Transmit data function
    {
    TXREG=serial_data;
    while(PIR1.TXIF==0);
    }
     
    void interrupt()
    {
    data[j]=RCREG; // Store the data into array when Reception interrupt occurs
    value=RCREG;
    j++;
    temp=1;
    }
    void lcd_ini()
    {
    lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5×7 font
    lcdcmd(0x0C); // Display On and Cursor Off
    lcdcmd(0x01); // Clear display screen
    lcdcmd(0x06); // Increment cursor
    lcdcmd(0x80); // Set cursor position to 1st line, 1st column
    }
    void lcdcmd(unsigned char cmdout)
    {
    lcdport=cmdout; //Send command to lcdport=PORTB
    rs=0;
    rw=0;
    en=1;
    Delay_ms(10);
    en=0;
    }
    void lcddata(unsigned char dataout)
    {
    lcdport=dataout; //Send data to lcdport=PORTB
    rs=1;
    rw=0;
    en=1;
    Delay_ms(10);
    en=0;
    }
     
     
     
    we are getting following errors after compiling this program
     
     
     
    Executing: "C:Program FilesMicrochipmplabc18v3.43binmcc18.exe" -p=18F4550 "gsmc.c" -fo="gsmc.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
    F:for prgrm testgsmc.c:46:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:47:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:48:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:49:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:50:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:51:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:53:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:66:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:70:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:74:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:78:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:82:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:86:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:89:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:93:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:96:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:100:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:129:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:153:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:160:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:181:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:182:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:183:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:184:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:185:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:190:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:191:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:192:Error [1151] struct or union object designator expected
    F:for prgrm testgsmc.c:193:Warning [2058] call of function without prototype
    F:for prgrm testgsmc.c:194:Error [1151] struct or union object designator expected
    Halting build on first failure as requested.

    Debug build of project `F:for prgrm test5 gsm.mcp' failed.
    Language tool versions: mpasmwin.exe v5.46, mplink.exe v4.44, mcc18.exe v3.43, mplib.exe v4.44
    Preprocessor symbol `__DEBUG' is defined.
    Tue Oct 30 17:13:18 2012

    BUILD FAILED
     
    kindly help us
    October 31, 2012 at 4:43 pm #8705
    AJISH ALFRED
    Participant

    I think there is something wrong with the included header file <p18f4550.h>.

    Do one thing, keep the header file same and try to build any simple program, for example glowing an LED.

    November 7, 2012 at 8:35 am #8725
    sangeetha
    Participant

    please tell me in which compiler i have to run this program

    November 8, 2012 at 6:24 pm #8729
    AJISH ALFRED
    Participant

    You are using mplab right. make sure you’ve installed it properly and done the required settings before writing the code. Keil is another good option to compile your code.

    January 24, 2013 at 4:14 am #9038
    sangeetha
    Participant

    pls help me what might be the problem in the above program….

    January 24, 2013 at 12:25 pm #9046
    AJISH ALFRED
    Participant

    I think the error occurs due to the probem regarding the header files.

    July 24, 2013 at 10:32 am #10190
    mohamed
    Participant

    hello sir,

    this program work on mikroc pro compiler and the eror is data ,change it by datax so program will work God willing.

    but the code doesn’t work well so modify it by using uart luberary to transmit and receive data from serial port

    January 12, 2014 at 10:16 am #10837
    Ian
    Participant

    Hi.

     

    I have had similar problems with this project and identical errors when compiling.

     

    I have made a couple of changes to the code to get it to compile but I am still struggling to get the project to work.

     

    Some of the changes are:

     

    1) where there is “RCSTA.SPEN=1” for instance I have needed to change this to “RCSTAbits.SPEN=1” this needs to be done wherever there is a register.port command

    2) needed to include the correct “.h” file otherwise commands which use LATA and PORTA etc give errors

    3) Also there is no “Delay_ms” function even though it is referred to in the code – not sure if maybe other versions of the compiler has this as a standard function. I have just made my own delay function

    4) The checking of the Port D input pins makes no sense to me and it gives an error. So I have changed them – see the code below.

     

    Like I said I’m still battling to get this project working and I am by no means an expert in these matters – but maybe the author can respond to some of these suggested changes.

     

    Code below. Cheers.

     

    #include <p18f4550.h>
    #include <timers.h>
    //Program to interface GSM Modem with PIC18F4550 Microcontroller
    //This code takes four choices as four inputs
    //Choice 1 : Test the simple AT Command.
    //Choice 2 : Find out the IMEI number of the GSM Modem.
    //Choice 3 : Connect a call to a GSM mobile number.
    //Choice 4 : Send a text message to a mobile number.
    #define FREQ 12000000
    #define baud 9600
    #define spbrg_value (((FREQ/64)/baud)-1)
    // #define rs LATA.F0
    // #define rw LATA.F1
    // #define en LATA.F2
    //LCD Control pins

    #define rs PORTBbits.RB4
    #define rw PORTBbits.RB3
    #define en PORTBbits.RB2

    #define lcdport LATB
    void tx_data(unsigned char);
    unsigned char rx_data();
    void lcd_ini(void);
    void lcdcmd(unsigned char);
    void lcddata(unsigned char);
    void gsm_cmd(unsigned char *);
    void output(void);
    void Delay_ms ( int delay );
    unsigned char value=0;
    int i=0,j,k,temp,flag,choice;
    unsigned char *starting_text=”Enter choice=”;
    unsigned char *dial_text=”Dialing…”;
    unsigned char *at_cmd=”AT”;
    unsigned char *imei_cmd=”AT+GSN”;
    unsigned char *call_cmd=”ATD9xxxxxxxxx;”;   // Provide a 10-Digit Mobile Number
    unsigned char *sms_format=”AT+CMGF=1″;
    unsigned char *sms_write=”AT+CMGS=”xxxxxxxxxx””;  // 10-Digit Mobile Number
    unsigned char *sms=”Hello”;
    unsigned char *sms_report=”SMS Sent…”;
    unsigned char sms_terminate=0x1A;
    unsigned char enter=0x0D;
    unsigned char *data;

    void main()
    {
        TRISB=0;                // Set Port B as output port
        LATB=0;
        TRISA=0;
        LATA=0;
        TRISD=0xFF;
        LATD=0;
        SPBRG=spbrg_value;            // Fill SPBRG register to set the baud rate
        RCSTAbits.SPEN=1;                // To activate serial port (Tx and Rx pins)
        TXSTAbits.TXEN=1;                // Activate Transmissiom
        RCSTAbits.CREN=1;                // Activate Reception
        PIE1bits.RCIE=1;                // Enable Reception interrupt
        INTCONbits.GIE=1;                // Enable Global interrupt
        INTCONbits.PEIE=1;                // Enable Peripheral interrupt
       
        lcd_ini();
        while(1)
        {
            k=0;
            lcdcmd(0x80);
            while(starting_text[k]!=’’)
            {
                lcddata(starting_text[k]);
                k++;
            }
           
            //Check inputs
    //Choice 1
            if(PORTD=0xfe)
            {
                gsm_cmd(at_cmd);
                output();
                Delay_ms(1000);
            }

            //Choice 2
            if(PORTD=0xfd)
            {
                gsm_cmd(imei_cmd);
                output();
                Delay_ms(1000);
            }

            //Choice 3       
            if(PORTD=0xfb)
            {
                gsm_cmd(call_cmd);
                output();
                Delay_ms(1000);
            }
    //Choice 4
            if(PORTD=0xf7)
            {
                gsm_cmd(sms_format);
                output();
                Delay_ms(1000);
    gsm_cmd(sms_write);
                output();
                Delay_ms(1000);
    gsm_cmd(sms);
                output();
                tx_data(0x1A);
                Delay_ms(1000);
            }
    }
    }
    void gsm_cmd(unsigned char *string)
    {
        i=0;j=0;
        while(string!=’’)
        {
            temp=0;
            if(string
    ==0x5C)        // Not to send ” cahracter
            i++;
            tx_data(string
    );        // Send by serial communication
            i++;
            while(temp!=1);
        }
        temp=0;
        tx_data(enter);                // Send ASCII code for ‘Enter’ key
        while(temp!=1);
    }
    void output(void)                // To print data on LCD
    {
        lcdcmd(0x01);
        i=-1;flag=0;
        while(i<j)
        {
            if(flag>1)
            {
                flag=0;
                Delay_ms(500);
                lcdcmd(0x01);
                lcdcmd(0x80);
            }
            if(data
    ==0x0A)        // This condition is to avoid double Enter
    // during execution of a command
            {
                flag++;
                lcdcmd(0xc0);
            }
            if(data
    ==’>’||data=='”‘)    // Not to print this character
            {
                i++;
                lcdcmd(0xc0);
            }
            if(data
    !=0x0D&&data!=0x0A&&data!=0x1A)      // Condition to print the data
                                // except ‘Enter’,’New line’ and ‘Submit’
           
            {
                lcddata(data
    );
                i++;
            }
            else
                i++;
            Delay_ms(300);
        }
        lcdcmd(0x01);
    }
    void tx_data(unsigned char serial_data)        // Transmit data function
    {
        TXREG=serial_data;
        while(PIR1bits.TXIF==0);
    }

    void interrupt()
    {
        data[j]=RCREG;            // Store the data into array when Reception interrupt occurs
        value=RCREG;
        j++;
        temp=1;
    }
    void lcd_ini(void)
    {
        lcdcmd(0x38);        // Configure the LCD in 8-bit mode, 2 line and 5×7 font
        lcdcmd(0x0C);        // Display On and Cursor Off
        lcdcmd(0x01);        // Clear display screen
        lcdcmd(0x06);        // Increment cursor
        lcdcmd(0x80);        // Set cursor position to 1st line, 1st column
    }
    void lcdcmd(unsigned char cmdout)
    {
        lcdport=cmdout;        //Send command to lcdport=PORTB
        rs=0;                       
        rw=0;
        en=1;
        Delay_ms(10);
        en=0;
    }
    void lcddata(unsigned char dataout)
    {
        lcdport=dataout;    //Send data to lcdport=PORTB
        rs=1;
        rw=0;
        en=1;
        Delay_ms(10);
        en=0;
    }

    void Delay_ms ( int delay )
    {
    int ms, x;

    for ( ms = 0; ms< delay; ms ++ )
    for ( x = 0; x < 70; x ++ );
    }

     

     

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What branch of electronics has easy spare parts sourcing in north africa ? March 6, 2026
  • USING EASYEDA BUT SOMETHING ISN'T RIGHT? March 6, 2026
  • ESP32 Sub Forum March 6, 2026
  • Hello & a Request: Recommendations for obsolete Panasonic filter Capacitors. March 6, 2026
  • Pnp transistor query March 6, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise