1024手机基地看电影,午夜福利视频导航,国产精品福利在线一区,亚洲欧美日韩另类成人,在线观看午夜日本理论片,成年超爽免费网站,国产精品成人免费,精品动作一级毛片,成人免费观看网站,97精品伊人久久大香蕉

標(biāo)題: 基于stm32 編碼器應(yīng)用 [打印本頁]

作者: 前行者    時(shí)間: 2018-5-27 12:15
標(biāo)題: 基于stm32 編碼器應(yīng)用
  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ù)制代碼







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