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.

How to control the push button?

Status
Not open for further replies.

Re: Help me to control the push button ...

I forget to tell you, this code uses 155 bytes of RAM and requires 1736 bytes of ROM, what fit in your PIC16F877A which have 368 bytes of RAM and 14KB of ROM.

Look to use some newer uC with more resources and higher capabilities such as PIC18F46K22, of course for less money.
 

Re: Help me to control the push button ...

Today all day I was in a crowd, I've entered the home before 30 min. :|

See this example:

RC0 - change selection
RC1 - choose selected option
RC2 - back to main menu

Note: RC0,RC1,RC2 should be in pull-down.



Code:
// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_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;

int select, select_op, selection, submenu;

void main()
{
  Lcd_Init();                                 //LCD display initialization
  Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
  Lcd_Cmd(_LCD_CURSOR_OFF);                   //Turn cursor Off for LCD


  ANSELC = 0;                                 //Configure PortC pins as digital
  TRISC.B0  = 1;                              //Set RC0 pin as input - Selection
  TRISC.B1  = 1;                              //Set RC1 pin as input - Choose selection
  TRISC.B2  = 1;                              //Set RC2 pin as input - Back to Main menu


  select = 1;
  selection = 1;
  submenu = 0;
  select_op = 1;

  //Display main menu
  Lcd_Cmd(_LCD_CLEAR);      //Clear LCD screen
  Lcd_Out(1, 2,"Menu1");
  Lcd_Out(2, 2,"Menu2");
  Lcd_Out(1,10,"Menu3");
  Lcd_Out(2,10,"Menu4");


  while (1)
        {

        if ((PORTC.B0 = 1) && (submenu == 0))              //When press RC0 '>' selecting display options
             {
                switch(selection)
                    {
                    case 1:
                         Lcd_Chr(1,1,'>');
                         selection = 2;
                         select = 1;
                         Lcd_Chr(2,9,' ');
                    break;
                    case 2:
                         Lcd_Chr(2,1,'>');
                         selection = 3;
                         select = 2;
                         Lcd_Chr(1,1,' ');
                    break;
                    case 3:
                         Lcd_Chr(1,9,'>');
                         selection = 4;
                         select = 3;
                         Lcd_Chr(2,1,' ');
                    break;
                    case 4:
                         Lcd_Chr(2,9,'>');
                         selection = 1;
                         select = 4;
                         Lcd_Chr(1,9,' ');
                    break;
                    }
             }


        if (PORTC.B1 = 1)              //When press RC1 - choose selected option/menu
             {
             switch(select)
                {
                case 1:
                   Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
                   Lcd_Out(1, 1,"Menu 1");
                   Lcd_Out(1,10,"Option1");
                   Lcd_Out(2,10,"Option2");
                   submenu = 1;
                break;
                case 2:
                   Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
                   Lcd_Out(1, 1,"Menu 2");
                   Lcd_Out(1,10,"Option1");
                   Lcd_Out(2,10,"Option2");
                   submenu = 1;
                break;
                case 3:
                   Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
                   Lcd_Out(1, 1,"Menu 3");
                   Lcd_Out(1,10,"Option1");
                   Lcd_Out(2,10,"Option2");
                   submenu = 1;
                break;
                case 4:
                   Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
                   Lcd_Out(1, 1,"Menu 4");
                   Lcd_Out(1,10,"Option1");
                   Lcd_Out(2,10,"Option2");
                   submenu = 1;
                break;
                }
             }


        if ((PORTC.B0 = 1) && (submenu == 1))
            {
             switch(select_op)
                 {
                 case 1:
                    Lcd_Chr(1,9,'>');
                    select_op = 2;
                    Lcd_Chr(2,9,' ');
                 break;
                 case 2:
                    Lcd_Chr(2,9,'>');
                    select_op = 1;
                    Lcd_Chr(1,9,' ');
                 break;
                 }
            }






        //RETURN TO MAIN MENU IF RC2 is PRESSED
        if (PORTC.B2 = 1)
             {
             Lcd_Cmd(_LCD_CLEAR);      //Clear LCD screen
             Lcd_Out(1, 2,"Menu1");
             Lcd_Out(2, 2,"Menu2");
             Lcd_Out(1,10,"Menu3");
             Lcd_Out(2,10,"Menu4");
             submenu = 0;
             }



        Delay_ms(300);

        }

}


LCD Screenshots :

When you power device LCD show main menu :

View attachment 92859

When you press RC0 selection mark is showen '>' :

View attachment 92860

After proper selection we call selection with RC1 and second menu opens :

View attachment 92862

Again we use RC0 for selecting options :

View attachment 92863

.
.
.

When RC2 is pressed we back to main menu :

View attachment 92864






I write this in hurry, but can be optimized more.



Best regards,
Peter

:wink:

- - - Updated - - -

Tested and works 100% :smile:



thnx alooooooooooot Peter :)))))))))))))))

(^_^)
 

Re: Help me to control the push button ...

thnx alooooooooooot Peter :)))))))))))))))

(^_^)


No prob my friend,

