单片机屏幕多级菜单系统之当前屏幕号+屏幕菜单当前深度 机制:
#include <stdio.h>
#include "ruanhead.h"
#include "app_define.h"
#include "app_function.h"
#include "app_menu.h"
#include "app_struct.h"
#include "app_bsp.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>
typedef unsigned char INT8U; /* Unsigned 8 bit quantity */
typedef signed char INT8S; /* Signed 8 bit quantity */
typedef unsigned short INT16U; /* Unsigned 16 bit quantity */
typedef signed short INT16S; /* Signed 16 bit quantity */
typedef unsigned int INT32U; /* Unsigned 32 bit quantity */
typedef signed int INT32S; /* Signed 32 bit quantity */
#define FAIL 0xFF //失败
#define B_TRUE 1 // 位真逻辑
#define B_FALSE 0 // 位假逻辑
#define L_TRUE 0x55 // 真逻辑
#define L_FALSE 0xAA // 假逻辑
#include "core_cm4.h" // 根据你的内核选择头文件
extern Uint8 zhankongbi_value[CTR_LINE];
void V2_2_set_ch_zhankongbi(u8 zhankongbi_inn,u8 ch);
extern u16 cur_time_for_a_Cycle[CTR_LINE]; //当前步数索引
V2_1_canshuos canshuos_1;
void LCD_Value3dot0Display1206(Uint8 x, Uint8 y, Uint16 val);
u32 V2_1_shansuo_for_tiaoguang_sel=0;
u8 V2_1_is_ing_liangdu_edit=0;
void V2_1_display_0_100_percent(Uint8 x, Uint8 y, Uint8 per_cent,Uint8 ch){
if(LCD_CurMenu.Menu==0x00||(ch!=LCD_CurMenu.Line)||V2_1_is_ing_liangdu_edit==0){
LCD_CurMenu.Versa = L_TRUE;
LCD_Value3dot0Display1206(x,y,per_cent);
LCD_CurMenu.Versa = L_FALSE;
// LCD_EnglishDisplay1206(x, y+6*3, 65); // "%"
}
//LCD_CurMenu.Line==(NUM_LINE_STATUS_SET-1):全选:
if(LCD_CurMenu.Menu!=0x00&&(ch==LCD_CurMenu.Line||LCD_CurMenu.Line==(NUM_LINE_STATUS_SET-1)) &&V2_1_is_ing_liangdu_edit==1 ){
if(V2_1_shansuo_for_tiaoguang_sel<50*6){ //600ms
LCD_CurMenu.Versa = L_TRUE;
LCD_Value3dot0Display1206(x,y,per_cent);
LCD_CurMenu.Versa = L_FALSE;
}else if(V2_1_shansuo_for_tiaoguang_sel<50*6*2){
LCD_Value3dot0Display1206(x,y,per_cent);
}else{
V2_1_shansuo_for_tiaoguang_sel=0;
}
// LCD_EnglishDisplay1206(x, y+6*3, 65); // "%"
}
}
void SYS_DelayMs(uint16_t nms);
void LCD_DisplayStatusMenu(); //每回路状态显示菜单
void V2_1_add_liangdu_(Uint8 ch){
Uint32 wait_Cycle_ccc=0;
if(ch>(CTR_LINE-1)){return;}
zhankongbi_value[ch]=zhankongbi_value[ch]+10;
if(zhankongbi_value[ch]>100){
zhankongbi_value[ch]=0;
}
//等到cur_time_for_a_Cycle[ch]<5时再动作,这样亮度才不会闪烁一下:
while(cur_time_for_a_Cycle[ch]>5 && wait_Cycle_ccc<=30 )
{
wait_Cycle_ccc++;
SYS_DelayMs(1);
}
V2_2_set_ch_zhankongbi(zhankongbi_value[ch],ch);
SYS_LCDDISPLAY.MainDisplay = 0;
Flag.Update_Delay=0;
LCD_DisplayStatusMenu(); //每回路状态显示菜单
}
#define flag_save_canshuos_init 123//122
u8 save_buf_tmp[150];
void V2_1_reload_tiaoguang_canshuo_data(){
V2_1_AT24CXX_SequentialRead(V2_1_EEP_is_tiaoguang_canshuo_inited, save_buf_tmp, 1);
//if(save_buf_tmp[0]==flag_save_canshuos_init)
{
V2_1_AT24CXX_SequentialRead(V2_1_EEP_beihe_start_tiaoguang_value, save_buf_tmp, 1);
canshuos_1.beihe_start_tiaoguang_value=save_buf_tmp[0];
V2_1_AT24CXX_SequentialRead(V2_1_EEP_duankai_start_tiaoguang_value, save_buf_tmp, 1);
canshuos_1.duankai_start_tiaoguang_value=save_buf_tmp[0];
//-------------------------------------------------------------------------
V2_1_AT24CXX_SequentialRead(V2_1_EEP_zongkai_tiaoguang_value, save_buf_tmp, 1);
canshuos_1.zongkai_tiaoguang_value=save_buf_tmp[0];
V2_1_AT24CXX_SequentialRead(V2_1_EEP_zongguan_tiaoguang_value, save_buf_tmp, 1);
canshuos_1.zongguan_tiaoguang_value=save_buf_tmp[0];
V2_1_AT24CXX_SequentialRead(V2_1_EEP_xiaofan_qiangqi_tiaoguang_value, save_buf_tmp, 1);
canshuos_1.xiaofan_qiangqi_tiaoguang_value=save_buf_tmp[0];
V2_1_AT24CXX_SequentialRead(V2_1_EEP_jianbian_times, save_buf_tmp, 1);
canshuos_1.jianbian_times=save_buf_tmp[0];//实际值时需要除以10
}
}
void V2_1_init_canshuos_sets(u8 is_qiangzhi){
u8 i=0;
u8 EEP_FlagW_adj = I2CReadData(0xA0, V2_1_EEP_is_tiaoguang_canshuo_inited);
int re_try_count=0;
while(EEP_FlagW_adj!=flag_save_canshuos_init && re_try_count<=10){//防止误触发 初始化 的操作!!!!!!
SYS_DelayMs(100);
re_try_count++;
EEP_FlagW_adj = I2CReadData(0xA0, V2_1_EEP_is_tiaoguang_canshuo_inited);
//CTR_L1; //彭工说现场不能这样搞!
}
if(is_qiangzhi==1|| (EEP_FlagW_adj!=flag_save_canshuos_init ) ){
save_buf_tmp[0]=5;
V2_1_AT24CXX_PageWrite(V2_1_EEP_beihe_start_tiaoguang_value ,save_buf_tmp, 1);
save_buf_tmp[0]=5;
V2_1_AT24CXX_PageWrite(V2_1_EEP_duankai_start_tiaoguang_value ,save_buf_tmp, 1);
save_buf_tmp[0]=100;
V2_1_AT24CXX_PageWrite(V2_1_EEP_zongkai_tiaoguang_value ,save_buf_tmp, 1);
save_buf_tmp[0]=0;
V2_1_AT24CXX_PageWrite(V2_1_EEP_zongguan_tiaoguang_value ,save_buf_tmp, 1);
save_buf_tmp[0]=100;
V2_1_AT24CXX_PageWrite(V2_1_EEP_xiaofan_qiangqi_tiaoguang_value ,save_buf_tmp, 1);
save_buf_tmp[0]=10;//需要除以10,10/10=1秒
V2_1_AT24CXX_PageWrite(V2_1_EEP_jianbian_times ,save_buf_tmp,1);
//放在最后:
save_buf_tmp[0]=flag_save_canshuos_init;
V2_1_AT24CXX_PageWrite(V2_1_EEP_is_tiaoguang_canshuo_inited ,save_buf_tmp, 1);
V2_1_reload_tiaoguang_canshuo_data();
}
}
u8 shansuo_set_led_count=0;
u32 V2_1_delay_ms1_for_shansuo_set_led=0;
u8 led_fanzhuan_Ed_ccc=0;
u8 shansuo_step1=0;
void set_shansuo_set_led_count(u8 ccc){
if(shansuo_step1==0){
shansuo_set_led_count=ccc;
}
}
void clear_shansuo_set_led_count(){
shansuo_step1=0;
shansuo_set_led_count=0;
}
//为了i2c寿命,提示写入中:
void V2_1_process_led_shansuo_for_tishi_i2cRom_writing_for_save_shouming(){
if(shansuo_step1==0){
if(shansuo_set_led_count>0){
shansuo_step1=1;
}
}
else
if(shansuo_step1==1){
if(shansuo_set_led_count>0){
if(V2_1_delay_ms1_for_shansuo_set_led>=100){
V2_1_delay_ms1_for_shansuo_set_led=0;
led_fanzhuan_Ed_ccc++;
SET_LED;
if(led_fanzhuan_Ed_ccc>=2){
led_fanzhuan_Ed_ccc=0;
shansuo_set_led_count=shansuo_set_led_count-1;
if(shansuo_set_led_count==0){
V2_1_delay_ms1_for_shansuo_set_led=0;
shansuo_step1=2;
}
}
}
}
}else if(shansuo_step1==2){
if(V2_1_delay_ms1_for_shansuo_set_led>=300){
shansuo_step1=3;
}
}else if(shansuo_step1==3){
shansuo_set_led_count=0;
shansuo_step1=0;
SET_LED_0;
if(SYS_LCDDISPLAY.MainDisplayFlag==L_FALSE){
SET_LED_1;
}
}else{
shansuo_step1=0;
}
}
Uint8 V2_1_the_menu_deepth=0;
void LCD_Value3dot0Display1206B(Uint8 x, Uint8 y, Uint16 val);
void show_value1(Uint8 x, Uint8 y,u16 set1,u8 Item_Line_Index){
if(LCD_CurMenu.Line==Item_Line_Index){//如果是当前的项
if(V2_1_the_menu_deepth==0){
//外框选中:
LCD_Value3dot0Display1206B(x,y,set1);
}
if(V2_1_the_menu_deepth==1){ //反显:
LCD_CurMenu.Versa=L_TRUE;
LCD_Value3dot0Display1206(x,y,set1);
LCD_CurMenu.Versa=L_FALSE;
}
}else{
LCD_Value3dot0Display1206(x,y,set1);
}
}
void V2_1_LCD_tiaohguang_Parameter_UI(){
Uint8 y;
LCD_ClearBuffer(); // Clear LCD Buffer
y = 2;
if(LCD_CurMenu.Line>=(6)){
LCD_CurMenu.Line=0;
}
if (LCD_CurMenu.Line < 4)
{
LCD_EnglishDisplay1206(0, y, 1); // "1"
LCD_EnglishDisplay1206(0, y + 6, 64); // "."
LCD_ChineseDisplay1616(0, y + 12, 86); // "总"
LCD_ChineseDisplay1616(0, y + 25, 87); // "开"
LCD_ChineseDisplay1616(0, y + 38, 90); // "百"
LCD_ChineseDisplay1616(0, y + 51, 91); // "分"
LCD_ChineseDisplay1616(0, y + 64, 92); // "比"
LCD_EnglishDisplay1206(0, y + 77, 67); // ":"
show_value1(0,y + 77+6,canshuos_1.zongkai_tiaoguang_value,0);
LCD_EnglishDisplay1206(2, y, 2); // "2"
LCD_EnglishDisplay1206(2, y + 6, 64); // "."
LCD_ChineseDisplay1616(2, y + 12, 86); // "总"
LCD_ChineseDisplay1616(2, y + 25, 89); // "关"
LCD_ChineseDisplay1616(2, y + 38, 90); // "百"
LCD_ChineseDisplay1616(2, y + 51, 91); // "分"
LCD_ChineseDisplay1616(2, y + 64, 92); // "比"
LCD_EnglishDisplay1206(2, y + 77, 67); // ":"
show_value1(2,y + 77+6,canshuos_1.zongguan_tiaoguang_value,1);
LCD_EnglishDisplay1206(4, y, 3); // "3"
LCD_EnglishDisplay1206(4, y + 6, 64); // "."
LCD_ChineseDisplay1616(4, y + 12, 93); // "消"
LCD_ChineseDisplay1616(4, y + 25, 94); // "防"
LCD_ChineseDisplay1616(4, y + 38, 95); // "强"
LCD_ChineseDisplay1616(4, y + 51, 96); // "启"
// LCD_ChineseDisplay1616(4, y + 64, 92); // "比"
LCD_EnglishDisplay1206(4, y + 77, 67); // ":"
show_value1(4,y + 77+6,canshuos_1.xiaofan_qiangqi_tiaoguang_value,2);
LCD_EnglishDisplay1206(6, y, 4); // "4"
LCD_EnglishDisplay1206(6, y + 6, 64); // "."
LCD_ChineseDisplay1616(6, y + 12, 100); // "渐"
LCD_ChineseDisplay1616(6, y + 25, 101); // "变"
LCD_ChineseDisplay1616(6, y + 38, 102); // "延"
LCD_ChineseDisplay1616(6, y + 51, 103); // "时"
// LCD_ChineseDisplay1616(6, y + 64, 92); // "比"
LCD_EnglishDisplay1206(6, y + 77, 67); // ":"
show_value1(6,y + 77+6,canshuos_1.jianbian_times,3);
}else{
LCD_EnglishDisplay1206(0, y, 5); // "5"
LCD_EnglishDisplay1206(0, y + 6, 64); // "."
LCD_ChineseDisplay1616(0, y + 12, 104); // "吸"
LCD_ChineseDisplay1616(0, y + 25, 105); // "合"
LCD_ChineseDisplay1616(0, y + 38, 90); // "百"
LCD_ChineseDisplay1616(0, y + 51, 91); // "分"
LCD_ChineseDisplay1616(0, y + 64, 92); // "比"
LCD_EnglishDisplay1206(0, y + 77, 67); // ":"
show_value1(0,y + 77+6,canshuos_1.beihe_start_tiaoguang_value,4);
LCD_EnglishDisplay1206(2, y, 6); // "6"
LCD_EnglishDisplay1206(2, y + 6, 64); // "."
LCD_ChineseDisplay1616(2, y + 12, 106); // "断"
LCD_ChineseDisplay1616(2, y + 25, 107); // "开"
LCD_ChineseDisplay1616(2, y + 38, 90); // "百"
LCD_ChineseDisplay1616(2, y + 51, 91); // "分"
LCD_ChineseDisplay1616(2, y + 64, 92); // "比"
LCD_EnglishDisplay1206(2, y + 77, 67); // ":"
show_value1(2,y + 77+6,canshuos_1.duankai_start_tiaoguang_value,5);
}
LCD_UpdateScreen();
}
#define max_menu_index1 5
void V2_1_KEY_Add_tiao_guang_Set_Menu(){
if(V2_1_the_menu_deepth==0){
if(LCD_CurMenu.Line<=(max_menu_index1-1)){
LCD_CurMenu.Line++;
}else{
LCD_CurMenu.Line=0;
}
}
if(V2_1_the_menu_deepth==1){
if(LCD_CurMenu.Line==0){//总开百分比
if(canshuos_1.zongkai_tiaoguang_value<=99){
canshuos_1.zongkai_tiaoguang_value++;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==1){//总关百分比
if(canshuos_1.zongguan_tiaoguang_value<=99){
canshuos_1.zongguan_tiaoguang_value++;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==2){//消防强启
if(canshuos_1.xiaofan_qiangqi_tiaoguang_value<=99){
canshuos_1.xiaofan_qiangqi_tiaoguang_value++;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==3){//渐变
if(canshuos_1.jianbian_times<=14){
canshuos_1.jianbian_times++;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==4){//吸合百分比
if(canshuos_1.beihe_start_tiaoguang_value<=49){
canshuos_1.beihe_start_tiaoguang_value++;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==5){//断开百分比
if(canshuos_1.duankai_start_tiaoguang_value<=49){
canshuos_1.duankai_start_tiaoguang_value++;
}
}
//-------------------------------------------------------------------------------
}
}
void V2_1_KEY_Sub_tiao_guang_Set_Menu(){
if(V2_1_the_menu_deepth==0){
if(LCD_CurMenu.Line>=1){
LCD_CurMenu.Line--;
}else{
LCD_CurMenu.Line=max_menu_index1;
}
}
if(V2_1_the_menu_deepth==1){
if(LCD_CurMenu.Line==0){//总开百分比
if(canshuos_1.zongkai_tiaoguang_value>=1){
canshuos_1.zongkai_tiaoguang_value--;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==1){//总关百分比
if(canshuos_1.zongguan_tiaoguang_value>=1){
canshuos_1.zongguan_tiaoguang_value--;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==2){//消防强启
if(canshuos_1.xiaofan_qiangqi_tiaoguang_value>=1){
canshuos_1.xiaofan_qiangqi_tiaoguang_value--;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==3){//渐变
if(canshuos_1.jianbian_times>=1){
canshuos_1.jianbian_times--;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==4){//吸合百分比
if(canshuos_1.beihe_start_tiaoguang_value>=1){
canshuos_1.beihe_start_tiaoguang_value--;
}
}
//-------------------------------------------------------------------------------
if(LCD_CurMenu.Line==5){//断开百分比
if(canshuos_1.duankai_start_tiaoguang_value>=2){
canshuos_1.duankai_start_tiaoguang_value--;
}
}
//-------------------------------------------------------------------------------
}
}
void V2_1_KEY_Enter_tiao_guang_Set_Menu(){
if(V2_1_the_menu_deepth==0){
V2_1_the_menu_deepth=1;
}else{
if(LCD_CurMenu.Line==0){//总开百分比
save_buf_tmp[0]=canshuos_1.zongkai_tiaoguang_value;
V2_1_AT24CXX_PageWrite(V2_1_EEP_zongkai_tiaoguang_value ,save_buf_tmp, 1);
}
if(LCD_CurMenu.Line==1){
save_buf_tmp[0]=canshuos_1.zongguan_tiaoguang_value;
V2_1_AT24CXX_PageWrite(V2_1_EEP_zongguan_tiaoguang_value ,save_buf_tmp, 1);
}
if(LCD_CurMenu.Line==2){//消防强启
save_buf_tmp[0]=canshuos_1.xiaofan_qiangqi_tiaoguang_value;
V2_1_AT24CXX_PageWrite(V2_1_EEP_xiaofan_qiangqi_tiaoguang_value ,save_buf_tmp, 1);
}
if(LCD_CurMenu.Line==3){//渐变时间
save_buf_tmp[0]=canshuos_1.jianbian_times;
V2_1_AT24CXX_PageWrite(V2_1_EEP_jianbian_times ,save_buf_tmp, 1);
}
if(LCD_CurMenu.Line==4){
save_buf_tmp[0]=canshuos_1.beihe_start_tiaoguang_value;
V2_1_AT24CXX_PageWrite(V2_1_EEP_beihe_start_tiaoguang_value ,save_buf_tmp, 1);
}
if(LCD_CurMenu.Line==5){
save_buf_tmp[0]=canshuos_1.duankai_start_tiaoguang_value;
V2_1_AT24CXX_PageWrite(V2_1_EEP_duankai_start_tiaoguang_value ,save_buf_tmp, 1);
}
V2_1_the_menu_deepth=0;
}
}
void V2_1_KEY_Return_tiao_guang_Set_Menu(){
if(V2_1_the_menu_deepth==0){
LCD_CurMenu.Menu = LCD_FUNCTION_SELECT_SET;
LCD_CurMenu.Line = 6;
LCD_CurMenu.LineNumber = NUM_FUNCTION_SELECT_SET ;
}
if(V2_1_the_menu_deepth==1){
V2_1_reload_tiaoguang_canshuo_data();
V2_1_the_menu_deepth=0;
}
}