Toll-Free Customer Support 24/7

Gsm Arm code




/*
 * Project name:
     GSM sim900 MODEM
 * Copyright
     (c) Researchdesignlab.com
 * Description:
    
 * Test configuration:
     MCU:             LPC2129
     Dev.Board:       LPC2129 mini
     Oscillator:      12 MHz
     Software:        Keil uVision3

*/


#include"lpc21xx.h"    // header file
//*******************************************************************
void SEND_CMD_2_LCD(unsigned char);    // function protoype
void SEND_2_LCD(unsigned char *, unsigned char);
void DISPLAY_ON_LCD(unsigned char);
char hex2ascii(unsigned int);
void DELAY(void);
void LCD_DELAY(void);

unsigned int LCD_RS=0X01000000;      // pin declerations
unsigned int LCD_EN=0X02000000;
unsigned int LCD_DATA_LINES=0X00003C00;

#define CR 0X0A
#define LF 0X0D
#define EOM 0X1A

unsigned char CMD_1[]="AT";
unsigned char CMD_4[]="AT+CMGF=1";
unsigned char CMD_6[]="AT+CMGS=\"1234567890\"";    //TO SEND MESSAGE
unsigned char RX;                            
void SEND_COMMAND_2_MODEM(unsigned char *);
void CR_LF(unsigned char);
void RX_REPLY_FROM_MODEM(void);
void RX_REPLY_2_SEND_MSG(void);
void SEND_MSG_2_MODEM(unsigned char *);


//*******************************************************************
int main()
{
    unsigned char LCD_CMD[]={0X20,0X28,0X0f,0X06,0X01,0X80},COUNT; // LCD commands
    unsigned char MSG[]="hello";



    IODIR0|=LCD_DATA_LINES;
    IODIR1=0X03200000;
    for(COUNT=0;COUNT<6;COUNT++)
    SEND_CMD_2_LCD(LCD_CMD[COUNT]); // LCD INIT function call

    PINSEL0    = 0X00050000;
    PINSEL1=0X15400000;       // UART INIT
    U1LCR = 0X83;           // 8bit data setting        
    U1DLL = 0X61;                                  
    U1LCR = 0X03;    // 9600 baud rate setting        
    U1FCR = 0X01;    // FIFO enable

    PINSEL0|=0X00000005;
    U0LCR=0X83;
    U0DLL=0X61;
    U0DLM=0X00;
    U0LCR=0X03;




    SEND_COMMAND_2_MODEM(CMD_1);
    RX_REPLY_FROM_MODEM();
    SEND_COMMAND_2_MODEM(CMD_4);
    RX_REPLY_FROM_MODEM();




    //***************************************
        while(1)
        {
        
        
        SEND_MSG_2_MODEM(MSG);
        
        while(1);
        
        }      
}

//********************************************************************
 void SEND_CMD_2_LCD(unsigned char DATA)
{
    unsigned int TEMP;                      // LCD command write function
    IOCLR0=LCD_DATA_LINES;
    TEMP=DATA;
    TEMP=((TEMP&0xf0)<<6);
    IOCLR1=LCD_RS;
    IOSET0=TEMP;
    IOSET1=LCD_EN;
    LCD_DELAY();
    LCD_DELAY();
    IOCLR1=LCD_EN;
    IOCLR0=LCD_DATA_LINES;
    
    LCD_DELAY();

    TEMP=DATA;
    TEMP=((TEMP&0x0f)<<10);
    IOCLR1=LCD_RS;
    IOSET0=TEMP;
    IOSET1=LCD_EN;
    LCD_DELAY();
    LCD_DELAY();
    IOCLR1=LCD_EN;
    IOCLR0=LCD_DATA_LINES;
}
//********************************************************************
void DISPLAY_ON_LCD(unsigned char DATA)
{
    unsigned int TEMP;
    IOCLR0=LCD_DATA_LINES;
    TEMP=DATA;                          //LCD data write function
    TEMP=((TEMP&0xf0)<<6);
    IOSET1=LCD_RS;
    IOSET0=TEMP;
    IOSET1=LCD_EN;
    LCD_DELAY();
    LCD_DELAY();
    IOCLR1=LCD_EN;
    IOCLR0=LCD_DATA_LINES;
    
    LCD_DELAY();

    TEMP=DATA;
    TEMP=((TEMP&0x0f)<<10);
    IOSET1=LCD_RS;
    IOSET0=TEMP;
    IOSET1=LCD_EN;
    LCD_DELAY();
    LCD_DELAY();
    IOCLR1=LCD_EN;
    IOCLR0=LCD_DATA_LINES;
}

//*************************************************************
void SEND_2_LCD(unsigned char *PTR, unsigned char POS)
{
    SEND_CMD_2_LCD(POS);
    while(*PTR)
    {                               // sending the data to LCD data line function
        DISPLAY_ON_LCD(*PTR);
        PTR++;
    }
    LCD_DELAY();
    LCD_DELAY();
}

//*****************************************************************************
void LCD_DELAY(void)
{
    unsigned int X=20000;  // delay calculation subroutine
    while(X--);
}

void SEND_COMMAND_2_MODEM(unsigned char *P)
   {
    while(*P){
        U0THR=*P;
        while(!(U0LSR&0X20));
        P++;}
    CR_LF(CR);
    CR_LF(LF);
    }

void CR_LF(unsigned char CRLF)
   {
    U0THR=CRLF;
    while(!(U0LSR&0X20));
    }

void RX_REPLY_FROM_MODEM(void)
   {
    RX=0;
    while(RX!='K'){
        while(!(U0LSR&0X01));
        RX=U0RBR;}
   }

/*void RX_REPLY_2_SEND_MSG()
   {
    while(RX!='>'){
        while(!(U0LSR&0X01));
        RX=U0RBR;}
    }
     */
void SEND_MSG_2_MODEM(unsigned char *P)
   {
    SEND_COMMAND_2_MODEM(CMD_6);
    //RX_REPLY_2_SEND_MSG();
    while(*P){
        U0THR=*P;
        while(!(U0LSR&0X20));
        P++;}
    CR_LF(EOM);
    }


//*****************************************************************************
void DELAY(void)
{
    unsigned int X=6000000;// delay subroutine
    while(X--);
}

//*****************************************************************************



Back to top