新聞中心

        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--);
        }


        評論


        技術專區

        關閉
        主站蜘蛛池模板: 永登县| 南康市| 定结县| 淮北市| 汤原县| 山阴县| 大关县| 长治县| 阳江市| 屏边| 团风县| 濮阳县| 广水市| 澄江县| 昌吉市| 麦盖提县| 黑山县| 阿城市| 利津县| 桐城市| 武强县| 仲巴县| 肥东县| 永和县| 新龙县| 永州市| 辉南县| 山东| 大方县| 阿拉善左旗| 徐州市| 安化县| 文水县| 济阳县| 马公市| 杭锦后旗| 洛阳市| 揭阳市| 红原县| 普格县| 林芝县|