11
Dependencies: mbed N5110 Joystick
main.cpp@1:77e6588be25b, 2021-04-09 (annotated)
- Committer:
- lhyr
- Date:
- Fri Apr 09 07:00:20 2021 +0000
- Revision:
- 1:77e6588be25b
- Parent:
- 0:283702b9a078
- Child:
- 2:4fd751cc1af7
111
Who changed what in which revision?
User | Revision | Line number | New 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 | |
lhyr | 0:283702b9a078 | 41 | |
lhyr | 0:283702b9a078 | 42 | //select(volatile int button_a_flag,volatile int button_d_flag,volatile int button_b_flag); |
lhyr | 0:283702b9a078 | 43 | while(1) { |
lhyr | 0:283702b9a078 | 44 | lcd_init(); |
lhyr | 0:283702b9a078 | 45 | lcd_clear(); |
lhyr | 0:283702b9a078 | 46 | print_menu(); |
lhyr | 0:283702b9a078 | 47 | lcd_refresh(); |
lhyr | 0:283702b9a078 | 48 | if (button_c_flag) { |
lhyr | 0:283702b9a078 | 49 | button_c_flag = 0; |
lhyr | 0:283702b9a078 | 50 | led1 = !led1; |
lhyr | 1:77e6588be25b | 51 | select11(button_a_flag,button_d_flag,button_b_flag); |
lhyr | 0:283702b9a078 | 52 | } |
lhyr | 0:283702b9a078 | 53 | |
lhyr | 0:283702b9a078 | 54 | } |
lhyr | 0:283702b9a078 | 55 | |
lhyr | 0:283702b9a078 | 56 | } |
lhyr | 0:283702b9a078 | 57 | |
lhyr | 1:77e6588be25b | 58 | void buttonA_isr(*button_a_flag) |
lhyr | 0:283702b9a078 | 59 | { |
lhyr | 0:283702b9a078 | 60 | button_a_flag = 1; // set flag in ISR |
lhyr | 0:283702b9a078 | 61 | } |
lhyr | 0:283702b9a078 | 62 | void buttonB_isr() |
lhyr | 0:283702b9a078 | 63 | { |
lhyr | 0:283702b9a078 | 64 | button_b_flag = 1; // set flag in ISR |
lhyr | 1:77e6588be25b | 65 | |
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 |