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

designing with LCD 16x2 and switch for user interface

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



Joined: 25 Feb 2006
Posts: 23

View user's profile Send private message

designing with LCD 16x2 and switch for user interface
PostPosted: Thu Jan 22, 2009 2:50 pm     Reply with quote

I'm designing a circuit with three functions and I'm using a 16x2 LCD with some switches so that I can select one of the three function. The LCD would display the selected function and it's setting. I can use the switch to change between the three functions or change the function's setting.

My question is where in my program should I put the code for my switch and LCD? How should I structure my code when using LCD and switches for user interface?

I hope I'm making sense.

Thanks!
david90



Joined: 25 Feb 2006
Posts: 23

View user's profile Send private message

PostPosted: Sat Jan 24, 2009 1:17 am     Reply with quote

I need to know if my method of using an LCD for user interface is good. Is there a better way to program this? So far the code works and I could change the duty cycle but I also want to be able to change the frequency also using the same inputs pin.





Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c"
#include "lcd_registers.c"
//==========================
void main()
{
lcd_init();

while(1)
   {

      delay_ms(50);
      if (input_state(PIN_B0))
         increase_duty(1);
      if (input_state(PIN_B1))
         increase_duty(0);
   }
}


Code:

#Define PWM_label1 "[PWM]"
#Define PWM_label2 "Duty%:"
#Define PWM_label3 "Freq:"
int duty_cycle=50;
int frequency=1000;

void lcd_output()
{
   lcd_send_byte(0, 1);
   printf(lcd_putc,"%s %s%u\n%s%u",PWM_label1,PWM_label2,duty_cycle, PWM_label3,frequency);
}

void increase_duty(int1 c)
{
   if (c)
   {
      if(duty_cycle!=100)
      {
         duty_cycle=duty_cycle+1;
         lcd_output();
      }
   }
   else
   {
      if(duty_cycle!=0)
      {
         duty_cycle=duty_cycle-1;
         lcd_output();
      }
   }
}
david90



Joined: 25 Feb 2006
Posts: 23

View user's profile Send private message

PostPosted: Sat Jan 24, 2009 10:18 pm     Reply with quote

Any comments on my code architecture?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 25, 2009 3:54 pm     Reply with quote

The reason no one wants to answer is because you want a full-blown LCD menu system. That's not a trivial thing to code.
david90



Joined: 25 Feb 2006
Posts: 23

View user's profile Send private message

PostPosted: Mon Jan 26, 2009 1:48 am     Reply with quote

Is there an existing example of a menu system code then?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Jan 26, 2009 6:52 am     Reply with quote

Here is one example found by searching this forum that shows how to set
up a menu. It does not show the user input code.

http://www.ccsinfo.com/forum/viewtopic.php?t=30610
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