1. 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.
    Dismiss Notice

lcd menu

Discussion in 'Microcontrollers' started by dawson, Oct 23, 2009.

  1. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    hey i just edited the above code. Use the one with

    Code (text):

    //REV2
     
    at the top
     
  2. dawson

    dawson New Member

    Joined:
    Sep 21, 2009
    Messages:
    97
    Likes:
    0
    Location:
    UK, north east
    That last one now produces:

    ">Option A"
    "Option B"

    "Option B"
    ">Option C"

    so it misses Option B
     
  3. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    i has to be your hardware then. I have that code working flawless in Proteus. Ill post a video... using mikroC pro and proteus to test it
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. dawson

    dawson New Member

    Joined:
    Sep 21, 2009
    Messages:
    97
    Likes:
    0
    Location:
    UK, north east

    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.
     
  6. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
  7. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    heh no problem you are right tho:

    Code (text):

    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
     
  8. dawson

    dawson New Member

    Joined:
    Sep 21, 2009
    Messages:
    97
    Likes:
    0
    Location:
    UK, north east
    Yea thats how it now works with the delays
     
  9. dawson

    dawson New Member

    Joined:
    Sep 21, 2009
    Messages:
    97
    Likes:
    0
    Location:
    UK, north east
    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 (text):

     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?
     
  10. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    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
     
  11. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    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 (text):

                   if (Button(&PORTA, MENU, 1, 0))
                       MainMenu();
     
    every now and then to check for the press
     
  12. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    This is my new temperature code:

    Code (text):

          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: Oct 25, 2009
  13. dawson

    dawson New Member

    Joined:
    Sep 21, 2009
    Messages:
    97
    Likes:
    0
    Location:
    UK, north east
    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 :)
     
  14. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    heh no problem :D if you need help just ask ok
     
  15. dawson

    dawson New Member

    Joined:
    Sep 21, 2009
    Messages:
    97
    Likes:
    0
    Location:
    UK, north east
    Sure will, thanks you have taught me a lot rther than just saying do this... cause i said so.


    Thanks :)
     
  16. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    thanks for saying thanks! heh i like helpin
     
  17. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US

Share This Page