Expt. 5: GSM Module Interfacing with ARM7-LPC2148 for sendindSMS




CODE


#include <lpc214x.h>


// Define Clock settings

#define PCLK 15000000

#define BAUDRATE 9600 // Set Baud Rate here


void delay(unsigned char time) {

    unsigned int i, j;

    for (j = 0; j < (unsigned int)time; j++) {

        for (i = 0; i < 8000; i++) {

            // Delay

        }

    }

}


// Function to Initialize the UART0

void InitUART(void) {

    unsigned int Baud16;

    U0LCR = 0x83;

    Baud16 = (PCLK / (16 * BAUDRATE));

    U0DLM = (unsigned char)(Baud16 >> 8);

    U0DLL = (unsigned char)Baud16;

    U0LCR = 0x03;

}


// Function to Transmit a byte

void SendByte(unsigned char data) {

    U0THR = data;

    while ((U0LSR & 0x40) == 0);

}


// Function to Transmit a string

void SendString(const unsigned char *str) {

    while (*str != '\0') {

        SendByte(*str++);

    }

}


int main(void) {

    PINSEL0 = 0x00050005; // Enable UART0 Rx and Tx pins

    InitUART();

    SendString("AT+CMGF=1\n"); // Command to set the message format

    delay(500);

    SendString("AT+CMGS=\"+919970991231\"\n"); // Mobile number to send the message to

    delay(500);

    SendString("Hello Sanjivani College"); // Message to be sent

    delay(500);

    while (1);

}


Comments