這個是F407ZGT6編碼器的程序,整了好長時間終于能用了,來分享一下
單片機源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- int main(void)
- {
- delay_init(84);
- u16 count,count_hc;//編碼器計數
- uart_init(115200); //串口初始化為115200
- TIM4_Init();//定時器編碼器接口初始化
- while(1)
- {
- count_hc=count;
- count=TIM_GetCounter( TIM4 ); //當前位置
- if(count!=count_hc)
- {
- printf("DIR= %d \r\n",( TIM4 ->CR1>>4 & 0x01 ) );
- printf("count = %d\r\n",count);
- }
-
- }
- }
復制代碼
所有資料51hei提供下載:
編碼器.7z
(295.03 KB, 下載次數: 81)
2019-10-20 16:14 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|