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 CCS Technical Support

Button assignment

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



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

Button assignment
PostPosted: Thu May 07, 2020 12:51 pm     Reply with quote

Dear All. Hope everyone is ok. I have an Lcd 20x4 and 5 buttons and i would like to make a menu (with pages). The buttons are Up, Down, Left, Right and Enter. Now the duty of every button from one page to another is not the same. Example on page 1 the duty of button Up is to scroll up from one line to another and of button Down is to scroll down from one line to another.

On page 2 the Up button is used to increment a typical variable assigned. Can someone please show me a principle of code because i got confused. To alter from one page to another is ok but the button assignment from one page to another - i have no idea and i really wish to understand it.
Mike Walne



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

View user's profile Send private message

PostPosted: Thu May 07, 2020 2:01 pm     Reply with quote

It's simpler to use only 3 buttons.

Your text for a page or up/down is on the top line of the LCD.

Each button is equally spaced below the bottom line.

The text above each button indicates its function.


Before programming play at computers and work out the paths through the code.
When you get really clever you can include a time out to prevent lockup.

Mike
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Thu May 07, 2020 2:14 pm     Reply with quote

Thanks for the reply but i did not understand what you are saying...sorry
Mike Walne



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

View user's profile Send private message

PostPosted: Thu May 07, 2020 2:46 pm     Reply with quote

We've met before and I still have no intention of writing code for you.

Maybe this will help.

1st line LCD___________Time setting 12:45
2nd line LCD ___________UP__DN__ENTER

Your three buttons line up under UP/DN/ENTER

It's a Time setting example, current time shows 12:45 with the 4 flashing to show it is being set.

Pressing UP increases 4 to 5.
Pressing DN decreases 4 to 3.
Pressing ENTER sets tens of minutes to 4 and moves on to 1's of hours.
Pressing ENTER twice more either returns to where you were before, or on to setting, day of week, month, day of month, year etc.
It's your program and it does what YOU want it to, NOT what I want it to.

Like I said before play at computers, work out what you want to do in pseudo code, THEN proceed to programming.
You don't do it all at once, start with a part of the code, write it, then test it 'til it begs for mercy.

Mike

PS If you don't like pseudo code draw a flowchart diagram of the pathways through your code.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 08, 2020 7:02 am     Reply with quote

If you're really 'frugal' you can do it with just ONE button... Very Happy

What you want can easily be done with the 'CASE' function.
First you need to 'see' which 'button' is pressed, hopefully from an ISR.
Then decode which button
Then use the 'case' function to direct the PIC to 'do something based upon which button was pressed'
Then in the 'level' or 'page' , you repeat ...

You will need some kind of 'timed' input though.
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Fri May 08, 2020 9:25 am     Reply with quote

Thanks for your replies. But my query is that my five buttons have different tasks for every page. How i can assign different tasks of these buttons according to the page/screen. I do not want codes...i want just ideas or discussion
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri May 08, 2020 9:38 am     Reply with quote

You just assign them different tasks....
You have the keys returning the same numeric code, and then in the
program for each page do the task required.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 08, 2020 9:50 am     Reply with quote

from the CCS C manual......
Code:

switch (cmd) {
    case 0:printf("cmd 0");
           break;
    case 1:printf("cmd 1");
           break;
    default:printf("bad cmd");
            break; }

For you, 'cmd' would be the value of the button pressed. Assuming you have an ISR that 'captures' or reads which button was pressed, you assign a value. Say '1' for up, '2' for down, etc... for the 5 buttons

Then in the SWITCH statement...
case 1 :do the 'up' stuff...
case 2 : do the 'dn' stuff...
...
case 5 : do the 'enter' stuff..

Within every 'level or 'page' , you simply change what is happening for the various 'cases'.....

Be sure to code for a default and invalid buttons AND have a 'timed' entry response. otherwise the PIC could look forever waiting for YOU to press a button !
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