本帖最后由 cooldog123pp 于 2021-11-6 22:08 编辑
板卡初次试用,先体验一下按键,串口,以及LED,这里移植了Mul
tiButton,即按下按键2,LED1循环闪烁,并答应,依次按键3,按键4,按键5.
LED分别是PF0,PF1,PF2,PF3
KEY对应的是PA0,PC13,PF5,PF4
UART对应的是PA9和PA10
在引出来的管脚上接上USB转TTL,并且接到电脑上去,如图
移植MultiButton,其他外设用
开发板给的demo代码即可
在systick的中断函数中加入button的tick
- void SysTick_Handler(void)
- {
- static uint8_t ButtonCnt;
- ButtonCnt++;
- delay_decrement();
- if(ButtonCnt == 5)
- {
- button_ticks();
- ButtonCnt = 0;
- }
- }
创建button,并在主函数里面循环查询,按下按键LED闪烁并且打印
- int main(void)
- {
- static uint8_t btn2_event_val;
- static uint8_t btn3_event_val;
- static uint8_t btn4_event_val;
- static uint8_t btn5_event_val;
- led_init();
- uart0_init ();
- key_init ();
- systick_config();
- button_init(&btn2, read_button2_GPIO, 0);
- button_init(&btn3, read_button3_GPIO, 0);
- button_init(&btn4, read_button4_GPIO, 0);
- button_init(&btn5, read_button5_GPIO, 0);
- button_start(&btn2);
- button_start(&btn3);
- button_start(&btn4);
- button_start(&btn5);
-
- printf("rn while() start! rn");
-
- while(1){
- if(btn2_event_val != get_button_event(&btn2)) {btn2_event_val = get_button_event(&btn2);}
- if(btn3_event_val != get_button_event(&btn3)) {btn3_event_val = get_button_event(&btn3);}
- if(btn4_event_val != get_button_event(&btn4)) {btn4_event_val = get_button_event(&btn4);}
- if(btn5_event_val != get_button_event(&btn5)) {btn5_event_val = get_button_event(&btn5);}
-
-
- if(btn2_event_val == PRESS_DOWN) {
- /* turn on LED1 */
- led_on(0);
- /* insert 200 ms delay */
- delay_1ms(200);
- /* turn on LED2 */
- led_off(0);
- /* insert 200 ms delay */
- delay_1ms(200);
- printf("rn Key2 PressDown! rn");
- }
- if(btn3_event_val == PRESS_DOWN) {
- /* turn on LED1 */
- led_on(1);
- /* insert 200 ms delay */
- delay_1ms(200);
- /* turn on LED2 */
- led_off(1);
- /* insert 200 ms delay */
- delay_1ms(200);
- printf("rn Key3 PressDown! rn");
- }
- if(btn4_event_val == PRESS_DOWN) {
- /* turn on LED1 */
- led_on(2);
- /* insert 200 ms delay */
- delay_1ms(200);
- /* turn on LED2 */
- led_off(2);
- /* insert 200 ms delay */
- delay_1ms(200);
- printf("rn Key4 PressDown! rn");
- }
- if(btn5_event_val == PRESS_DOWN) {
- /* turn on LED1 */
- led_on(3);
- /* insert 200 ms delay */
- delay_1ms(200);
- /* turn on LED2 */
- led_off(3);
- /* insert 200 ms delay */
- delay_1ms(200);
- printf("rn Key5 PressDown! rn");
- }
- }
- }
代码:
往期试用:
【星空派GD32F303开发板试用体验】+板卡概览