標(biāo)題: STM32單片機(jī)撥碼開(kāi)關(guān)值獲取程序 [打印本頁(yè)]

作者: sr861126    時(shí)間: 2022-7-18 14:47
標(biāo)題: STM32單片機(jī)撥碼開(kāi)關(guān)值獲取程序
#include "stm32f10x.h"
u8 ReadValue;
void Delay(u32 count)
{
   u32 i=0;
   for(;i<count;i++);
}


//void delay_ms(u16 time)
//{   
//   u16 i=0;  
//   while(time--)
//   {
//      i=12000;  //自己定義
//      while(i--) ;   
//   }
//}
void LED_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);         //使能PB,PE端口時(shí)鐘
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;                                 //LED0-->PB.5 端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                  //推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                 //IO口速度為50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure);                                         //根據(jù)設(shè)定參數(shù)初始化GPIOB.5
GPIO_SetBits(GPIOC,GPIO_Pin_13);               
        
        }

void GPIO_config(void)
{
   GPIO_InitTypeDef GPIO_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC , ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); /*使能SWD 禁用JTAG*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
        
        }


int main(void)
{        

         GPIO_config();                 //PE.5 輸出高           
   LED_config();

         while(1)
        {
                 ReadValue = GPIO_ReadInputData(GPIOB);//獲取值
     ReadValue=        ReadValue&0x1f;
          switch(ReadValue)
                {
                  case 0x01: GPIO_SetBits(GPIOC,GPIO_Pin_13);        break;        
                  case 0x03: GPIO_ResetBits(GPIOC,GPIO_Pin_13);break;               
               
                }
                        
        
        }
}






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