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 and pushbutton problem

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



Joined: 07 Jul 2011
Posts: 4

View user's profile Send private message

LCD and pushbutton problem
PostPosted: Wed Sep 21, 2011 1:31 am     Reply with quote

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
Lyreco



Joined: 07 Jul 2011
Posts: 4

View user's profile Send private message

PostPosted: Wed Sep 21, 2011 7:39 am     Reply with quote

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);
  }   
}
   
}
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Sep 21, 2011 3:12 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 21, 2011 3:27 pm     Reply with quote

button function in Code library:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Sep 21, 2011 4:45 pm     Reply with quote

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. ;-))
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 22, 2011 6:05 pm     Reply with quote

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.
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