sumonpic10
Newbie level 5
Dear All,
Recently I facing some problems with LCD display characters, here I used next & previous button for change the program line in the LCD display. But there some random characters came when I pressed the previous button. And my while loop working not good with display. But I was used some led high/low command in that while loop. That's led working according my code. At that time display is random characters. Pls help me, below my code & screenshot of display
Recently I facing some problems with LCD display characters, here I used next & previous button for change the program line in the LCD display. But there some random characters came when I pressed the previous button. And my while loop working not good with display. But I was used some led high/low command in that while loop. That's led working according my code. At that time display is random characters. Pls help me, below my code & screenshot of display
Code:
// LCD module connections /////////////////////////////////////////////
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections //////////////////////////////////////////////
// SWITCH CONNECTIONS ///////////////////////////////////////////////
#define prog porta.f3 // used for INPUT
#define rev porta.f7 // used for INPUT
#define forw portb.f0 // used for INPUT
//END SWITCH CONNECTIONS ///////////////////////////////////////////////
const char menu_1[] = "MAIN MENU";
const char part1[] = "1 PROGRAM";
const char part2[] = "2 PROGRAM";
const char part3[] = "3 PROGRAM";
const char part4[] = "4 PROGRAM";
const char part5[] = "5 PROGRAM";
const char part6[] = "6 PROGRAM";
const char arrow[] = "<==";
unsigned int number = 1;
char msg[20]; //declare array
// copy const to ram string
char * CopyConst2Ram(char * dest, const char * src){
char * d ;
d = dest;
for(;*dest++ = *src++;)
;
return d;
}
void main()
{
ANSEL = 0x01;
ANSELH = 0; // Configure other AN pins as digital I/O
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
adcon1=0x80; // Analog A0 is Active
trisa =0xff;
porta =0x00;
trise =0xff;
porte =0x00;
trisb =0xff;
portb =0x00;
trisd =0x00;
portd =0x00;
lcd_init(); // initialazied the LCD
lcd_cmd(_LCD_CLEAR); // Clean thje LCD
lcd_cmd(_LCD_CURSOR_OFF); // LCD cursor off
while(1)
{
while(number == 1) // while number = 1 ,then print Arrow on the 1no program
{
if(rev == 1) // check rev button is 1 or 0
{
number = 2; // if button is press number value will save 2
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
delay_ms(200); // Delay 200 mili second
}
Lcd_Out(1,6,CopyConst2Ram(msg,menu_1)); // print "MAIN MENU";
Lcd_Out(2,1,CopyConst2Ram(msg,part1)); // print "1 PROGRAM"; <==
Lcd_Out(3,1,CopyConst2Ram(msg,part2)); // print "2 PROGRAM";
Lcd_Out(4,1,CopyConst2Ram(msg,part3)); // print "3 PROGRAM";
Lcd_Out(2,11,CopyConst2Ram(msg,arrow)); // <==
}
while(number == 2) // when number = 2
{
if(rev == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 3;
delay_ms(200);
}
if(forw == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 1;
delay_ms(200);
}
Lcd_Out(1,6,CopyConst2Ram(msg,menu_1)); // print "MAIN MENU";
Lcd_Out(2,1,CopyConst2Ram(msg,part1)); // print "1 PROGRAM";
Lcd_Out(3,1,CopyConst2Ram(msg,part2)); // print "2 PROGRAM"; <==
Lcd_Out(4,1,CopyConst2Ram(msg,part3)); // print "3 PROGRAM";
Lcd_Out(3,11,CopyConst2Ram(msg,arrow)); // <==
}
while(number == 3) // when number = 2
{
if(rev == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 4;
delay_ms(200);
}
if(forw == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 2;
delay_ms(200);
}
Lcd_Out(1,6,CopyConst2Ram(msg,menu_1)); // print "MAIN MENU";
Lcd_Out(2,1,CopyConst2Ram(msg,part1)); // print "1 PROGRAM";
Lcd_Out(3,1,CopyConst2Ram(msg,part2)); // print "2 PROGRAM"; <==
Lcd_Out(4,1,CopyConst2Ram(msg,part3)); // print "3 PROGRAM";
Lcd_Out(4,11,CopyConst2Ram(msg,arrow)); // <==
}
while(number == 4) // when number = 2
{
if(rev == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 5;
delay_ms(200);
}
if(forw == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 3;
delay_ms(200);
}
Lcd_Out(1,6,CopyConst2Ram(msg,menu_1)); // print "MAIN MENU";
Lcd_Out(2,1,CopyConst2Ram(msg,part4)); // print "1 PROGRAM";
Lcd_Out(3,1,CopyConst2Ram(msg,part5)); // print "2 PROGRAM"; <==
Lcd_Out(4,1,CopyConst2Ram(msg,part6)); // print "3 PROGRAM";
Lcd_Out(2,11,CopyConst2Ram(msg,arrow)); // <==
}
while(number == 5) // when number = 2
{
if(rev == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 6;
delay_ms(200);
}
if(forw == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 4;
delay_ms(200);
}
Lcd_Out(1,6,CopyConst2Ram(msg,menu_1)); // print "MAIN MENU";
Lcd_Out(2,1,CopyConst2Ram(msg,part4)); // print "1 PROGRAM";
Lcd_Out(3,1,CopyConst2Ram(msg,part5)); // print "2 PROGRAM"; <==
Lcd_Out(4,1,CopyConst2Ram(msg,part6)); // print "3 PROGRAM";
Lcd_Out(3,11,CopyConst2Ram(msg,arrow)); // <==
}
while(number == 6) // when number = 2
{
if(forw == 1)
{
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
number = 5;
delay_ms(200);
}
Lcd_Out(1,6,CopyConst2Ram(msg,menu_1)); // print "MAIN MENU";
Lcd_Out(2,1,CopyConst2Ram(msg,part4)); // print "1 PROGRAM";
Lcd_Out(3,1,CopyConst2Ram(msg,part5)); // print "2 PROGRAM"; <==
Lcd_Out(4,1,CopyConst2Ram(msg,part6)); // print "3 PROGRAM";
Lcd_Out(4,11,CopyConst2Ram(msg,arrow)); // <==
}
}
}