Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Need urgent help in switch case in this menu code.

Status
Not open for further replies.

Rickooo

Member level 3
Joined
Aug 28, 2018
Messages
67
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
507
Hello, I am working on nmenu code and I want to do switching ON the LED by using push button which then select the desired menu on OLED SSD1306 . There are three button, up down and select which is connected to b5, b6, b7 pin and I want output at bo, b1, b2. Please look to the image added below the text. Now how do I switch ON the led when I select the desired menu on OLED and that time other 2 led is off.

I have used this switch logic;
Code:
void discharging_USB() {
       
        SSD1306_ClearDisplay();
        cursor(starting_row); 
        SSD1306_GotoXY(starting_col, starting_row);
        SSD1306_PutC("1. 5V 1A");
        delay_ms(10);
        start_row = starting_row;
        start_row +=1;
        SSD1306_GotoXY(starting_col, start_row);
        SSD1306_PutC("2. 5V 2A");
        delay_ms(10);
        start_row +=1;
        SSD1306_GotoXY(starting_col, start_row);
        SSD1306_PutC("3. 5V 3A");
        delay_ms(10);
        start_row +=1; 
        SSD1306_GotoXY(starting_col, start_row);
        SSD1306_PutC("4. Back");
        delay_ms(100);
       if (m2==1 && row_Ind == 1 && button_select==0){ 
       m2++;
        if( m2==2 && row_Ind ==1)
           {
           
           
           
            output_low(PIN_B0);
            output_low(PIN_B1);
            output_high(PIN_B2);
            button_select==1;
           }
           else if (m2==2 && row_Ind ==2){
           
            output_high(PIN_B0);
            output_low(PIN_B1);
            output_low(PIN_B2);
            button_select==1;
           }
            else if (m2==3 && row_Ind ==3){
            
            output_high(PIN_B0);
            output_low(PIN_B1);
            output_low(PIN_B2);
            button_select==1;
            }
           else 
           {
            output_low(PIN_B0);
            output_low(PIN_B1);
            output_high(PIN_B2);
            button_select==1;
       
        }
  }
       }

I don't know how do I frame this loop.

m2==1 mean that there is menu which is considered as m2==1
for eg:
1. ABC
2. DEF
3. GHI
and when m2==2 mean that when we go to sub menu of 1. ABC 2. DEF 3. GHI
and I wanna select sub menu of ABC, which is
1. 5V 1A
2. 5V 2A
3. 5V 3A
4. Back

If I just go with m2==2 then program get confuse with which menu it will go with, either ABC, DEF or GHI

Guide me what syntax do I use in it..
Awaiting your response.

Here is the image link:
http://postimg.cc/68js4q64
 
Last edited by a moderator:

It is your choice but I find the code confusing, I would do it differently:
Instead of writing everything "in-line", put the text and the output commands into an array. This lets you select them by one index instead of having to select them all each time. Then the selection process becomes a simple process of adding or subtracting from the index number.

The image link takes me to a home improvement web site! Please post images directly on Edaboard if possible.

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top