Discussion in "Project Addition or Changes" started by    bgk3678    Nov 4, 2018.
Sun Nov 04 2018, 08:18 pm
#1
#include<reg51.h>
unsigned int data_out,command=0x80,temp,r;
sfr lcd_data_pin=0x90; //P1 port
sbit rs=P2^0; //Register select
sbit rw=P2^1; //Read/Write
sbit en=P2^2; //Enable pin
//unsigned char match;
unsigned char m,key,count,index=3,k,i1,x1;
unsigned char x[100];


void delay1(unsigned int itime )
{
unsigned int i,j;

for (i=0;i<itime;i++)
for (j=0;j<1275;j++);
}

void lcd_command(unsigned char comm) //Lcd command funtion
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay1(1);
en=0;
}

void lcd_data(unsigned char disp) //Lcd data function
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay1(1);
en=0;
}

lcd_string(unsigned char *disp) //Function to send string
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}
void lcd_ini() //Function to initialize the LCD
{
lcd_command(0x38);
delay1(5);
lcd_command(0x0F);
delay1(5);
lcd_command(0x80);
delay1(5);
}



void serialcom()
{
TMOD=0x20;
TH1=0xFD;
SCON =0x50;
TR1=1;
}


void serial(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
}
unsigned rx_data(void)
{
while(RI == 0); // WAIT UNTIL DATA IS RECEIVED
RI = 0; // CLEAR FLAG
return SBUF; // RETURN SERIAL DATA

}

void send2gsm(char *aaa)
{
unsigned int i;
for(i=0;aaa[i]!='\0';i++)
{
serial(aaa[i]);
}
}

void main()
{
//int l;
TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1; // Triggering Timer 1
lcd_ini();
delay1(200);

lcd_command(0x81); //Place cursor to second position of first line
//lcd_string("gsm3 interface: ");
delay1(200);
lcd_command(0x80);
lcd_string(" bgk GSM ");
lcd_command(0xc1);
serialcom();
send2gsm("AT");
serial(0x0D);
serial(0x0A);

delay1(2);
send2gsm("AT+CMGF=1");
serial(0x0D);
serial(0x0A);

delay1(2);








while(1)
{
send2gsm("AT+CMGR=1");
serial(0x0D);
serial(0x0A);





while(rx_data() !='+' );


for(i1=0;i1<40;i1++)

{
x[i]=rx_data();
}
delay1(20);

for(i1=0;i1<40;i1++)
{
lcd_data(x[i]);


delay1(20);


}


}
}
Sun Nov 04 2018, 08:22 pm
#2
sir ,
as I have posted the code ,it is not displaying the message from second line actually message is in second line
Tue Nov 06 2018, 11:40 pm
#3
I got this output in Proteus.



What are you expecting to happen ?


[ Edited Thu Nov 08 2018, 10:20 am ]
Sun Nov 11 2018, 12:55 pm
#4
sir,Thank you for your response .The bgk GSM is the starting message will display on LCD, after that message sent by mobile will be displayed on LCD.
Sun Nov 11 2018, 09:33 pm
#5
I was just passing through looking for something else and noticed your post.

I'm not familiar with the GSM300 but a couple of things stand out from the code in the first post.

1) Some LCD displays have a small setup time from RS and RW to the leading edge of EN so it would be safer to put "en=1" after setting "rs" and "rw" in lcd_command() and lcd_data().
eg:
rs=0;
rw=0;
en=1;

2) In main() the code uses "i1" as the variable in the for loops but "i" as the variable for indexing the array x[].
This could just be a typing mistake in the first post or possibly the source of the problem.



[ Edited Sun Nov 11 2018, 09:33 pm ]
Mon Nov 12 2018, 06:51 am
#6


2) In main() the code uses "i1" as the variable in the for loops but "i" as the variable for indexing the array x[].
This could just be a typing mistake in the first post or possibly the source of the problem.

wimac


Thanks for the comments.
Actually the missing "1" is due to the way the website handles text.
For some reason it deletes that "1".


[ Edited Tue Nov 20 2018, 11:09 am ]
Mon Nov 19 2018, 06:41 am
#7
I used your code in a Proteus simulation that can simulate a very simple modem.
Here is the result.
The Terminal box on the left is output from the 8051.
At the bottom is the modem's reply.

As you can see, you should get some text on line 2.
Because of the way the LCD displays text, more text would appear on line 4 of a 4 line display.
You have to display the text in chunks ,16 chars for 16 char wide displays, 20 for 20.
Move the cursor to a new line for each chunk.




[ Edited Tue Nov 20 2018, 11:09 am ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

EdwardFew
Mon Mar 18 2024, 01:14 pm
EmeryPah
Mon Mar 18 2024, 11:51 am
RobertMax
Sun Mar 17 2024, 10:22 pm
DanielJar
Fri Mar 15 2024, 06:52 pm
Tuzaimecor
Fri Mar 15 2024, 02:32 am
PromotionFoode
Thu Mar 14 2024, 08:11 pm
EdwardGeawn
Sun Mar 10 2024, 12:24 pm
ZacharyShado
Sat Mar 09 2024, 10:04 am