11

Dependencies:   mbed N5110 Joystick

Committer:
lhyr
Date:
Fri Apr 09 06:34:15 2021 +0000
Revision:
0:283702b9a078
Child:
1:77e6588be25b
11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lhyr 0:283702b9a078 1 /********************************** include *********************************/
lhyr 0:283702b9a078 2 #include "mbed.h"
lhyr 0:283702b9a078 3 #include "start.h"
lhyr 0:283702b9a078 4 #include "lcd.h"
lhyr 0:283702b9a078 5
lhyr 0:283702b9a078 6
lhyr 0:283702b9a078 7 InterruptIn button_a(p29);
lhyr 0:283702b9a078 8 InterruptIn button_b(p28);
lhyr 0:283702b9a078 9 InterruptIn button_d(p26);
lhyr 0:283702b9a078 10 InterruptIn button_c(p27);
lhyr 0:283702b9a078 11 DigitalOut led(LED1);
lhyr 0:283702b9a078 12
lhyr 0:283702b9a078 13 Ticker flipper;
lhyr 0:283702b9a078 14 volatile int button_a_flag;
lhyr 0:283702b9a078 15 volatile int button_b_flag;
lhyr 0:283702b9a078 16 volatile int button_d_flag;
lhyr 0:283702b9a078 17 volatile int button_c_flag;
lhyr 0:283702b9a078 18 DigitalOut led1(LED1);
lhyr 0:283702b9a078 19
lhyr 0:283702b9a078 20 void buttonA_isr();
lhyr 0:283702b9a078 21 void buttonB_isr();
lhyr 0:283702b9a078 22 void buttonC_isr();
lhyr 0:283702b9a078 23 void buttonD_isr();
lhyr 0:283702b9a078 24
lhyr 0:283702b9a078 25 void rise_A();
lhyr 0:283702b9a078 26 void rise_B();
lhyr 0:283702b9a078 27 void rise_C();
lhyr 0:283702b9a078 28 void rise_D();
lhyr 0:283702b9a078 29
lhyr 0:283702b9a078 30 int main()
lhyr 0:283702b9a078 31 {
lhyr 0:283702b9a078 32 button_a_flag = 0;
lhyr 0:283702b9a078 33 button_b_flag = 0;
lhyr 0:283702b9a078 34 button_c_flag = 0;
lhyr 0:283702b9a078 35 button_d_flag = 0;
lhyr 0:283702b9a078 36 rise_A();
lhyr 0:283702b9a078 37 rise_B();
lhyr 0:283702b9a078 38 rise_C();
lhyr 0:283702b9a078 39 rise_D();
lhyr 0:283702b9a078 40 int p[1]= {button_b_flag};
lhyr 0:283702b9a078 41
lhyr 0:283702b9a078 42
lhyr 0:283702b9a078 43 //select(volatile int button_a_flag,volatile int button_d_flag,volatile int button_b_flag);
lhyr 0:283702b9a078 44 while(1) {
lhyr 0:283702b9a078 45 lcd_init();
lhyr 0:283702b9a078 46 lcd_clear();
lhyr 0:283702b9a078 47 print_menu();
lhyr 0:283702b9a078 48 lcd_refresh();
lhyr 0:283702b9a078 49 if (button_c_flag) {
lhyr 0:283702b9a078 50 button_c_flag = 0;
lhyr 0:283702b9a078 51 led1 = !led1;
lhyr 0:283702b9a078 52 select11(button_c_flag,button_d_flag,p);
lhyr 0:283702b9a078 53 }
lhyr 0:283702b9a078 54
lhyr 0:283702b9a078 55 }
lhyr 0:283702b9a078 56
lhyr 0:283702b9a078 57 }
lhyr 0:283702b9a078 58
lhyr 0:283702b9a078 59 void buttonA_isr()
lhyr 0:283702b9a078 60 {
lhyr 0:283702b9a078 61 button_a_flag = 1; // set flag in ISR
lhyr 0:283702b9a078 62 }
lhyr 0:283702b9a078 63 void buttonB_isr()
lhyr 0:283702b9a078 64 {
lhyr 0:283702b9a078 65 button_b_flag = 1; // set flag in ISR
lhyr 0:283702b9a078 66 }
lhyr 0:283702b9a078 67 void buttonC_isr()
lhyr 0:283702b9a078 68 {
lhyr 0:283702b9a078 69 button_c_flag = 1; // set flag in ISR
lhyr 0:283702b9a078 70 }
lhyr 0:283702b9a078 71 void buttonD_isr()
lhyr 0:283702b9a078 72 {
lhyr 0:283702b9a078 73 button_d_flag = 1; // set flag in ISR
lhyr 0:283702b9a078 74 }
lhyr 0:283702b9a078 75 void rise_A()
lhyr 0:283702b9a078 76 {
lhyr 0:283702b9a078 77 button_a.rise(&buttonA_isr);//检测上升沿
lhyr 0:283702b9a078 78 button_a.mode(PullNone);
lhyr 0:283702b9a078 79 }
lhyr 0:283702b9a078 80 void rise_B()
lhyr 0:283702b9a078 81 {
lhyr 0:283702b9a078 82 button_b.rise(&buttonB_isr);//检测上升沿
lhyr 0:283702b9a078 83 button_b.mode(PullNone);
lhyr 0:283702b9a078 84 }
lhyr 0:283702b9a078 85 void rise_C()
lhyr 0:283702b9a078 86 {
lhyr 0:283702b9a078 87 button_c.rise(&buttonC_isr);//检测上升沿
lhyr 0:283702b9a078 88 button_c.mode(PullNone);
lhyr 0:283702b9a078 89 }
lhyr 0:283702b9a078 90
lhyr 0:283702b9a078 91 void rise_D()
lhyr 0:283702b9a078 92 {
lhyr 0:283702b9a078 93 button_d.rise(&buttonD_isr);//检测上升沿
lhyr 0:283702b9a078 94 button_d.mode(PullNone);
lhyr 0:283702b9a078 95 }
lhyr 0:283702b9a078 96
lhyr 0:283702b9a078 97