Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 25th October 2009, 05:31 PM   #76
Default

i meant like the project files. Like can you post a zip or something with all files in that folder so i can see how everything is setup
AtomSoft is offline  
Old 25th October 2009, 06:14 PM   #77
Default

Here is my project files and schematic
Attached Files
File Type: zip menu.zip (89.2 KB, 12 views)
dawson is offline  
Old 25th October 2009, 06:17 PM   #78
Default

You are using MikroC ? Or MikroC Pro?
AtomSoft is offline  
Old 25th October 2009, 06:22 PM   #79
Default

mikroC PRO sorry didnt realise there was a difference
dawson is offline  
Old 25th October 2009, 06:51 PM   #80
Default

Try This pal:
Code:
//REV2
 #define MENU   2
#define UP  3
#define DOWN  4
// LCD connections definitions
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_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 TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_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 connections definitions

 unsigned char MainMenuLIST[3][16] = {
{"Option A"},
{"Option B"},
{"Option C"}
};

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))
          done = MENU;
    if (Button(&PORTA, UP, 1, 0))
          done = UP;
    if (Button(&PORTA, DOWN, 1, 0))
          done = DOWN;
        }
        return done;                                  //Return our done/key var
}

void MainMenu(void){
unsigned char POS = 0;         //Used for cursor ONLY!
unsigned char done = 0;
unsigned char x;
unsigned char ITEM=0;
unsigned char PAGE=0;

Lcd_Cmd(_LCD_CLEAR);

while(!done){
    for(x=0;x<2;x++){
        if(x == POS)
            Lcd_Out((x+1),1,">");
        else
            Lcd_Out((x+1),1," ");
            
        Lcd_Out((x+1),2,MainMenuLIST[(x+PAGE)]);
    }

    switch(WaitForInput()){
        case UP:
            if(POS>0){
                POS--;
                ITEM--;
            } else {
                if(PAGE>0){
                    POS++;
                    ITEM++;
                    PAGE=0;
                }
            }
            break;
        case DOWN:
            if(POS<1){
                POS++;
                ITEM++;
            } else {
                if(PAGE<1){
                    PAGE = 1;
                    POS--;
                    ITEM--;
                }
            }
            break;
        case MENU:
            done = 0xFF;
            break;
    }
}
        // ITEM contains what item is selected
        // POS isnt used incase larger then 2 menu...
    ITEM+=PAGE;
    switch(ITEM){
        case 0:
            Delay_ms(2000);
            break;
        case 1:
            Delay_ms(2000);
            break;
    }
}


void main() {
  CMCON  |= 7;                       // Disable Comparators
  TRISA = 0b00011100;                 // RA5,RA4,RA3,RA2 are set to input
  Lcd_Init();                                    // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                           // Clear LCD
  Lcd_Cmd(_LCD_CURSOR_OFF);                      // Turn cursor off
  Lcd_Out(1, 3, "Waiting");
      do {
 switch(WaitForInput()){
                case MENU:
                Delay_ms(100);
                MainMenu();
                break;
                }

} while (1);
}

Last edited by AtomSoft; 25th October 2009 at 06:55 PM.
AtomSoft is offline  
Old 25th October 2009, 06:56 PM   #81
Default

hey i just edited the above code. Use the one with

Code:
//REV2
at the top
AtomSoft is offline  
Old 25th October 2009, 07:02 PM   #82
Default

That last one now produces:

">Option A"
"Option B"

"Option B"
">Option C"

so it misses Option B
dawson is offline  
Old 25th October 2009, 07:14 PM   #83
Default

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
AtomSoft is offline  
Old 25th October 2009, 07:26 PM   #84
Default

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.
dawson is offline  
Old 25th October 2009, 07:33 PM   #85
Default

Here is the simulation video:

YouTube - Menu Help
AtomSoft is offline  
Old 25th October 2009, 07:39 PM   #86
Default

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
AtomSoft is offline  
Old 25th October 2009, 07:39 PM   #87
Default

Yea thats how it now works with the delays
dawson is offline  
Old 25th October 2009, 07:48 PM   #88
Default

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?
dawson is offline  
Old 25th October 2009, 08:08 PM   #89
Default

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 is offline  
Old 25th October 2009, 08:13 PM   #90
Default

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 is offline  
Reply

Tags
lcd, menu

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
LCD menu in C? picstudent Micro Controllers 1 13th September 2009 04:48 AM
LCD+keypad interface -> menu structure. Concepts sought. Assembly. PIC. astronomerroyal Micro Controllers 23 29th August 2008 04:59 AM
LG CRT Repair and servce menu. dark666 General Electronics Chat 0 7th June 2008 06:17 PM
Electronic Music Menu cyprio7 General Electronics Chat 0 11th April 2008 04:50 PM
One menu, multiple pages. Anyone good at websites? ThermalRunaway Chit-Chat 6 25th June 2006 11:45 AM



All times are GMT. The time now is 06:05 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker