How to Interface GSM with 8051

8051 Primer Board

The 8051 Primer board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXP’s 8051 (89V51RD2), 8051 Primer Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.

GSM (Global System for Mobile Communication)

GSM is a digital mobile telephony system. GSM digitizes and compresses data, then sends it down a channel with two other streams of user data, each in its own time slot. It operates at either the 900 MHz or 1800 MHz frequency band.

Interfacing GSM

Fig. 1 shows how to interface the GSM with microcontroller. The GSM module is communicate the microcontroller with mobile phones through UART. To communicate over UART or USART, we just need three basic signals which are namely, RXD (receive), TXD (transmit), GND (common ground).

GSM modem interfacing with microcontroller for SMS control of industrial equipments. The sending SMS through GSM modem when interfaced with microcontroller or PC is much simpler as compared with sending SMS through UART.

Text message may be sent through the modem by interfacing only three signals of the serial interface of modem with microcontroller i.e., TxD, RxD and GND. In this scheme RTS and CTS signals of serial port interface of GSM Modem are connected with each other.

The transmit signal of serial port of microcontroller is connected with transmit signal (TxD) of the serial interface of GSM Modem while receive signal of microcontroller serial port is connected with receive signal (RxD) of serial interface of GSM Modem.

The SMS message in text mode can contain only 140 characters at the most. It depends upon the amount of information collected from GPS Engine that you need at the base station for tracking vehicle or person.


Fig. 1 Interfacing UART to Microcontroller

Interfacing GSM with 8051

We now want to display a text in mobile from 8051 Primer Board by using GSM module through UART. In 8051 Primer Board contains two serial interfaces that are UART0 & UART1. Here we are using UART0. The GSM modem is being interfaced with the microcontroller 8051 Primer Board for SMS communication. The SMS can be sending and receiving for the data sharing and situation information and control.

Pin Assignment with 8051


Circuit Diagram to Interface GSM with 8051

Source Code

The Interfacing GSM module with 8051 program is very simple and straight forward, which send a message to mobiles from 8051 Primer Board through GSM module by using UART0. Some delay is occurring when a single data is sent to mobile through UART. C programs are written in Keil software. The baud rate of microcontroller is 9600.

C Program to send a message from 8051


Title : Program to send a message from 8051 to mobile through GSM



#include <REG51.H>               /* special function register declarations   */

#include <stdio.h>               /* prototype declarations for I/O functions */

#define LED P0                               //define prot P0 for LED


void serial_init(void);


unsigned int j;

//Setup the serial port for 9600 baud at 11.0592MHz.


void serial_init(void)


   SCON = 0x50;                        /* SCON: mode 1, 8-bit UART, enable rcvr        */

   TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload                   */

   TH1   = 0xFD;               /* TH1: reload value for 9600 baud @ 11.0592MHz*/

   TR1   = 1;                 /* TR1: timer 1 run                             */

   TI   = 1;                 /* TI:   set TI to send first char of UART          */




//Delay Routine start here

void delay1(int n)


   int i;




void delay2(int n)


   int i;




void led_left()


for (j=0x01; j<=0x80; j<<=1)


   LED = j;






//                     Main program starts here


void main(void)


            serial_init();                                                                                                 //serial initialization

            LED = 0x00; 

            printf("AT+CMGF=1%c",13);                                         delay2(20);  //Text Mode            | hex value of 13 is 0x0D (CR )

            printf("AT+CMGS=\"9600292363\"%c",13); delay2(20);           //Type your mobile number Eg : "9884467058"

            led_left();                 //scroll left


            printf("Hi :-) GSM Modem Test");                     delay2(20);  //Type text as u want

            printf("%c",0x1A);                                                             delay2(20);  //line feed command







To compile the above C code you need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Keil, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without 8051 Primer Board.

The Flash Magic software is used to download the hex file into your microcontroller IC 8051 through UART0.

Testing the GSM with 8051

Give +5V power supply to 8051 Primer Board; connect the +9V adapter with GSM module which is connected with 8051 Primer Board through UART0. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show some text messages.

The following Commands and sequence of events performed for sending text message to a mobile phone through GSM Modem interfaced with microcontroller:

  • First select the text mode for SMS by sending the following AT Command to GSM Modem : AT+CMGF = 1 . This command configures the GSM modem in text mode.
  • Send the following AT Command for sending SMS message in text mode along with mobile number to the GSM Modem : AT+CMGS =+923005281046 . This command sends the mobile number of the recipient mobile to the GSM modem.
  • Send the text message string ("GSM Modem Test") to the GSM Modem This is a test message from UART".
  • Send ASCII code for CTRL+Z i.e., 0x1A to GSM Modem to transmit the message to mobile phone. After message string has been sent to the modem, send CTRL+Z to the micro-controller, which is equivalent to 0x1A (ASCII value).

If you not reading any text from UART0, then you just check the jumper connections & just check the serial cable is working. Otherwise you just check the code with debugging mode in Keil. If you want to see more details about debugging just see the videos in below link.

   -How to Create & Debug a Project in Keil.

General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • More instructions are available in following articles,

   - User Manual of 8051 Primer Board.

   -Tutorial of how to create & Debug a project in KEIL.

   -How to Interface GSM with LPC 2148

Related Article