CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

LCD Menu problems

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
noral



Joined: 09 May 2014
Posts: 4

View user's profile Send private message

LCD Menu problems
PostPosted: Fri Jun 20, 2014 2:41 am     Reply with quote

Hi everyone!!

I'm developing a user's menu with two buttons to introduce a value. To reach my goal I use a increaser counter from 0 to 9 to introduce the hundreds in "MENU2" and the tens in "MENU3". With the left button I increase the number and with right button I want to move the cursor to introduce the tens.

My issue is that I can't pass from the "MENU2" to "MENU3".

Can anybody help me? I attach the code.

Code:

#include <24FJ128GC010.H>
#device adc=12
#fuses FRC, NOWDT, NOPROTECT, BROWNOUT, ICSP1
#use delay(clock = 8000000)
#include <flex_lcd.c>
#define ledrojo PIN_E0
#define ledverde PIN_E1
#define botonder PIN_E2
#define botonizq PIN_E3
#define buzzer PIN_E4
int boton;


//==========================

float tension;
signed int32 read;
int menu=1;
int i=0;
char tabNum[10]={'0','1','2','3','4','5','6','7','8','9'},j=0;
int mov[10];
int centenas;
int decenas;
int unidades;

void configurar(void);

void main()
{
    disable_interrupts(GLOBAL);

    setup_oscillator(OSC_INTERNAL,8000000);

    output_low(ledrojo);
    output_low(ledverde);
    output_low(buzzer);

    lcd_init();
    delay_ms(100);
    lcd_gotoxy(1,1);
    printf(lcd_putc,"\fLISTO!");
    printf(lcd_putc,"\n");
    delay_ms(1500);
    printf(lcd_putc,"\f");
    delay_ms(750);

    while(1)
    {
        if(input(botonder)==1){ //boton
            delay_ms(30);
        if(input(botonder)==1){
            output_toggle(PIN_E0); //salida led
            output_toggle(PIN_E1); //salida led
            configurar();
            menu++;
            if (menu==7){
                menu=1;
                delay_ms(30);
            }
            while(input(botonder)==1);
        }
        }
    }
}

void configurar()
{
    switch (menu)
    {
        case 1:menu=1;
        {
            printf(lcd_putc, "\f");
            printf(lcd_putc, "\n          INICIO");
        }
        break;
        case 2: menu=2;
        {
            printf(lcd_putc, "\fMENU2:");
            printf(lcd_putc, "\n             -->");
            while(menu=2){                     
                if(input(botonizq)){                 
                        do{                           
                        }while(input(botonizq));
                        delay_ms(75);
                        if(j>9){                     
                            j=0;                     
                            output_high(buzzer);         
                            delay_ms(50);               
                            output_low(buzzer);           
                         }
                         lcd_gotoxy(1,2);
                         printf(lcd_putc,"%c",tabNum[j]);   
                         printf(lcd_putc,"\b");           
                         j++;
                         //incremento contador indice tabNum
                }
                if(input(botonder)==1){
                    menu=3;
                }
            }                     
        centenas=j*100;               
        }
        break;
        case 3: menu=3;
        {
            printf(lcd_putc, "\fMENU3:");
            while (menu==3){                     
                if(!input(botonizq)){                 
                    do{                           
                    }while(!input(botonizq));           
                        if(j>9){                     
                        j=0;                     
                        output_high(buzzer);       
                        delay_ms(50);               
                        output_low(buzzer);           
                        }
                    lcd_gotoxy(2,2);
                    printf(lcd_putc,"a");   
                    //printf(lcd_putc,"\b");           
                    j++;                       
                }
            }                     
            decenas=j*10;
        }
}
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Jun 20, 2014 4:46 am     Reply with quote

Take a step back.
Work out what you want to happen with pencil and paper.
Draw a picture of what you want to see at each stage.
It should fall out.

Mike
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Fri Jun 20, 2014 5:26 am     Reply with quote

Mike Walne wrote:
Take a step back.
Work out what you want to happen with pencil and paper.
Draw a picture of what you want to see at each stage.
It should fall out.


Also think strongly about separating the functions: button handling/debouncing, and menu processing. Its simpler to do and involves less repeated code than trying to do it all in one hit.

I had a similar sort of problem on a ARM based product with just two user buttons. I wrote a button press handler that did all the button stuff, and a table driven menu handler which implemented the menu functions. One button was for moving from item to item in the menus, the other was for selecting the menu item. I could have several levels of menus, all defined by the table. So it was left press, press to get to an item/sub-menu, right press to select it, left press to traverse the sub-menu, right press to select, etc.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group