menu layout
This commit is contained in:
2
i2c.h
2
i2c.h
@@ -15,7 +15,7 @@
|
|||||||
#define SDA_PIN PC4 //PIN am Atmel
|
#define SDA_PIN PC4 //PIN am Atmel
|
||||||
#define SCL_PIN PC5 //PIN am Atmel
|
#define SCL_PIN PC5 //PIN am Atmel
|
||||||
#define I2C_PORT PORTC //PORT am Atmel
|
#define I2C_PORT PORTC //PORT am Atmel
|
||||||
#define SCL_CLOCK 100000UL
|
#define SCL_CLOCK 40000UL
|
||||||
|
|
||||||
void i2c_init(void);
|
void i2c_init(void);
|
||||||
uint8_t i2c_start (uint8_t);
|
uint8_t i2c_start (uint8_t);
|
||||||
|
|||||||
1
lcd.c
1
lcd.c
@@ -107,6 +107,7 @@ void lcd_init() {
|
|||||||
lcd_nibble_out(0x0C, 0);
|
lcd_nibble_out(0x0C, 0);
|
||||||
|
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
|
lcd_cursor(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//***************************************************************************************
|
//***************************************************************************************
|
||||||
|
|||||||
26
main.c
26
main.c
@@ -36,10 +36,14 @@ void modbusGet(void) {
|
|||||||
{
|
{
|
||||||
switch(rxbuffer[1]) {
|
switch(rxbuffer[1]) {
|
||||||
case fcReadHoldingRegisters:
|
case fcReadHoldingRegisters:
|
||||||
holdingRegisters[0] = OCR1A;
|
holdingRegisters[0] = duty[0];
|
||||||
holdingRegisters[1] = duty[0];
|
holdingRegisters[1] = duty[1];
|
||||||
holdingRegisters[2] = duty[1];
|
holdingRegisters[2] = duty[2];
|
||||||
holdingRegisters[3] = duty[2];
|
|
||||||
|
holdingRegisters[3] = temp_values[0];
|
||||||
|
holdingRegisters[4] = temp_values[1];
|
||||||
|
holdingRegisters[5] = temp_values[2];
|
||||||
|
|
||||||
modbusExchangeRegisters(holdingRegisters,0,10);
|
modbusExchangeRegisters(holdingRegisters,0,10);
|
||||||
break;
|
break;
|
||||||
case fcPresetSingleRegister:
|
case fcPresetSingleRegister:
|
||||||
@@ -70,6 +74,9 @@ void read_buttons(){
|
|||||||
set_item(4);
|
set_item(4);
|
||||||
else if(buttons & (1 << 4))
|
else if(buttons & (1 << 4))
|
||||||
set_item(5);
|
set_item(5);
|
||||||
|
else if((buttons & (1 << 5)) == 0) // inverted logic on this one
|
||||||
|
set_item(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@@ -82,7 +89,7 @@ int main(void)
|
|||||||
adc_init();
|
adc_init();
|
||||||
enc_init();
|
enc_init();
|
||||||
|
|
||||||
init_pid(&controller, 3, 0.13, 0);
|
init_pid(&controller, 1, 0.05, 0);
|
||||||
|
|
||||||
modbusSetAddress(1);
|
modbusSetAddress(1);
|
||||||
modbusInit();
|
modbusInit();
|
||||||
@@ -106,14 +113,19 @@ int main(void)
|
|||||||
modbusGet();
|
modbusGet();
|
||||||
read_buttons();
|
read_buttons();
|
||||||
|
|
||||||
//update lcd every once in a while
|
//blink cursor
|
||||||
if(x==0){
|
if(x==0){
|
||||||
|
//}
|
||||||
|
////write values
|
||||||
|
//if(x % 2048 == 0){
|
||||||
|
lcd_cursor(0);
|
||||||
write_temps();
|
write_temps();
|
||||||
write_setpoints();
|
write_setpoints();
|
||||||
|
write_motor();
|
||||||
update_cursor();
|
update_cursor();
|
||||||
}
|
}
|
||||||
x++;
|
x++;
|
||||||
if(x>=2024)
|
if(x >= 1024)
|
||||||
x=0;
|
x=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
71
menu.c
71
menu.c
@@ -19,15 +19,23 @@ void write_heater_set_temp(uint8_t n, uint16_t temp){
|
|||||||
void update_cursor(){
|
void update_cursor(){
|
||||||
switch(menu_state){
|
switch(menu_state){
|
||||||
case 1:
|
case 1:
|
||||||
lcd_set_position(2,8);
|
lcd_set_position(0,5);
|
||||||
lcd_cursor(1);
|
lcd_cursor(1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
lcd_set_position(2,13);
|
lcd_set_position(0,9);
|
||||||
lcd_cursor(1);
|
lcd_cursor(1);
|
||||||
break;
|
break;
|
||||||
case 3:
|
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);
|
lcd_cursor(1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -38,48 +46,59 @@ void update_cursor(){
|
|||||||
|
|
||||||
void draw_menu(){
|
void draw_menu(){
|
||||||
lcd_clear();
|
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_set_position(2, 0);
|
||||||
lcd_write(" set:");
|
lcd_write("motor:");
|
||||||
lcd_set_position(3, 0);
|
lcd_set_position(3, 0);
|
||||||
lcd_write("real:");
|
lcd_write("fan :");
|
||||||
//char str[16];
|
}
|
||||||
//sprintf(str, "test %d", 1);
|
|
||||||
//lcd_print_str(str);
|
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(){
|
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]);
|
sprintf(str, "%3i", temp_values[0]);
|
||||||
str[3] = 0xDF;
|
str[3] = 0xDF;
|
||||||
lcd_print_str(str);
|
lcd_print_str(str);
|
||||||
|
|
||||||
lcd_set_position(3, 11);
|
lcd_set_position(1, 7);
|
||||||
sprintf(str, "%3i", temp_values[1]);
|
sprintf(str, "%3i", temp_values[1]);
|
||||||
str[3] = 0xDF;
|
str[3] = 0xDF;
|
||||||
lcd_print_str(str);
|
lcd_print_str(str);
|
||||||
|
|
||||||
lcd_set_position(3, 16);
|
lcd_set_position(1, 12);
|
||||||
sprintf(str, "%3d", temp_values[2]);
|
sprintf(str, "%3d", temp_values[2]);
|
||||||
str[3] = 0xDF;
|
str[3] = 0xDF;
|
||||||
lcd_print_str(str);
|
lcd_print_str(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_setpoints(){
|
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]);
|
sprintf(str, "%3i", temp_setpoints[0]);
|
||||||
str[3] = 0xDF;
|
str[3] = 0xDF;
|
||||||
lcd_print_str(str);
|
lcd_print_str(str);
|
||||||
|
|
||||||
lcd_set_position(2, 11);
|
lcd_set_position(0, 7);
|
||||||
sprintf(str, "%3i%%", temp_setpoints[1]);
|
sprintf(str, "%3i%%", temp_setpoints[1]);
|
||||||
lcd_print_str(str);
|
lcd_print_str(str);
|
||||||
|
|
||||||
lcd_set_position(2, 16);
|
lcd_set_position(0, 12);
|
||||||
sprintf(str, "%3i%%", temp_setpoints[2]);
|
sprintf(str, "%3i%%", temp_setpoints[2]);
|
||||||
lcd_print_str(str);
|
lcd_print_str(str);
|
||||||
}
|
}
|
||||||
@@ -101,11 +120,19 @@ void enc_init(){
|
|||||||
|
|
||||||
void encoder_isr(){
|
void encoder_isr(){
|
||||||
//TODO good quadrature reading code
|
//TODO good quadrature reading code
|
||||||
if((PIND & (1<<7)) && (menu_state >= 1) && (menu_state <= 3)){
|
if((PIND & (1<<7))){
|
||||||
if(PIND & (1<<6))
|
if((menu_state >= 1) && (menu_state <= 3)){
|
||||||
temp_setpoints[menu_state-1]--;
|
if(PIND & (1<<6))
|
||||||
else
|
temp_setpoints[menu_state-1]--;
|
||||||
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<<7))
|
||||||
|
|||||||
1
menu.h
1
menu.h
@@ -8,6 +8,7 @@ extern volatile uint16_t temp_setpoints[4];
|
|||||||
|
|
||||||
void write_temps(void);
|
void write_temps(void);
|
||||||
void write_setpoints(void);
|
void write_setpoints(void);
|
||||||
|
void write_motor(void);
|
||||||
void update_cursor(void);
|
void update_cursor(void);
|
||||||
void set_item(uint8_t page_num);
|
void set_item(uint8_t page_num);
|
||||||
void draw_menu(void);
|
void draw_menu(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user