|
|
Question : Problem: LCD Display
|
|
Hi Everyone,
Following is my code to display some msgs on LCD.I cant get the "range" displayed on the second line. Please help.
//pic16f877a running at 4 Mhz // 2x16 LCD, 4 bit mode #include
int RTC = 0; int Dlay;
static volatile bit RS @ (unsigned) & PORTD*8 + 0; static volatile bit EN @ (unsigned) & PORTD*8 + 2; static volatile bit RW @ (unsigned) & PORTD*8 + 1;
char Message[17] = "*PARKING SENSOR*"; char Msg[7]="Range=";
void interrupt tmr0_int(void) { if(T0IF) { T0IF = 0; RTC++; } }
void LCDNibble(char Nibble) { PORTD= Nibble; EN=1; EN=0; }
void LCDByte(char Byte) { PORTD= (PORTD & 0x0F )|( Byte & 0xF0); EN=1; EN=0; Dlay= RTC+6; while(Dlay!=RTC);
PORTD= (PORTD & 0x0F)| (( Byte<<4) & 0xF0); EN=1; EN=0; Dlay= RTC+6; while(Dlay!=RTC); }
void main() { int i,j; OPTION = 0x01; // /4 prescale TMR0=0; T0IE=1; GIE=1; RBPU=0; RW=0;
TRISD=0x00; PORTD=0x00;
Dlay= RTC+ 20; while(Dlay!=RTC);
LCDNibble(0x30);
Dlay= RTC+6; while(Dlay!=RTC);
LCDNibble(0x30);
Dlay= RTC+1; while(Dlay!=RTC);
LCDNibble(0x30);
Dlay= RTC+1; while(Dlay!=RTC);
LCDNibble(0x20);
Dlay= RTC+1; while(Dlay!=RTC);
LCDByte(0x28); LCDByte(0x08); LCDByte(0x01); LCDByte(0x06); LCDByte(0x0E);
RS=1;
for(i=0;i<16;i++) LCDByte(Message);
for(j=0;j<6;j++) LCDByte(Msg[j]);
while(1) {
} }
|
Answer : Problem: LCD Display
|
|
Try adding this function.
// Moves the cursor to the desired position. LCD_Locate(unsigned char Position) {
RS = 0; LCDByte(0x80 + Position); RS = 1; }
Then add this code before the second For
LCD_Locate(0x40);
You can create a function called LCD_Print for example that will receive arguments like (String1, String2) for the two lines... or (String, Position) so you don't need to worry about the location of the cursor.
This website is one of the best with all the comands you'll need.. but a very neet page is the LCD sim. http://www.geocities.com/dinceraydin/lcd/index.html http://www.geocities.com/dinceraydin/djlcdsim/djlcdsim.html
|
|
|
|