注册会员
- 积分
- 32
- 威望
- 20
- 贡献
- 10
- 兑换币
- 11
- 注册时间
- 2018-11-15
- 在线时间
- 1 小时
|
- #ifndef __MENU_H
- #define __MENU_H
- #include "common.h"
- #include "MK60_flash.h"
- #define SECTOR_NUM (FLASH_SECTOR_NUM-1)
- extern uint8 func_index;
- extern int pid,speed,angle;
- //extern void(*current_operation_index)();
- extern uint8 mybit(int m);
- uint8 mybit(int m);
- void fun0();
- void fun1();
- void fun2();
- void fun3();
- void fun4();
- void fun5();
- void fun6();
- void fun7();
- void fun8();
- void fun9();
- void fun10();
- void fun11();
- void fun12();
- void menu();
- #endif
复制代码
- #include "menu.h"
- #include "include.h"
- int pid,speed,angle;
- uint8 func_index=0;
- void (*current_operation_index)();
- void (*current_operation)();
- typedef struct
- {
- uint8_t current;
- uint8_t up;
- uint8_t down;
- uint8_t enter;
- void (*current_operation)();
- }key_table;
- key_table table[]=
- {
- {0,1,1,1,(*fun0)},
- {1,0,2,4,(*fun1)},
- {2,1,3,5,(*fun2)},
- {3,2,1,6,(*fun3)},
- {4,7,8,1,(*fun4)},
- {5,9,10,2,(*fun5)},
- {6,11,12,3,(*fun6)},
- {7,7,8,1,(*fun7)},
- {8,7,8,1,(*fun8)},
- {9,9,10,2,(*fun9)},
- {10,9,10,2,(*fun10)},
- {11,11,12,3,(*fun11)},
- {12,11,12,3,(*fun12)},
- };
- ......
- void fun12()
- {
- angle-=1;
- OLED_ShowString(80,0," pid",12);
- OLED_ShowString(80,12," speed",12);
- OLED_ShowString(80,24,"*angle",12);
- OLED_Showint(110,0,pid,mybit(pid),12);
- OLED_Showint(110,12,speed,mybit(speed),12);
- OLED_Showint(110,24,angle,mybit(angle),12);
- OLED_Refresh_Gram();
- }
- void menu()
- {
- if(key_check(KEY_2)==KEY_DOWN)
- {
- func_index=table[func_index].up;
- OLED_Clear();
- current_operation_index=table[func_index].current_operation;
- (*current_operation_index)();
-
- while(key_check(KEY_2)==KEY_DOWN)
- {
- DELAY_MS(20);
- }
- }
- if(key_check(KEY_8)==KEY_DOWN)
- {
- func_index=table[func_index].down;
- OLED_Clear();
- current_operation_index=table[func_index].current_operation;
- (*current_operation_index)();
-
- while(key_check(KEY_8)==KEY_DOWN)
- {
- DELAY_MS(20);
- }
- }
- if(key_check(KEY_4)==KEY_DOWN)
- {
- func_index=table[func_index].enter;
- OLED_Clear();
- current_operation_index=table[func_index].current_operation;
- (*current_operation_index)();
-
- while(key_check(KEY_4)==KEY_DOWN)
- {
- DELAY_MS(20);
- }
- }
- if(key_check(KEY_0)==KEY_DOWN)
- {
- flash_erase_sector(SECTOR_NUM);
- if( 1 == flash_write(SECTOR_NUM, 0, pid) )
- {
- pid = flash_read(SECTOR_NUM,0,int);
- };
- if( 1 == flash_write(SECTOR_NUM, 8, speed) )
- {
- speed = flash_read(SECTOR_NUM,8,int);
- };
- if( 1 == flash_write(SECTOR_NUM, 16, angle) )
- {
- angle = flash_read(SECTOR_NUM,16,int);
- };
- OLED_ShowString(80,52,"saved",12);
- OLED_Refresh_Gram();
- while(key_check(KEY_0)==KEY_DOWN)
- {
- DELAY_MS(20);
- }
-
- }
-
- }
复制代码
这是我从主函数源文件里出来写的menu.h和menu.c文件,当时什么都不懂,全局变量报错,反正各种报错......至少现在不报错了。。 |
|