- #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;//編碼器計數(shù)
- int main(void)
- {
-
- delay_init(); //延時函數(shù)初始化
- uart_init(115200); //串口初始化為115200
- EXTI_PA1_Config();//編碼器Z相歸零信號外部中斷口初始化
- TIM6_Int_Init(49999,7199);//10Khz的計數(shù)頻率,計數(shù)到49999為500ms
- TIM4_Init();//定時器編碼器接口初始化
- LED_Init(); //LED端口初始化
- KEY_Init(); //初始化與按鍵連接的硬件接口
- while(1)
- {
- count = TIM4->CNT/4;//獲取計數(shù)值
- delay_ms(100);//每隔1s打印一次編碼器角度,用手去撥動編碼器 使其慢速旋轉(zhuǎn)
- 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, 下載次數(shù): 92)
2017-8-4 01:08 上傳
點擊文件名下載附件
編碼器測位置
|