找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3883|回復: 1
收起左側(cè)

stm32編碼器測位置 源程序

[復制鏈接]
ID:224512 發(fā)表于 2017-8-3 20:25 | 顯示全部樓層 |閱讀模式
0.png
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "usart.h"
  6. #include "exti.h"
  7. #include "encode.h"
  8. #include "timer.h"
  9. extern double w;
  10. extern int x,y,buff,num;
  11. u16 count;//編碼器計數(shù)
  12. int main(void)
  13. {               
  14.        

  15.         delay_init();                     //延時函數(shù)初始化          
  16.         uart_init(115200);         //串口初始化為115200
  17.         EXTI_PA1_Config();//編碼器Z相歸零信號外部中斷口初始化
  18.         TIM6_Int_Init(49999,7199);//10Khz的計數(shù)頻率,計數(shù)到49999為500ms
  19.         TIM4_Init();//定時器編碼器接口初始化
  20.         LED_Init();                             //LED端口初始化
  21.         KEY_Init();          //初始化與按鍵連接的硬件接口
  22.         while(1)
  23.         {
  24.                 count = TIM4->CNT/4;//獲取計數(shù)值
  25.                 delay_ms(100);//每隔1s打印一次編碼器角度,用手去撥動編碼器  使其慢速旋轉(zhuǎn)
  26.                 printf("count = %d\n    ",count);
  27. //                printf("num = %d\n   ",num);
  28. //                printf("x = %d\n   ",x);
  29. //                printf("y = %d\n   ",y);
  30. //                printf("w = %lf\n   ",w);
  31.         }         
  32. }

復制代碼


編碼器測位置.rar (288.87 KB, 下載次數(shù): 92)

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

ID:756378 發(fā)表于 2023-9-8 18:42 | 顯示全部樓層
這個怎么接線?
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表