sinaku08
Newbie level 5
- Joined
- Nov 23, 2010
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,364
hi anyone please tell me where is the mistake in my code. the code is working fine with the 8 bit mode. but not in the 4 bit mode. the code and details are shown below.
every body writing their own codes. once I come to understand the basic operation then I can be able to write my own code.
after seeing the below code please suggest me the corrections and any modifications in the commands and the calculations of the delays in the loops.
/*
Iam following the following steps
1. wait for 20 m sec
2. send command 0x30
3. wait for 10 m sec
4. send command 0x30
5. wait for 1 m sec
6. send command 0x30
7. wait for 1 m sec
8. send command 0x20 // for selecting 4 bit mode
9. wait for 1 m sec
in BOTH command mode and data mode
1. masking lower 4 bits
2. send to the lcd
3. send enable signal H->L
4. masking higher 4 bits
5. send to the lcd
6. send enable signal H->L
******************************************************************************
******************************************************************************/
#include<at89c51.h>
sfr ldata = 0xA0;
sbit rs = P1^1;
sbit rw = P1^2;
sbit en = P1^3;
unsigned char name[21] = "hyderabadsecunderabad";
void delay(unsigned int time)
{
unsigned int i,j;
for(i = 0; i < time; i++)
for(j = 0; j < 1275; j++);
}
void lcdcmd(unsigned char value1)
{
unsigned char temp1;
rs = 0;
rw = 0;
temp1 = value1;
ldata = ( value1 & 0xf0 ) ;
en = 1;
delay(10);
en = 0;
ldata = ( temp1 & 0x0f );
ldata = ( ldata << 4 );
en = 1;
delay(10);
en = 0;
return;
}
void lcddata(unsigned char value2)
{
unsigned char temp2;
rs = 1;
rw = 0;
temp2 = value2;
ldata = ( value2 & 0xf0 );
en = 1;
delay(10);
en = 0;
ldata = ( temp2 & 0x0f );
ldata = ( ldata << 4 );
en = 1;
delay(10);
en = 0;
return;
}
void main (void)
{
unsigned char a;
delay(200);
lcdcmd(0x30);
delay(100);
lcdcmd(0x30);
delay(10);
lcdcmd(0x30);
delay(10);
lcdcmd(0x20);
delay(10);
while(1){
lcdcmd(0x01);
delay(5);
lcdcmd(0x0e);
delay(5);
lcdcmd(0x80);
delay(5);
for(a = 0; a <= 8; a++) {
lcddata(name[a]);
delay(5);
}
lcdcmd(0xc0);
delay(5);
for(a = 9; a <= 20; a++){
lcddata(name[a]);
delay(5);
}
delay(250);
}
}
/*then I am simulating in TOPVIEW simulator.
and Iam not sure about the delay calculations by using loops */
every body writing their own codes. once I come to understand the basic operation then I can be able to write my own code.
after seeing the below code please suggest me the corrections and any modifications in the commands and the calculations of the delays in the loops.
/*
Iam following the following steps
1. wait for 20 m sec
2. send command 0x30
3. wait for 10 m sec
4. send command 0x30
5. wait for 1 m sec
6. send command 0x30
7. wait for 1 m sec
8. send command 0x20 // for selecting 4 bit mode
9. wait for 1 m sec
in BOTH command mode and data mode
1. masking lower 4 bits
2. send to the lcd
3. send enable signal H->L
4. masking higher 4 bits
5. send to the lcd
6. send enable signal H->L
******************************************************************************
******************************************************************************/
#include<at89c51.h>
sfr ldata = 0xA0;
sbit rs = P1^1;
sbit rw = P1^2;
sbit en = P1^3;
unsigned char name[21] = "hyderabadsecunderabad";
void delay(unsigned int time)
{
unsigned int i,j;
for(i = 0; i < time; i++)
for(j = 0; j < 1275; j++);
}
void lcdcmd(unsigned char value1)
{
unsigned char temp1;
rs = 0;
rw = 0;
temp1 = value1;
ldata = ( value1 & 0xf0 ) ;
en = 1;
delay(10);
en = 0;
ldata = ( temp1 & 0x0f );
ldata = ( ldata << 4 );
en = 1;
delay(10);
en = 0;
return;
}
void lcddata(unsigned char value2)
{
unsigned char temp2;
rs = 1;
rw = 0;
temp2 = value2;
ldata = ( value2 & 0xf0 );
en = 1;
delay(10);
en = 0;
ldata = ( temp2 & 0x0f );
ldata = ( ldata << 4 );
en = 1;
delay(10);
en = 0;
return;
}
void main (void)
{
unsigned char a;
delay(200);
lcdcmd(0x30);
delay(100);
lcdcmd(0x30);
delay(10);
lcdcmd(0x30);
delay(10);
lcdcmd(0x20);
delay(10);
while(1){
lcdcmd(0x01);
delay(5);
lcdcmd(0x0e);
delay(5);
lcdcmd(0x80);
delay(5);
for(a = 0; a <= 8; a++) {
lcddata(name[a]);
delay(5);
}
lcdcmd(0xc0);
delay(5);
for(a = 9; a <= 20; a++){
lcddata(name[a]);
delay(5);
}
delay(250);
}
}
/*then I am simulating in TOPVIEW simulator.
and Iam not sure about the delay calculations by using loops */