- /*---------------------------------------------------------------------------------------------------------*/
- /* */
- /* SPDX-License-Identifier: Apache-2.0 */
- /* Copyright(c) 2020 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- //***********************************************************************************************************
- // File Function: ML51 GPIO toggle demo code
- //***********************************************************************************************************
- #include "ml51.h"
- //----------------------------------------------------------------------------------------------//
- void led_init(void)
- {
- //根据原理图,P0.3的LED低电平点亮,因此采用下面三种模式均可实现拉低到地的点亮
- // GPIO_SetMode(Port0,SET_BIT3,GPIO_MODE_PUSHPULL);
- // GPIO_SetMode(Port0,SET_BIT3,GPIO_MODE_OPENDRAIN);
- GPIO_SetMode(Port0,SET_BIT3,GPIO_MODE_QUASI);
- }
- void led_on(void)
- {
- P03=0;//根据原理图LED在P0.3引脚,为低电平点亮
- }
- void led_off(void)
- {
- P03=1;//根据原理图LED在P0.3引脚,为高电平点亮
- }
- void button_init(void)
- {
- //按钮假设采用开发板14引脚的P2.3引脚,则需要配置为输入模式,并使能内部上拉电阻。
- GPIO_SetMode(Port2,SET_BIT3,GPIO_MODE_INPUT);
- GPIO_Pull_Enable(Port2,SET_BIT3,PULLUP);
- }
- void main (void)
- {
- led_init();
- button_init();
- while(1)
- {
- if(P2&SET_BIT3)//如果没有按下按钮,则闪烁led
- {
- led_on();
- Timer2_Delay(24000000,4,200,1000);
- led_off();
- Timer2_Delay(24000000,4,200,1000);
- }
- else //否则按下按钮时候熄灭led
- {
- led_off();
- }
- }
- }
学习了一天,写的测试程序,非常奈斯。这个板子真不错。
|