在线时间828 小时
UID3079326
注册时间2015-2-11
NXP金币29
TA的每日心情 | 奋斗 2025-5-7 09:07 |
---|
签到天数: 353 天 连续签到: 1 天 [LV.8]以坛为家I
金牌会员
 
- 积分
- 5786
- 最后登录
- 2025-5-7
|
https://www.nxpic.org.cn/module/forum/forum.php?mod=viewthread&tid=602524&page=1#pid2166100
上个帖子测试了GPIO I/O中断的检测。
硬件准备;1. 360度旋转编码器
2. FRDM-KL02
3.连接线几根
编码器 FRDM-kl02
CLK-----PTA12
DT-------PTB5
SW-------暂时没接
+ ---------+5
GND---------GND
- #include <stdio.h>
- #include <string.h>
- #include "gpio.h"
- #include "common.h"
- #include "uart.h"
- #define KEY3_PORT HW_GPIOA
- #define KEY3_PIN 12
- #define KEY1_PORT HW_GPIOB
- #define KEY1_PIN 5
- extern long int num;
- int main(void)
- {
- DelayInit();
- GPIO_QuickInit(KEY1_PORT, KEY1_PIN, kGPIO_Mode_IPU);
- GPIO_QuickInit(KEY3_PORT, KEY3_PIN, kGPIO_Mode_IPU);
- UART_QuickInit(UART0_RX_B2_TX_B1, 9600);
- printf("360旋转编码器 demo!\r\n");
- GPIO_ITDMAConfig(KEY3_PORT, 12, kGPIO_IT_RisingFallingEdge, true);
- while(1)
- {
- printf("%ld \r\n",num);
- }
复制代码- void PORTA_IRQHandler(void)
- {
- if(PORTA_ISFR == (1<<12));
- {
- PORTA_PCR12 |= PORT_PCR_ISF_MASK;
- if( GPIO_ReadBit(HW_GPIOA, 12)==0)
- { if( GPIO_ReadBit(HW_GPIOB, 5)==0)
- num++;
- }
- else
- {
- if( GPIO_ReadBit(HW_GPIOB, 5)==0)
- num--;
- }
复制代码
|
评分
-
查看全部评分
|