View previous topic :: View next topic |
Author |
Message |
david90
Joined: 25 Feb 2006 Posts: 23
|
designing with LCD 16x2 and switch for user interface |
Posted: Thu Jan 22, 2009 2:50 pm |
|
|
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
|
|
Posted: Sat Jan 24, 2009 1:17 am |
|
|
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
|
|
Posted: Sat Jan 24, 2009 10:18 pm |
|
|
Any comments on my code architecture? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 25, 2009 3:54 pm |
|
|
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
|
|
Posted: Mon Jan 26, 2009 1:48 am |
|
|
Is there an existing example of a menu system code then? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
|
|