打印
[Kinetis]

【FRDM-KL02】+读数360旋转编码器

[复制链接]
928|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
史迪威将军|  楼主 | 2015-12-27 20:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
史迪威将军|  楼主 | 2015-12-27 20:12 | 只看该作者


           编码器          FRDM-kl02

使用特权

评论回复
板凳
史迪威将军|  楼主 | 2015-12-27 20:13 | 只看该作者
CLK-----PTA12
                 DT-------PTB5
                SW-------暂时没接
                 + ---------+5
                GND---------GND




使用特权

评论回复
地板
史迪威将军|  楼主 | 2015-12-27 20:14 | 只看该作者
#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;

使用特权

评论回复
5
史迪威将军|  楼主 | 2015-12-27 20:14 | 只看该作者
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);
}

使用特权

评论回复
6
史迪威将军|  楼主 | 2015-12-27 20:15 | 只看该作者
    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--;
    }

使用特权

评论回复
7
史迪威将军|  楼主 | 2015-12-27 20:16 | 只看该作者





















使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

34

主题

291

帖子

0

粉丝