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 / Interfacing GSM SIM900 with PIC18f26k22

Interfacing GSM SIM900 with PIC18f26k22

|

Microcontroller › PIC › Interfacing GSM SIM900 with PIC18f26k22

  • This topic has 1 reply, 2 voices, and was last updated 12 years, 1 month ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • March 5, 2014 at 5:54 pm #2922
    shubham
    Participant

    Trying to recieve a message into the microcontroller via the GSM module and then display it using Hterm. Hterm is not displaying anyting. This is the code used. Can’t figure out where is it wrong.

     

     

    #include<stdio.h>

    #include<stdlib.h>
    #include<delays.h>
    #include<p18f26k22.h>
     
    #pragma config FOSC=INTIO7
    #pragma config WDTEN=OFF
    #pragma config LVP=OFF
    #pragma config DEBUG=OFF
     
    void UART2(void)
    {
        TXSTA2bits.BRGH=1;
        SPBRG2=51;
        TRISBbits.RB6=1;
        TRISBbits.RB7=1;
        RCSTA2bits.SPEN=1;
        TXSTA2bits.SYNC=0;
        TXSTA2bits.TXEN=1;
        RC2STAbits.CREN=1;
    }
     
    void UART1(void)
    {
        TXSTA1bits.BRGH=1;
        SPBRG1=51;
        TRISCbits.RC6=1;
        TRISCbits.RC7=1;
        RCSTA1bits.SPEN=1;
        TXSTA1bits.SYNC=0;
        TXSTA1bits.TXEN=1;
        RC1STAbits.CREN=1;
    }
     
    void UART_sendbyte(unsigned char c)
    {
        while(!TXSTA1bits.TRMT); /* Wait until TX buf read for new data */
        TX1REG = c;
    }
    void UART_sendstring(char *str)
    {
    while(*str != ‘’)
    {
    Delay1KTCYx(100);
    while(!TXSTA1bits.TRMT);
    TX1REG = *str;
    str++;
    }
    }
     
    void UART2_sendstring(char *str)
    {
    while(*str != ‘n’)
    {
    Delay1KTCYx(100);
    while(!TXSTA2bits.TRMT);
    TX2REG = *str;
    str++;
    }
    }
     
    unsigned char *UART_getstring()
    {
        unsigned char *strng;
        int i=0;
    while(strng!=13)
    {
                if(PIR1bits.RC1IF)
                {
                    strng=RC1REG;
                    i++;
                }
            }
        strng=’’;
        return strng;
    }
     
    void main()
    {
        unsigned char *cmd, *msg, c;
        UART1();       //This is to be used for communicating with the GSM module via Tx1 Rx1
        UART2();      //This is to be used for communicating with the Hterm via Tx2 Rx2
        Delay10KTCYx(200);
        UART_sendbyte(‘r’);
        Delay10KTCYx(100);
        sprintf(cmd,”AT+CMGR=1″);
        UART_sendbyte(‘r’);
        Delay10KTCYx(200);
        UART_sendstring(cmd);
        UART_sendbyte(‘r’);
        Delay10KTCYx(200);
        msg=UART_getstring();
        Delay10KTCYx(200);
        UART2_sendstring(msg);
    }
     
     
    March 7, 2014 at 4:27 am #11219
    AJISH ALFRED
    Participant

    Hi Shubham,

    The codem for sending string may or maynot work depends on the compiler. Some compiler requires ” const char * “, like

    “void UART_sendstring(const char *str)”.

     

    Try to send a readable ascii character using UART_sendbyte(), like

    UART_sendbyte(‘A’);

     

    Also make sure that the serial port settings like the baud rate, start bit, stop bit etc. are same on both the sides.

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

RSS Recent Posts

  • Some opamp advice please April 12, 2026
  • isolating S-params in of PCB board without connectors April 11, 2026
  • want help with microprocessor April 11, 2026
  • Voltage comparator circuit verification April 11, 2026
  • Integrating 0–5V ECU Signals into a Double-DIN Setup – Module vs Custom Head Unit? April 11, 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