menu layout

rewrite_for_hd774
Eggert Jung 4 years ago
parent f85971e49b
commit bfdd4210e1

@ -15,7 +15,7 @@
#define SDA_PIN PC4 //PIN am Atmel
#define SCL_PIN PC5 //PIN am Atmel
#define I2C_PORT PORTC //PORT am Atmel
#define SCL_CLOCK 100000UL
#define SCL_CLOCK 40000UL
void i2c_init(void);
uint8_t i2c_start (uint8_t);

@ -107,6 +107,7 @@ void lcd_init() {
lcd_nibble_out(0x0C, 0);
lcd_clear();
lcd_cursor(0);
}
//***************************************************************************************

@ -36,10 +36,14 @@ void modbusGet(void) {
{
switch(rxbuffer[1]) {
case fcReadHoldingRegisters:
holdingRegisters[0] = OCR1A;
holdingRegisters[1] = duty[0];
holdingRegisters[2] = duty[1];
holdingRegisters[3] = duty[2];
holdingRegisters[0] = duty[0];
holdingRegisters[1] = duty[1];
holdingRegisters[2] = duty[2];
holdingRegisters[3] = temp_values[0];
holdingRegisters[4] = temp_values[1];
holdingRegisters[5] = temp_values[2];
modbusExchangeRegisters(holdingRegisters,0,10);
break;
case fcPresetSingleRegister:
@ -70,6 +74,9 @@ void read_buttons(){
set_item(4);
else if(buttons & (1 << 4))
set_item(5);
else if((buttons & (1 << 5)) == 0) // inverted logic on this one
set_item(0);
}
int main(void)
@ -82,7 +89,7 @@ int main(void)
adc_init();
enc_init();
init_pid(&controller, 3, 0.13, 0);
init_pid(&controller, 1, 0.05, 0);
modbusSetAddress(1);
modbusInit();
@ -106,14 +113,19 @@ int main(void)
modbusGet();
read_buttons();
//update lcd every once in a while
//blink cursor
if(x==0){
//}
////write values
//if(x % 2048 == 0){
lcd_cursor(0);
write_temps();
write_setpoints();
write_motor();
update_cursor();
}
x++;
if(x>=2024)
if(x >= 1024)
x=0;
}
}

@ -19,15 +19,23 @@ void write_heater_set_temp(uint8_t n, uint16_t temp){
void update_cursor(){
switch(menu_state){
case 1:
lcd_set_position(2,8);
lcd_set_position(0,5);
lcd_cursor(1);
break;
case 2:
lcd_set_position(2,13);
lcd_set_position(0,9);
lcd_cursor(1);
break;
case 3:
lcd_set_position(2,18);
lcd_set_position(0,14);
lcd_cursor(1);
break;
case 4:
lcd_set_position(2,9);
lcd_cursor(1);
break;
case 5:
lcd_set_position(3,9);
lcd_cursor(1);
break;
default:
@ -38,48 +46,59 @@ void update_cursor(){
void draw_menu(){
lcd_clear();
lcd_write(" Heat Zone Control");
lcd_set_position(0, 0);
lcd_write("s:");
lcd_set_position(1, 0);
lcd_write("r:");
lcd_set_position(2, 0);
lcd_write(" set:");
lcd_write("motor:");
lcd_set_position(3, 0);
lcd_write("real:");
//char str[16];
//sprintf(str, "test %d", 1);
//lcd_print_str(str);
lcd_write("fan :");
}
void write_motor(){
char str[5];
str[4] = 0; //null terminated
lcd_set_position(2, 7);
sprintf(str, "%3i", OCR2B);
lcd_print_str(str);
}
void write_temps(){
char str[4];
char str[5];
str[4] = 0; //null terminated
lcd_set_position(3, 6);
lcd_set_position(1, 3);
sprintf(str, "%3i", temp_values[0]);
str[3] = 0xDF;
lcd_print_str(str);
lcd_set_position(3, 11);
lcd_set_position(1, 7);
sprintf(str, "%3i", temp_values[1]);
str[3] = 0xDF;
lcd_print_str(str);
lcd_set_position(3, 16);
lcd_set_position(1, 12);
sprintf(str, "%3d", temp_values[2]);
str[3] = 0xDF;
lcd_print_str(str);
}
void write_setpoints(){
char str[4];
char str[5];
str[4] = 0; //null terminated
lcd_set_position(2, 6);
lcd_set_position(0, 3);
sprintf(str, "%3i", temp_setpoints[0]);
str[3] = 0xDF;
lcd_print_str(str);
lcd_set_position(2, 11);
lcd_set_position(0, 7);
sprintf(str, "%3i%%", temp_setpoints[1]);
lcd_print_str(str);
lcd_set_position(2, 16);
lcd_set_position(0, 12);
sprintf(str, "%3i%%", temp_setpoints[2]);
lcd_print_str(str);
}
@ -101,12 +120,20 @@ void enc_init(){
void encoder_isr(){
//TODO good quadrature reading code
if((PIND & (1<<7)) && (menu_state >= 1) && (menu_state <= 3)){
if((PIND & (1<<7))){
if((menu_state >= 1) && (menu_state <= 3)){
if(PIND & (1<<6))
temp_setpoints[menu_state-1]--;
else
temp_setpoints[menu_state-1]++;
}
if(menu_state == 4){
if(PIND & (1<<6) && (OCR2B > 0))
OCR2B--;
else if(!(PIND & (1<<6)) && (OCR2B < 255))
OCR2B++;
}
}
//if(PIND & (1<<7))
// if(PIND & (1<<6)){

@ -8,6 +8,7 @@ extern volatile uint16_t temp_setpoints[4];
void write_temps(void);
void write_setpoints(void);
void write_motor(void);
void update_cursor(void);
void set_item(uint8_t page_num);
void draw_menu(void);

Loading…
Cancel
Save