五、MCU代码篇
(1)MCU程序整体部分
(2)MCU程序用户处理部分
(3)串口事件部分
(4) 处理用户部分代码
void userHandle(void)
{
uint8_t ret = 0;
static uint32_t lcdLastTimer = 0;
static uint32_t capLastTimer = 0;
static uint8_t last_cap=0;
uint8_t cap_id=0;
static uint16_t cap_time_count=0;
static uint16_t cap_time_count1=0;
if((gizwitsGetTimerCount()-lcdLastTimer) > LCD_TIME_MAX) //timeout = 2S
{
touch_scan();
static uint8 power_on=0;
ReadADCPoll(&temperature_c);
if(0x00 == power_on)
{
power_on=1;
memset_my(g_showBuff, 0x00, sizeof(g_showBuff));
// show_mode_signal();
return;
}
show_temperature(temperature_c.cur_temp, RT);
show_mode_signal();
// show_time(); //20160122时间不准,去掉显示时间
lcd_reload();
if(temperature_c.backlight > 0)
{
temperature_c.backlight--;
lcd_backlight(temperature_c.backlight);
}
if(temperature_c.sync_delay > 0)
{
temperature_c.sync_delay--;
if(0x00 == temperature_c.sync_delay)
{
temperature_c.sync_flag = 1;
}
}
lcdLastTimer = gizwitsGetTimerCount();
}
if((gizwitsGetTimerCount()-capLastTimer) > CAP_SCAN_PERIOD) //timeout = 2S
{
auto_rev_opt(&temperature_c);
led_buzzer_ctrl(0,0);
cap_id=GET_TOUCH_NUMBER();
if (last_cap!=cap_id)
{
last_cap =cap_id;
}
else
{
if (0!=cap_id)
{
cap_pad[cap_id- 1].touch = 1; //for relay ctrl
led_buzzer_ctrl(logicch2phych[cap_id-1],1);
led_buzzer_ctrl(5,1);
}
}
if (cap_id == 1)
{
cap_time_count++;
if (cap_time_count > 5000 / CAP_SCAN_PERIOD)
{
gizwitsSetMode(SoftAp_Mode);
cap_time_count = 0;
lcd_init();
}
} else
{
cap_time_count = 0;
}
if (cap_id == 4)
{
cap_time_count1++;
if (cap_time_count1 > 5000 / CAP_SCAN_PERIOD)
{
gizwitsSetMode(AirLink_Mode);
cap_time_count1 = 0;
lcd_init();
}
} else
{
cap_time_count1 = 0;
}
capLastTimer = gizwitsGetTimerCount();
}
}
(5)功能为触摸按键检测 、温度检测和 LCD刷新代码部分
void smart_frame(uint8_t cmd[],uint8_t buff[])
{
uint8_t data[5],state=0;
if ((cmd[0]!=9)&&(cmd[0]!=6)) return ;
if (cmd[1]!=3) return ;
if (cmd[3]!=0) return ;
if (cmd[4]!=0) return ;
IWDG->KR=0xaaaa;
smart_frame_buff *wifi_data = (smart_frame_buff *)buff;
if (wifi_data->action==0x02)
{
//read;
send_state_frame();
//state|=((temperature_c.temp_param.mode<<2)&0x12);
}
if (wifi_data->action==0x01)
{
if (wifi_data->attrr_flags&0x01)
{
temperature_c.temp_param.on_off=(((wifi_data->attrr_value_L & 0x01)!=0 )?1:0);
}
if (wifi_data->attrr_flags&0x02)
{
temperature_c.temp_param.lock=(((wifi_data->attrr_value_L&0x02)!=0)?1:0);
}
if (wifi_data->attrr_flags&0x04)
{
temperature_c.temp_param.mode=((wifi_data->attrr_value_L&0x0c)>>2);
}
if (wifi_data->attrr_flags&0x08)
{
temperature_c.temp_param.speed=((wifi_data->attrr_value_L&0x30)>>4);
}
if (wifi_data->attrr_flags&0x16)
{
temperature_c.temp_param.limit_t=BIN2BCD(wifi_data->attrr_value_H);
}
//write
led_buzzer_ctrl(5,1);
temperature_c.backlight = 60;
ctrl_reply();
}
}
详细代码请查阅本主题帖代码附件,谢谢!