欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1904|回復(fù): 0
收起左側(cè)

基于stm32 編碼器應(yīng)用

[復(fù)制鏈接]
ID:305089 發(fā)表于 2018-5-27 12:15 | 顯示全部樓層 |閱讀模式
  1. void Encoder1_Init(void)
  2. {
  3.         GPIO_InitTypeDef GPIO_Initure;
  4.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  5.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
  6.        
  7.         GPIO_Initure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  8.         GPIO_Initure.GPIO_Mode = GPIO_Mode_IPU;
  9.         GPIO_Initure.GPIO_Speed = GPIO_Speed_50MHz;
  10.         GPIO_Init(GPIOA, &GPIO_Initure);
  11.        
  12.         TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI2, TIM_ICPolarity_Falling, TIM_ICPolarity_Falling);
  13.        
  14.         TIM3->CNT = 1500;
  15.         //TIM3->CNT = 0;
  16.         TIM_Cmd(TIM3, ENABLE);
  17. }

  18. //讀取編碼器的值
  19. int Encoder1_read(void)
  20. {
  21.         int count = 0;
  22.        
  23.         count = TIM3->CNT - 1500;
  24.   //count = TIM3->CNT;
  25.         //        TIM3->CNT = 0x7fff; //清零重新讀取

  26.         return count;
  27. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表