- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "exti.h"
- #include "encode.h"
- #include "timer.h"
- extern double w;
- extern int x,y,buff,num;
- u16 count;//编码器计数
- int main(void)
- {
-
- delay_init(); //延时函数初始化
- uart_init(115200); //串口初始化为115200
- EXTI_PA1_Config();//编码器Z相归零信号外部中断口初始化
- TIM6_Int_Init(49999,7199);//10Khz的计数频率,计数到49999为500ms
- TIM4_Init();//定时器编码器接口初始化
- LED_Init(); //LED端口初始化
- KEY_Init(); //初始化与按键连接的硬件接口
- while(1)
- {
- count = TIM4->CNT/4;//获取计数值
- delay_ms(100);//每隔1s打印一次编码器角度,用手去拨动编码器 使其慢速旋转
- printf("count = %d\n ",count);
- // printf("num = %d\n ",num);
- // printf("x = %d\n ",x);
- // printf("y = %d\n ",y);
- // printf("w = %lf\n ",w);
- }
- }
复制代码
编码器测位置.rar
(288.87 KB, 下载次数: 92)
|