View previous topic :: View next topic |
Author |
Message |
Lyreco
Joined: 07 Jul 2011 Posts: 4
|
LCD and pushbutton problem |
Posted: Wed Sep 21, 2011 1:31 am |
|
|
hello everyone,
I have a PICDEM PIC18 dev board and I am writing to the lcd directly bypassing the i/o expander.
I have used the flex lcd to get some display on the lcd which works, now I am trying to use the two push buttons and integrate it with the lcd.
What I wish to do is write a function for the push buttons which will be called in the main. I want to have push button 1 cycle through a menu (list) and use push button 2 to select a list.
Is this difficult to do?
ie: push button 1 will scroll through a list of items with each continuous press, button 2 selects a chosen item.
regards
![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Lyreco
Joined: 07 Jul 2011 Posts: 4
|
|
Posted: Wed Sep 21, 2011 7:39 am |
|
|
I have this code here...
Which works as a two button model (button 1 = mode1, button 2= mode 2).
But i need to use button 1 to cycle through the modes and use button 2 to select a particular mode.
How would I approach this, can case/switch statements be used or a counter?
Thanks. )
Code: |
void main()
{
lcd_init();
set_tris_a(0x20); // Set Pin A5 as input
set_tris_b(0x01); // Set Pin B0 as input
//setup_adc_ports(NO_ANALOGS);
while(TRUE){
{
if(button(PIN_B0, 0, 50, 10, B0, 1)) {
printf(lcd_putc, "\fMODE 1");
output_high(PIN_D6);
}
if(button(PIN_A5, 0, 50, 10, A5, 1)){
printf(lcd_putc, "\fMODE 2");
output_high(PIN_D2);
}
delay_ms(100);
output_low(PIN_D2);
output_low(PIN_D6);
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Sep 21, 2011 3:12 pm |
|
|
button(PIN_B0, 0, 50, 10, B0, 1) ?????
does not compile!!!
where is this "button()" function??
did you write or copy it?
show what you wrote
then maybe you get help |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Sep 21, 2011 4:45 pm |
|
|
you say
Quote: |
How would I approach this, can case/switch statements be used or a counter?
|
so how would YOU modify or rewrite that routine ?
this is more of a general programing question than a CCS issue.
there are several approaches to solving this but a state machine oriented
replacement for button() could work with both CASE or IF THEN logic.
its the idea that counts.
But however you do it - you will benefit from thinking about how you can use timers to keep track of what is going on
at any given moment -the "state of your machine" - if you will.
if you feel you have to use a DELAY_MS statement at any point to make it work - IMHO, you are on the wrong track. ;-)) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 22, 2011 6:05 pm |
|
|
Quote: |
I want to have push button 1 cycle through a menu (list) and use push
button 2 to select a list.
|
This post has sample code for two buttons to perform Set and Select
functions in a menu. Maybe it can be modified to do what you want.
http://www.ccsinfo.com/forum/viewtopic.php?t=39585&start=1
This is just the button code. You will have to add the menu code. |
|
![](templates/subSilver/images/spacer.gif) |
|