久久ER99热精品一区二区-久久精品99国产精品日本-久久精品免费一区二区三区-久久综合九色综合欧美狠狠

新聞中心

EEPW首頁 > 嵌入式系統 > 設計應用 > 【STM32 Cotex-M3處理器系列編程】按鍵燈亮

【STM32 Cotex-M3處理器系列編程】按鍵燈亮

作者: 時間:2016-11-27 來源:網絡 收藏
//分別按下S1~S4,D1~D4分別點亮
#include "stm32f10x.h"
void Delay(unsigned int x);
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE);//IO口使能設置
GPIO_InitTypeDef GPIO_InitStructure; //定義結構體
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;//LED管腳
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_13; //LED管腳
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;//按鍵管腳
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //設置為上拉輸入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
while (1)
{
if(!(GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_5)))
GPIO_SetBits(GPIOC, GPIO_Pin_6);
else
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
if(!(GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_4)))
GPIO_SetBits(GPIOC, GPIO_Pin_7);
else
GPIO_ResetBits(GPIOC, GPIO_Pin_7);
if(!(GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_3)))
GPIO_SetBits(GPIOD, GPIO_Pin_13);
else
GPIO_ResetBits(GPIOD, GPIO_Pin_13);
if(!(GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_2)))
GPIO_SetBits(GPIOD, GPIO_Pin_6);
else
GPIO_ResetBits(GPIOD, GPIO_Pin_6);
}
}
void Delay(unsigned int x)
{
unsigned int t;
t=x;
while(t--);
}


評論


技術專區

關閉