• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

lcd menu

Status
Not open for further replies.

dawson

New Member
I had a look and noticed there was no delay for switch presses I have now added in a delay for each press and it is working :)

Thanks for all the help.
 

AtomSoft

Well-Known Member
heh no problem you are right tho:

Code:
unsigned char WaitForInput(void){
    unsigned char done = 0; //DONE Var will determine if done and hold key

    while(!done){                                  //while done == 0
        if (Button(&PORTA, MENU, 1, 0)){
              Delay_ms(10);
              done = MENU;
        }
        if (Button(&PORTA, UP, 1, 0)){
              Delay_ms(10);
              done = UP;
        }
        if (Button(&PORTA, DOWN, 1, 0)){
              Delay_ms(10);
              done = DOWN;
        }
    }
    return done;                                  //Return our done/key var
}
Thats way better
 

dawson

New Member
just one more problem, when i combine it to my temp sensor code it waits for the button then wats ti read temp then there is delays in temp before it comes back round to wait for MENU to be pressed so you have to get the timing right when pressing it.

here is the code:
Code:
 do {
        switch(WaitForInput()){
           case MENU:
              Delay_ms(100);
              MainMenu();
              break;
        }
        read_temp();
     } while (1);
is there a better way of waiting for a button press while it is doing the temprature reading?
 

AtomSoft

Well-Known Member
The best way is with interrupts. But thats not my strong point heh you can ask around for that.

I can barely do it in C18 i can imagin MikroC is simpler but i would have to learn it more
 

AtomSoft

Well-Known Member
also interrupts are on PORTRB line.. If you want to test another way is to check the MENU button with the temp code itself. Like through in:
Code:
               if (Button(&PORTA, MENU, 1, 0))
                   MainMenu();
every now and then to check for the press
 

AtomSoft

Well-Known Member
This is my new temperature code:

Code:
      for(tmp=0;tmp<5;tmp++){
        ADCON0bits.GO = 1;          //Start the conversion
        while(ADCON0bits.DONE);     //Wait until it’s done
        result = ADRESH;            //Load ADRESH into result
        result <<= 8;               //Shift over Result 8 bits to the left
        result |= ADRESL;           //OR in our LOW byte to finish off out INT
        avg[tmp] = result;  
[B]        if(KeyPORT == MENU) MainMenu();[/B]
        DelayMS(40);
      }       
        result = 0;
        for(tmp=0;tmp<5;tmp++){
            result += avg[tmp];
        }
        result /= 5;
        if(result==oldresult) goto tSame;
        
        DegC = (result*5)/10;
        DegC--;

        DegF = DegC * 9;
        DegF/=5;
        DegF+=32;
        //clear LCD temp buffer
[B]        if(KeyPORT == MENU) MainMenu();[/B]
        for(tmp=0;tmp<16;tmp++)
            lcdtmp[tmp] = ' ';

    if(MyView == 'F'){
        lcdtmp[0] = DECtoASCII(DegF,'h');
        lcdtmp[1] = DECtoASCII(DegF,'l');
        lcdtmp[2] = 0xDF;
        lcdtmp[3] = 'F';
        lcdtmp[4] = ' ';
    } else {
        lcdtmp[0] = DECtoASCII(DegC,'h');
        lcdtmp[1] = DECtoASCII(DegC,'l');
        lcdtmp[2] = 0xDF;
        lcdtmp[3] = 'C';
        lcdtmp[4] = ' ';
    }
[B]        if(KeyPORT == MENU) MainMenu();[/B]
        LCD_LINE(2);
        LCD_STR((unsigned rom char*)"Temp: ");

        LCD_STR2(lcdtmp);
        DelayMS(DelayTime);

        oldresult = result;
As you can see i test the button every now and then .. this way i have a better chance without interrupts
 
Last edited:

dawson

New Member
ok, not sure if i understand all that lol, will have a look through what I have and try and figure out the rest.

Thanks again for all the help :)
 
Status
Not open for further replies.

EE World Online Articles

Loading

 
Top