flashing LCD screen

General discussion on mikroC.
Post Reply
Author
Message
jason5
Posts: 5
Joined: 07 Aug 2010 14:41

flashing LCD screen

#1 Post by jason5 » 01 Oct 2010 20:21

Hello,
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
Thank you

KaranSoin
Posts: 130
Joined: 07 May 2010 22:27
Location: Melbourne, Australia

Re: flashing LCD screen

#2 Post by KaranSoin » 11 Oct 2010 10:45

LCD is flickering because you are trying to write to the LCD in idle condition (when no button is pressed). Put the case statement inside the second "if" statement and that should fix it.



// 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
}//end of first if

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;
};//end of switch
}//end of second if


} while(1);


} // fin du programme

Post Reply

Return to “mikroC General”