標(biāo)題: 這個是STM32F407ZGT6編碼器的程序,整了好長時間終于能用了,來分享一下 [打印本頁]

作者: q1114785858    時間: 2019-10-20 13:42
標(biāo)題: 這個是STM32F407ZGT6編碼器的程序,整了好長時間終于能用了,來分享一下
這個是F407ZGT6編碼器的程序,整了好長時間終于能用了,來分享一下

單片機(jī)源程序如下:
  1. #include "sys.h"
  2. #include "delay.h"               
  3. #include "usart.h"
  4. #include "led.h"




  5. int main(void)
  6. {               
  7.         delay_init(84);
  8.         u16 count,count_hc;//編碼器計數(shù)
  9.         uart_init(115200);         //串口初始化為115200
  10.         TIM4_Init();//定時器編碼器接口初始化
  11.         while(1)
  12.         {
  13.                 count_hc=count;
  14.                 count=TIM_GetCounter( TIM4 );                                                        //當(dāng)前位置
  15.                 if(count!=count_hc)
  16.                 {
  17.                         printf("DIR= %d        \r\n",( TIM4 ->CR1>>4 & 0x01 ) );
  18.                         printf("count = %d\r\n",count);
  19.                 }
  20.                        
  21.         }         
  22. }
復(fù)制代碼

所有資料51hei提供下載:
編碼器.7z (295.03 KB, 下載次數(shù): 81)



作者: sevenpark    時間: 2020-3-25 19:53
printf輸出看不到值啊樓主




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1