0% found this document useful (0 votes)
18 views6 pages

GSM Interfacing with LPC2148 Code

The document describes a program statement for interfacing a GSM module with an LPC2148 microcontroller to send and receive SMS messages and make voice calls. The code includes a main.c file that initializes UART communication and sends commands to the GSM module, and UART.h and UART.c files that define UART functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

GSM Interfacing with LPC2148 Code

The document describes a program statement for interfacing a GSM module with an LPC2148 microcontroller to send and receive SMS messages and make voice calls. The code includes a main.c file that initializes UART communication and sends commands to the GSM module, and UART.h and UART.c files that define UART functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name:-Anway Alamwar

Roll No:-TYETA207

Program Statement:-Interfacing GSM with LPC2148 for sending and receiving message and
voice call.

Code:
 Main.c File
#include "lpc214x.h"
#include "UART.h"
#include "stdio.h"
#include "string.h"
void delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<5000;j++);
}
void GSM_cmd(unsigned char *cmd)
{
printf("\r\ncommand: %s",cmd);
printf("response: ");
UART1_PutS(cmd);
delay(100);
}
int main()
{
unsigned char *msg = "MicroEmbedded Technologies\r";

Uart0Init(9600);
Uart1Init(9600);
printf("GSM program\r\n");

GSM_cmd("ATE0\r\n"); //Turn OFF echo


delay(3000);

GSM_cmd("ATD9673693053;\r\n"); //Call (CHANGE THIS NUMBER)


delay(20000);
GSM_cmd("ATH0\r");
//disconnect call
delay(3000);

GSM_cmd("AT+CMGF=1\r\n"); //Send SMS: Select Text mode


delay(1000);
GSM_cmd("AT+CSCS=\"GSM\"\r\n"); //GSM Character Set
delay(1000);
GSM_cmd("AT+CMGS=\"9673693053\"\r\n"); //Number (CHANGE THIS
NUMBER)
delay(1000);
UART1_PutS(msg); //Send string
delay(1000);
UART1_PutChar(0x1A);
//SUBSTITUTE character <CTRL+Z>

while(1);
return 0;
}

 UART.h File

#ifndef UART_H
#define UART_H

void Uart0Init(unsigned int);


void Uart1Init(unsigned int);
unsigned char UART0_GetChar(void);
unsigned char UART0_PutChar(unsigned char);
unsigned char UART1_GetChar(void);
unsigned char UART1_PutChar(unsigned char);
void UART1_PutS(unsigned char*);

#endif
 UART.C File

#include "stdio.h"
#include "LPC214x.h"
#include "UART.h"

void UART1_isr(void) __irq


{
UART0_PutChar(UART1_GetChar());
VICVectAddr = 0;
}

void Uart0Init(unsigned int baudrate)


{
unsigned int FDiv;
PINSEL0 |= 0x00000005; //Enable RxD0 and TxD0
U0LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
FDiv = (15000000 / 16 ) / baudrate ; //
U0DLM = FDiv /256; //0x00;
U0DLL = FDiv %256; //0x97;
U0LCR = 0x03; // DLAB = 0
}

void Uart1Init(unsigned int baudrate)


{
unsigned int FDiv;
PINSEL0 |= 0x00050000; //Enable RxD1 and TxD1
U1LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
FDiv = (15000000 / 16 ) / baudrate ; //
U1DLM = FDiv /256; //0x00;
U1DLL = FDiv %256; //0x97;
U1LCR = 0x03; // DLAB = 0

U1IER = 0x01;
VICVectCntl1 = 0x20 | 7;
VICVectAddr1 = (unsigned int)UART1_isr;
VICIntEnable |= 1<<7;
}

unsigned char UART0_GetChar(void)


{
while(!(U0LSR & 0x01));
return(U0RBR);
}

unsigned char UART1_GetChar(void)


{
while(!(U1LSR & 0x01));
return(U1RBR);
}

unsigned char UART0_PutChar(unsigned char Ch)


{
while(!(U0LSR & 0x20));
// if(Ch == '\n')
// Ch = 0x0D;
U0THR = Ch;
return Ch;
}

unsigned char UART1_PutChar(unsigned char Ch)


{
while(!(U1LSR & 0x20));
U1THR = Ch;
return Ch;
}

void UART1_PutS(unsigned char *Ch)


{
while(*Ch)
UART1_PutChar(*Ch++);
}

int fputc(int ch, FILE *f) {


return (UART0_PutChar(ch));
}

struct __FILE { int handle; /* Add whatever you need here */ };


FILE __stdout;
Output:

Fig : Interfacing with GSM kit

Fig: Output on Receiver Mobile


Fig: Output On terminal window

You might also like