I have a program that displays a "menu" and change once the switch is activated.
This works fine for now ... except that the LCD refresh area consent and gives an effect "flashing".
Can you help me?
Here is the code
Code: Select all
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char txt1[] = "OPEN - FIRE";
char txt2[] = "MSTK CORPORATION";
char txt3[] = "MODE ON";
char txt4[] = "MODE OFF";
char txt5[] = "MODE TIMING";
char txt6[] = "Allume";
char txt7[] = "Eteind";
char txt8[] = "Temporise";
char txt9[] = "Arret";
char txt10[]= "Tourne";
char txt11[]= "OK -> demarrer";
char txt12[]= "OK -> arreter";
char menu_principal = 1;
char nb_total_menu = 4;
char oldstate_menu = 0;
void main()
{
ANSELA = 0;
ANSELB = 0;
ANSELD = 0; // SET AN IND as difital
TRISD0_bit = 0; // set RD0 pin as input
Lcd_Init(); // Initialize LCD
Sound_Init(&PORTE, 2); // Initialize Sound
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,4,txt1); // Write text in first row
Lcd_Out(2,1,txt2); // Write text in second row
Delay_ms(3000);
do
{
if (Button(&PORTD, 0, 1, 1)) // Detect logical one
oldstate_menu = 1; // Update flag
if (oldstate_menu == 1 && Button(&PORTD, 0, 1, 0))
{ // Detect one-to-zero transition
menu_principal += 1;
if (menu_principal == nb_total_menu)
menu_principal = 1;
oldstate_menu = 0; // Update flag
}
switch(menu_principal)
{
case 1 : // mode OFF
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,4,txt4); // MODE OFF
Lcd_Out(2,5,txt12); // OK pour arreter
break;
case 2 :
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,4,txt3); // MODE ON
Lcd_Out(2,5,txt12); // OK pour arreter
break;
case 3 :
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,4,txt5); // MODE Timing
Lcd_Out(2,4,txt12); // OK pour arreter
break;
}
} while(1);
} // fin du programme