This is the code i am sending it is having gsm.h, lcd.h, main.c, uart0.h, uart.h files.
extern unsigned char mx,my,mz,mm;
unsigned char uc_temp,uc_temp1,uc_temp2=0;
unsigned long int uli_temp3=0;
void gsm_delay( unsigned int value );
void gsm_cmd(char *cmd);
void gsm_check(void);
void gsm_init(void);
void gsm_send_num_mesg(unsigned char *num,unsigned char *mes);
unsigned char msg[50],mobilenum[11];
void gsm_delay( unsigned int value )
{
unsigned int ui_temp1,ui_temp2;
for(ui_temp1=0;ui_temp1<value;ui_temp1++)
for(ui_temp2=0;ui_temp2<2500;ui_temp2++);
}
void gsm_cmd(char *cmd)
{
while(*cmd)
{
while (!(U0LSR & 0x20));
U0THR = *cmd++;
}
}
void gsm_enter(void)
{
uart0_putch(10);
uart0_putch(13);
}
void gsm_check()
{
check:
uc_temp1=0;
uli_temp3=0;
gsm_cmd("AT");
gsm_enter();
while(uc_temp1<10)
{
while (!(U0LSR & 0x01))
{
uli_temp3++;
if(uli_temp3==6000000)
{
uli_temp3=0;
goto end;
}
}
uc_temp= U0RBR;
if(uc_temp=='O')
{
uc_temp=uart0_getch();
if(uc_temp=='K')
{
uc_temp2=1;
break;
}
}
uc_temp1++ ;
uli_temp3=0;
}
end:
if(uc_temp2==0)
{
lcd_cmd(0x01);
lcd_puts("MODEM IS NOT");
lcd_cmd(0xc0);
lcd_puts(" READY");
gsm_delay(1000);
goto check;
}
}
void gsm_init()
{
check1:
uc_temp1=0;
uli_temp3=0;
uc_temp2=0;
gsm_cmd("ATE0");
gsm_enter();
while(uc_temp1<10)
{
while (!(U0LSR & 0x01))
{
uli_temp3++;
if(uli_temp3==8000000)
{
uli_temp3=0;
goto end1;
}
} // Wait RXD Receive Data Ready
uc_temp= U0RBR;
if(uc_temp=='O')
{
uc_temp=uart0_getch();
if(uc_temp=='K')
{
uc_temp2=1;
break;
}
}
uc_temp1++ ;
uli_temp3=0;
}
end1:
if(uc_temp2==0)
{
lcd_cmd(0x01);
lcd_puts("MODEM IS NOT");
lcd_cmd(0xc0);
lcd_puts(" READY");
gsm_delay(1000);
goto check1;
}
check:
uc_temp1=0;
uli_temp3=0;
uc_temp2=0;
gsm_cmd("AT+CMGF=1");
gsm_enter();
while(uc_temp1<10)
{
while (!(U0LSR & 0x01))
{
uli_temp3++;
if(uli_temp3==8000000)
{
uli_temp3=0;
goto end;
}
} // Wait RXD Receive Data Ready
uc_temp= U0RBR;
if(uc_temp=='O')
{
uc_temp=uart0_getch();
if(uc_temp=='K')
{
uc_temp2=1;
break;
}
}
uc_temp1++ ;
uli_temp3=0;
}
end:
if(uc_temp2==0)
{
lcd_cmd(0x01);
lcd_puts("MODEM IS NOT");
lcd_cmd(0xc0);
lcd_puts(" READY");
gsm_delay(1000);
goto check;
}
lcd_cmd(0x01);
lcd_puts("MODEM IS READY");
gsm_delay(2000);
}
void gsm_clear_msg(char num)
{
check:
uc_temp1=0;
uli_temp3=0;
uc_temp2=0;
gsm_cmd("at+cmgd=");
uart0_putch(num+48);
gsm_enter();
while(uc_temp1<10)
{
while (!(U0LSR & 0x01))
{
uli_temp3++;
if(uli_temp3==8000000)
{
uli_temp3=0;
goto end;
}
} // Wait RXD Receive Data Ready
uc_temp= U0RBR;
if(uc_temp=='O')
{
uc_temp=uart0_getch();
if(uc_temp=='K')
uc_temp2=1;
break;
}
uc_temp1++ ;
uli_temp3=0;
}
end:
if(uc_temp2==0)
{
lcd_cmd(0x01);
lcd_puts("MSG DELETE ERROR");
gsm_delay(1500);
goto check;
}
lcd_cmd(0x01);
lcd_puts("MSG DELETED");
gsm_delay(2000);
}
void gsm_send_num_mesg(unsigned char *num,unsigned char *mes)
{
unsigned char uc_temp,uc_temp1,uc_temp3=0;
unsigned long long int uli_temp2;
U1IER=0;
U0IER=0;
gsm_cmd("at+cmgs=");
uart0_putch('"');
while(*num)
uart0_putch(*num++);
uart0_putch('"');
gsm_enter();
while(*mes)
uart0_putch(*mes++);
gsm_enter();
gsm_enter();
uart0_putch(0x1a);
uc_temp1=0;
uli_temp2=0;
while(uc_temp1<10)
{
while (!(U0LSR & 0x01))
{
if(uli_temp2==8000000)
{
lcd_cmd(0x01);
lcd_puts("MSG SENDING ");
lcd_cmd(0xc0);
lcd_puts(" ERROR");
gsm_delay(2000);
lcd_cmd(0x01);
lcd_puts("MODEM IS");
lcd_cmd(0xc0);
lcd_puts(" NOT CONNECTED");
gsm_delay(2000);
goto end;
}
uli_temp2++;
} // Wait RXD Receive Data Ready
uc_temp= U0RBR;
if(uc_temp=='+')
{
uc_temp=uart0_getch();
if(uc_temp=='C')
uc_temp=uart0_getch();
else
{
lcd_cmd(0x01);
lcd_puts("NO BALENCE");
lcd_cmd(0xc0);
lcd_puts(" IN UR SIM CARD");
gsm_delay(2000);
goto end;
}
if(uc_temp=='M')
uc_temp=uart0_getch();
else
{
lcd_cmd(0x01);
lcd_puts("NO BALENCE");
lcd_cmd(0xc0);
lcd_puts(" IN UR SIM CARD");
gsm_delay(2000);
goto end;
}
if(uc_temp=='G')
uc_temp=uart0_getch();
else
{
lcd_cmd(0x01);
lcd_puts("NO BALENCE");
lcd_cmd(0xc0);
lcd_puts(" IN UR SIM CARD");
gsm_delay(2000);
goto end;
}
if(uc_temp=='S')
{
uc_temp3=1;
break;
}
else
{
lcd_cmd(0x01);
lcd_puts("NO BALENCE");
lcd_cmd(0xc0);
lcd_puts(" IN UR SIM CARD");
gsm_delay(2000);
goto end;
}
}
uc_temp1++ ;
}
if(uc_temp3==1)
{
lcd_cmd(0x01);
lcd_puts("MESSAGE HAS BEEN");
lcd_cmd(0xc0);
lcd_puts(" SENT TO USER");
gsm_delay(2000);
}
else
{
lcd_cmd(0x01);
lcd_puts("MSG SENDING ");
lcd_cmd(0xc0);
lcd_puts(" ERROR");
gsm_delay(2000);
}
end:
U1IER=0x01;
U0IER=0x01;
}
void gsm_send_num_mesg_data(unsigned char *num,unsigned char *mes ,unsigned char *mes1)
{
unsigned char uc_temp,uc_temp1,uc_temp3=0;
unsigned long long int uli_temp2;
U1IER=0;
U0IER=0;
gsm_cmd("at+cmgs=");
uart0_putch('"');
while(*num)
uart0_putch(*num++);
uart0_putch('"');
gsm_enter();
while(*mes)
uart0_putch(*mes++);
gsm_enter();
while(*mes1)
uart0_putch(*mes1++);
gsm_enter();
uart0_putch(0x1a);
uc_temp1=0;
uli_temp2=0;
while(uc_temp1<10)
{
while (!(U0LSR & 0x01))
{
if(uli_temp2==8000000)
{
lcd_cmd(0x01);
lcd_puts("MSG SENDING ");
lcd_cmd(0xc0);
lcd_puts(" ERROR");
gsm_delay(2000);
lcd_cmd(0x01);
lcd_puts("MODEM IS");
lcd_cmd(0xc0);
lcd_puts(" NOT CONNECTED");
gsm_delay(2000);
goto end;
}
uli_temp2++;
} // Wait RXD Receive Data Ready
uc_temp= U0RBR;
if(uc_temp=='+')
{
uc_temp=uart0_getch();
if(uc_temp=='C')
uc_temp=uart0_getch();
else
{
lcd_cmd(0x01);
lcd_puts("NO BALENCE");
lcd_cmd(0xc0);
lcd_puts(" IN UR SIM CARD");
gsm_delay(2000);
goto end;
}
if(uc_temp=='M')
uc_temp=uart0_getch();
else
{
lcd_cmd(0x01);
lcd_puts("NO BALENCE");
lcd_cmd(0xc0);
lcd_puts(" IN UR SIM CARD");
gsm_delay(2000);
goto end;
}
if(uc_temp=='G')
uc_temp=uart0_getch();
else
{
lcd_cmd(0x01);
lcd_puts("NO BALENCE");
lcd_cmd(0xc0);
lcd_puts(" IN UR SIM CARD");
gsm_delay(2000);
goto end;
}
if(uc_temp=='S')
{
uc_temp3=1;
break;
}
else
{
lcd_cmd(0x01);
lcd_puts("NO BALENCE");
lcd_cmd(0xc0);
lcd_puts(" IN UR SIM CARD");
gsm_delay(2000);
goto end;
}
}
uc_temp1++ ;
}
if(uc_temp3==1)
{
lcd_cmd(0x01);
lcd_puts("MESSAGE HAS BEEN");
lcd_cmd(0xc0);
lcd_puts(" SENT TO USER");
gsm_delay(2000);
}
else
{
lcd_cmd(0x01);
lcd_puts("MSG SENDING ");
lcd_cmd(0xc0);
lcd_puts(" ERROR");
gsm_delay(2000);
}
end:
U1IER=0x01;
U0IER=0x01;
}
void gsm_mes_read(void)
{
unsigned char a,b,i,count,numcnt;
U1IER=0;
U0IER=0;
gsm_delay(100);
while ((U0LSR & 0x01)) // Wait RXD Receive Data Ready
{
b= U0RBR;
gsm_delay(5);
}
gsm_cmd("at+cmgr=1");
gsm_enter();
count=0;
i=0;
a=0;
numcnt=0;
while(count!=3)
{
b=uart0_getch();
if((b==',')||(a==1))
{
if(numcnt<15)
{
if(numcnt>4)
{
mobilenum[numcnt-5]=b;
}
a=1;
numcnt++;
}
else
a=0;
}
if(count==2)
{
msg[i++]=b;
}
if(b==10)
count+=1;
}
msg[--i]='\0';
msg[--i]='\0';
mobilenum[10]='\0';
lcd_cmd(0x01);
lcd_puts(msg);
gsm_delay(2000);
gsm_cmd("at+cmgd=1");
gsm_enter();
U1IER=0x01;
U0IER=0x01;
}
3. lcd.h
//*****************************************************************************
// file name :lcd.h
//*****************************************************************************
#ifndef _LPC214X_H_
#define _LPC214X_H_
// Define LCD PinIO Mask
#define LCD_RS 0x00010000 // P1.16(0000 0000 0000 000x 0000 0000 0000 0000)
#define LCD_EN 0x00020000 // P1.17(0000 0000 0000 00x0 0000 0000 0000 0000)
#define LCD_D4 0x00040000 // P1.18(0000 0000 0000 0x00 0000 0000 0000 0000)
#define LCD_D5 0x00080000 // P1.19(0000 0000 0000 x000 0000 0000 0000 0000)
#define LCD_D6 0x00100000 // P1.20(0000 0000 000x 0000 0000 0000 0000 0000)
#define LCD_D7 0x00200000 // P1.21(0000 0000 00x0 0000 0000 0000 0000 0000)
lcd_cmd(unsigned char val)
{
unsigned int lcd_ch;
unsigned int lcd_i; // LCD Initial Delay Count
IOCLR1 = LCD_RS ; // RS = 0
lcd_ch=((val>>4)&0x0F); // Strobe 4-Bit High-Nibble to LCD
IOCLR1 = (LCD_D7|LCD_D6|LCD_D5|LCD_D4); // Reset 4-Bit Pin Data
IOSET1 = (lcd_ch<<18); // EN,0,RW,RS:DDDD:0000:0000:0000:0000:0000:0000
IOSET1 = LCD_EN ; // EN = 1 (Enable)
for (lcd_i=0;lcd_i<10000;lcd_i++);
IOCLR1 = LCD_EN ; // EN = 0 (Disable)
lcd_ch=(val&0x0F); // Strobe 4-Bit Low-Nibble to LCD
IOCLR1 = (LCD_D7|LCD_D6|LCD_D5|LCD_D4); // Reset 4-Bit Pin Data
IOSET1 = (lcd_ch<<18); // EN,0,RW,RS:DDDD:0000:0000:0000:0000:0000:0000
IOSET1 = LCD_EN ; // EN = 1 (Enable)
for (lcd_i=0;lcd_i<10000;lcd_i++);
IOCLR1 = LCD_EN ; // EN = 0 (Disable)
for (lcd_i=0;lcd_i<10000;lcd_i++);
}
lcd_data(unsigned char val)
{
unsigned int lcd_ch;
unsigned int lcd_i; // LCD Initial Delay Count
IOSET1 = LCD_RS ; // RS = 1
lcd_ch=((val>>4)&0x0F); // Strobe 4-Bit High-Nibble to LCD
IOCLR1 = (LCD_D7|LCD_D6|LCD_D5|LCD_D4); // Reset 4-Bit Pin Data
IOSET1 = (lcd_ch<<18); // EN,0,RW,RS:DDDD:0000:0000:0000:0000:0000:0000
IOSET1 = LCD_EN ; // EN = 1 (Enable)
for (lcd_i=0;lcd_i<10000;lcd_i++);
IOCLR1 = LCD_EN ; // EN = 0 (Disable)
lcd_ch=(val&0x0F); // Strobe 4-Bit Low-Nibble to LCD
IOCLR1 = (LCD_D7|LCD_D6|LCD_D5|LCD_D4); // Reset 4-Bit Pin Data
IOSET1 = (lcd_ch<<18); // EN,0,RW,RS:DDDD:0000:0000:0000:0000:0000:0000
IOSET1 = LCD_EN ; // EN = 1 (Enable)
for (lcd_i=0;lcd_i<10000;lcd_i++);
IOCLR1 = LCD_EN ; // EN = 0 (Disable)
for (lcd_i=0;lcd_i<10000;lcd_i++);
}
void lcd_puts(unsigned char* str)
{
while(*str)
lcd_data(*str++);
}
void lcd_int(unsigned int lcd_value)
{
unsigned int lcd_arr[10],lcd_val;
for(lcd_val=1;lcd_val<5;lcd_val++)
{
lcd_arr[lcd_val] = lcd_value%10;
lcd_value = lcd_value/10;
}
for(lcd_val=4; lcd_val!=0 ; lcd_val--) //sending data to LCD
{
lcd_data(lcd_arr[lcd_val]+48);
}
}
lcd_init()
{
unsigned int lcd_main_i; // LCD Initial Delay Count
PINSEL2 |= 0x00000000; // GPIO1[31..26] = I/O Function
IODIR1 |= 0x003F0000 ; // LCD Data Bus = Write // LCD Data Bus = Write
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++); // Power-On Delay (15 mS)
IOCLR1 = ((LCD_D7|LCD_D6|LCD_D5|LCD_D4|LCD_RS|LCD_EN)); // Reset (RS,RW,EN,4-Bit Data) Pin
IOSET1 = (LCD_D5|LCD_D4); // DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000
IOSET1 = LCD_EN ; // EN = 1 (Enable)
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++);
IOCLR1 = LCD_EN ; // EN = 0 (Disable)
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++); // Delay 4.1mS
IOCLR1 = ((LCD_D7|LCD_D6|LCD_D5|LCD_D4|LCD_RS|LCD_EN)); // Reset (RS,RW,EN,4-Bit Data) Pin
IOSET1 = (LCD_D5|LCD_D4); // DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000
IOSET1 = LCD_EN ; // EN = 1 (Enable)
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++);
IOCLR1 = LCD_EN ; // EN = 0 (Disable)
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++); // delay 100uS
IOCLR1 = ((LCD_D7|LCD_D6|LCD_D5|LCD_D4|LCD_RS|LCD_EN)); // Reset (RS,RW,EN,4-Bit Data) Pin
IOSET1 = (LCD_D5|LCD_D4); // DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000
IOSET1 = LCD_EN ; // EN = 1 (Enable)
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++);
IOCLR1 = LCD_EN ; // EN = 0 (Disable)
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++);
IOCLR1 = ((LCD_D7|LCD_D6|LCD_D5|LCD_D4|LCD_RS|LCD_EN)); // Reset (RS,RW,EN,4-Bit Data) Pin
IOSET1 = (LCD_D5); // DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000
IOSET1 = LCD_EN ; // EN = 1 (Enable)
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++);
IOCLR1 = LCD_EN ; // EN = 0 (Disable)
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++);
lcd_cmd(0x28);
lcd_cmd(0x0c);
lcd_cmd(0x06);
lcd_cmd(0x01);
for (lcd_main_i=0;lcd_main_i<10000;lcd_main_i++); // Wait Command Ready
}
void lcd_float(float value)
{
unsigned char xxx[5],z=0;
int intval;
intval=(int)value;
value=value-intval;
while(intval!=0)
{
xxx[z]=intval%10;
intval=intval/10;
z++;
}
while(z!=0)
{
z--;
lcd_data(xxx[z]+48);
}
lcd_puts(".");
intval=value*10;
lcd_data(intval+48);
/* while(intval!=0)
{
xx[z]=intval%10;
intval=intval/10;
z++;
}
while(z!=0)
{
z--;
lcd_data(xx[z]+48);
} */
}
#endif
4. uart.h
void uart0_init()
{
PINSEL0 |=0x00000005;
U0LCR =0X80;
U0DLL =97;
U0LCR =0X03;
}
void com_baudrate0 (unsigned int baudrate)
{
unsigned long DLreload;
PINSEL0 |=0x00000005;
DLreload = (15000000UL / baudrate) / 16UL;
U0LCR = 0x80; /* Set DLAB */
U0DLL = DLreload;
U0DLM = (DLreload >> 8);
U0LCR = 0x03; /* Clear DLAB */
}
void uart0_putch(unsigned char val)
{
while(!(U0LSR & 0x20));
U0THR =val;
}
unsigned char uart0_getch()
{
while(!(U0LSR & 0x01));
return(U0RBR);
}
void uart0_puts( char *stringptr)
{
while (*stringptr)
uart0_putch(*stringptr++);
}
void uart0_int(unsigned long value)
{
unsigned char arr[10];
unsigned char val=0;
if(value==0)
uart0_putch(0+48);
while(value!=0)
{
arr[val] = value%10;
value = value/10;
val++;
}
while(val!=0)
{
val--;
uart0_putch(arr[val]+48);
}
}
5. uart1.h