0

I have a LCD screen which waits for a button press and then starts a timer. One button runs a normal timer and then another button runs a sped up timer. The two problems I have is the button press isnt the best, I can't figure out how to use GPIO interrupts on the PIC16f18877.

My other problem is the LCD screen flickers every two seconds - I thought that maybe the while loop was causing the LCD Screen to reinitialise?

Any help would be appreciated

I put the detection of the button press inside a while loop and the initialisation outside the while loop. Thought this may stop the flicker but it hasn't.

void initialise() 
{
    OSCCON1 = 0x1EA;
    OSCFRQ = 0x02;
    
    Port_Dir_Ini();
    Port_Init_State();
    Delay(30000);
    Eusart_Setup();
    Disp_Size(); /* For 20 by 4 LCD digole display only*/
    Delay(1000);
    LCD_Cursor_Off();
    Delay(1000);
    LCD_Clear();
    Delay(1000);
    TMR2_Setup();
    LCD_Text_Position_xy (1,0);
    Eusart_Transmit("NP269 Sync Test");
    LCD_Text_Position_xy (1,3);
    Eusart_Transmit("Toggle Relay RL500");
    LCD_Text_Position_xy(12,1);
    Eusart_Transmit("HH:MM:SS");
    
}}


int main(void)     
{ 
    initialise();    
     __CONFIG(FOSV_INTRCCLK&WDTE_OFF&MCLRE_OFF&CP_OFF);

     while(1)
     {
        if(!SW102)
        {
            LCD_Text_Position_xy(1,1);
            Eusart_Transmit("HyperSpeed");
           
            for(;;)
            {
            CLRWDT();
            if (TMR2IF)
            {
                timerValue_ms ++;  
                TMR2IF = 0; 
                MILLISECONDS = 1;
                HyperClock();
                }
            }  
            Relay();
            MILLISECONDS = 0;
        }
     else if(!SW103)
     {
        LCD_Text_Position_xy(1,1);
        Eusart_Transmit("Current");
        
            for(;;)
            {
            CLRWDT();
            if (TMR2IF)
            {
                timerValue_ms ++;  
                TMR2IF = 0; 
                MILLISECONDS = 1;
                Clock();
                }
            }  
            Relay();
            MILLISECONDS = 0;
        }
    }
     
     //Delay(10000);
 }
 
Kozmotronik
  • 2,080
  • 3
  • 10
  • 25
Georgem
  • 3
  • 2
  • 1
    Try adding some delay between 50-100 ms everytime right after you detect a button press. This will filter noisy signal (debouncing) the mechanical button emits when it is pressed or unpressed. – Kozmotronik May 10 '23 at 13:36

0 Answers0