If you have lots of screens this can be cheap solution, but for advanced look and projects consider GLCD 128x64 with touch screen, there is more space for datas and options. Also there is Touch LCD 2x16.




Best regards,
Peter

;-)
 

Re: Help me to control the push button ...

No prob my friend,

If you have lots of screens this can be cheap solution, but for advanced look and projects consider GLCD 128x64 with touch screen, there is more space for datas and options. Also there is Touch LCD 2x16.




Best regards,
Peter

;-)

(^_^) , i'm now edit the code for my project .. when finished , i will send code for u to see it

really thnx for yr TIME :) :) :)
 

Re: Help me to control the push button ...

Today all day I was in a crowd, I've entered the home before 30 min. :|

See this example:

RC0 - change selection
RC1 - choose selected option
RC2 - back to main menu

Note: RC0,RC1,RC2 should be in pull-down.



Code:
// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_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;

int select, select_op, selection, submenu;

void main()
{
  Lcd_Init();                                 //LCD display initialization
  Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
  Lcd_Cmd(_LCD_CURSOR_OFF);                   //Turn cursor Off for LCD


  ANSELC = 0;                                 //Configure PortC pins as digital
  TRISC.B0  = 1;                              //Set RC0 pin as input - Selection
  TRISC.B1  = 1;                              //Set RC1 pin as input - Choose selection
  TRISC.B2  = 1;                              //Set RC2 pin as input - Back to Main menu


  select = 1;
  selection = 1;
  submenu = 0;
  select_op = 1;

  //Display main menu
  Lcd_Cmd(_LCD_CLEAR);      //Clear LCD screen
  Lcd_Out(1, 2,"Menu1");
  Lcd_Out(2, 2,"Menu2");
  Lcd_Out(1,10,"Menu3");
  Lcd_Out(2,10,"Menu4");


  while (1)
        {

        if ((PORTC.B0 = 1) && (submenu == 0))              //When press RC0 '>' selecting display options
             {
                switch(selection)
                    {
                    case 1:
                         Lcd_Chr(1,1,'>');
                         selection = 2;
                         select = 1;
                         Lcd_Chr(2,9,' ');
                    break;
                    case 2:
                         Lcd_Chr(2,1,'>');
                         selection = 3;
                         select = 2;
                         Lcd_Chr(1,1,' ');
                    break;
                    case 3:
                         Lcd_Chr(1,9,'>');
                         selection = 4;
                         select = 3;
                         Lcd_Chr(2,1,' ');
                    break;
                    case 4:
                         Lcd_Chr(2,9,'>');
                         selection = 1;
                         select = 4;
                         Lcd_Chr(1,9,' ');
                    break;
                    }
             }


        if (PORTC.B1 = 1)              //When press RC1 - choose selected option/menu
             {
             switch(select)
                {
                case 1:
                   Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
                   Lcd_Out(1, 1,"Menu 1");
                   Lcd_Out(1,10,"Option1");
                   Lcd_Out(2,10,"Option2");
                   submenu = 1;
                break;
                case 2:
                   Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
                   Lcd_Out(1, 1,"Menu 2");
                   Lcd_Out(1,10,"Option1");
                   Lcd_Out(2,10,"Option2");
                   submenu = 1;
                break;
                case 3:
                   Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
                   Lcd_Out(1, 1,"Menu 3");
                   Lcd_Out(1,10,"Option1");
                   Lcd_Out(2,10,"Option2");
                   submenu = 1;
                break;
                case 4:
                   Lcd_Cmd(_LCD_CLEAR);                        //Clear LCD screen
                   Lcd_Out(1, 1,"Menu 4");
                   Lcd_Out(1,10,"Option1");
                   Lcd_Out(2,10,"Option2");
                   submenu = 1;
                break;
                }
             }


        if ((PORTC.B0 = 1) && (submenu == 1))
            {
             switch(select_op)
                 {
                 case 1:
                    Lcd_Chr(1,9,'>');
                    select_op = 2;
                    Lcd_Chr(2,9,' ');
                 break;
                 case 2:
                    Lcd_Chr(2,9,'>');
                    select_op = 1;
                    Lcd_Chr(1,9,' ');
                 break;
                 }
            }






        //RETURN TO MAIN MENU IF RC2 is PRESSED
        if (PORTC.B2 = 1)
             {
             Lcd_Cmd(_LCD_CLEAR);      //Clear LCD screen
             Lcd_Out(1, 2,"Menu1");
             Lcd_Out(2, 2,"Menu2");
             Lcd_Out(1,10,"Menu3");
             Lcd_Out(2,10,"Menu4");
             submenu = 0;
             }



        Delay_ms(300);

        }

}


LCD Screenshots :

When you power device LCD show main menu :

View attachment 92859

When you press RC0 selection mark is showen '>' :

View attachment 92860

After proper selection we call selection with RC1 and second menu opens :

View attachment 92862

Again we use RC0 for selecting options :

View attachment 92863

.
.
.

When RC2 is pressed we back to main menu :

View attachment 92864






I write this in hurry, but can be optimized more.



Best regards,
Peter

:wink:

- - - Updated - - -

Tested and works 100% :smile:

how can use these code with only one button ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top