一、如何启用按键的中断方式?
按键的中断方式比轮询方式更合理高效,我查看了pin_manager.h中对引脚的宏定义,发现可以通过代码来定义中断,但不知道中断处理函数是哪个、在哪个位置?
这是我写的配置代码,不知道正确否:
- int main(void)
- {
- /* Initializes MCU, drivers and middleware */
- SYSTEM_Initialize();
-
- /* 开启按键中断 */
- IO_PF6_SetDigitalInput(); //设置数字输入方式
- IO_PF6_EnableInterruptForLowLevelSensing();//启用低电平感应中断
-
- /* Replace with your application code */
- while (1){
- if(IO_PF6_GetValue()==0){
- DELAY_milliseconds(50);
- if(IO_PF6_GetValue()==0){
- if(direction==1){
- delays = delays << 1;
- if(delays > 1000){
- direction = 0;
- delays = 800;
- }
- }
- else{
- delays = delays >> 1;
- if(delays < 100){
- direction = 1;
- delays = 100;
- }
- }
- }
- }
- IO_PF5_Toggle();
- DELAY_milliseconds(delays);
- }
- }
二、如何启用定时器
我想启用定时器的功能来控制LED的闪烁,免得使用低效的延时程序,但不清楚如何配置和启用定时器,在数据手册里也没有找到有关定时器的部分,在此请教大家该如何配置和启用定时器。
|