i am interfacing gsm modem sim300 with micrcontroller p89v51rd2. i want to send 'at' and the reply'ok' i want to display on the lcd. but i don't know whr am i going wrong . following is the code
#include<p89v51rx2.h.txt>
#include<string.h>
sfr lcd_data_pin=0xA0; // data port P2
sbit rs=P3^0; // Register select pin
sbit rw=P3^1; // Read write pin
sbit en=P3^2; // Enable pin
sbit D7 = P2^7;
unsigned char msg[20];
unsigned char a,i,z,j;
void delay(unsigned int msec) //delay function
{
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void checkbusy()
{
D7=1;
rs=0;
rw=1;
while(D7!=0)
{
en=0;
delay(1);
en=1;
}
}
void lcd_command(unsigned char comm) // function to send command to LCD
{
checkbusy();
lcd_data_pin=comm;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
}
void lcd_data(unsigned char show) // function to send data on LCD
{
checkbusy();
lcd_data_pin=show;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
void lcd_dataa(unsigned char disp[]) // function to send string to LCD
{
unsigned char x;
for(x=0;disp[x]!=0;x++)
{
if(disp[x]=='O'||disp[x]=='K')
lcd_data(disp[x]);
}
}
void lcd_ini() //Function to inisialize the LCD
{
lcd_command(0x38);
delay(5);
lcd_command(0x0F);
delay(5);
lcd_command(0x80);
delay(5);
}
void init_serial(void)
{
a,i=0;
TH1=0xFD; // 9600 baud
TMOD=0x20; // Mode=2
SCON=0x50; // Serial mode=1 ,8-Bit data,1 Stop bit ,1 Start bit , Receiving on
TR1=1; //start timer
IEN0=0x90;
for(z=0;z<20;z++)
msg[z]=0;
}
void string(unsigned char text[])
{
while(text)
{
EA=0;
SBUF=text;
while(TI==0);
TI=0;
i++;
EA=1;
}
}
void receive() interrupt 4
{
msg[a]=SBUF;
RI=0;
a++;
}
/*void lcdstr(unsigned char *s)
{
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=1;i<=l;i++)
{
lcddata(*s); // write every char one by one
s++;
}
}*/
void main()
{
delay(5);
lcd_ini(); //to initialise lcd
lcd_dataa("READY"); //TO DISPLAY AN INITIAL MSG ON LCD
delay(10);
string("AT\r"); // AT commands to initialize gsm modem
delay(50);
lcd_dataa(msg);
}