新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 基于STM32的LED和KEY

        基于STM32的LED和KEY

        作者: 時間:2016-12-01 來源:網絡 收藏
        #include "stm32f10x.h"

        /***********************************************************************
        ************************************************************************/
        GPIO_InitTypeDef GPIO_InitStructure;

        本文引用地址:http://www.104case.com/article/201612/324393.htm

        /***********************************************************************
        ************************************************************************/
        void delay(vu32 nCount)
        {
        for(; nCount != 0; nCount--);
        }
        //

        u8 key(void)
        {
        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_13) == Bit_RESET ) //讀取指定端口引腳的輸入
        {
        return 1;
        }
        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15) == Bit_RESET ) //讀取指定端口引腳的輸入
        {
        return 2;
        }
        else
        return 0;
        }
        /***********************************************************************
        ************************************************************************/
        main()
        {
        u8 k=0;

        /* GPIOD Periph clock enable */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
        /* Configure PD.2 in output pushpull mode */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOD, &GPIO_InitStructure);


        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
        /* Configure PA.13 and PA15 in input pushpull mode */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
        GPIO_Init(GPIOA, &GPIO_InitStructure);


        while(1)
        {
        k=key();
        if(k == 1 )
        {
        GPIO_WriteBit(GPIOD,GPIO_Pin_2,Bit_RESET); //置位或清除所選定的特定位
        }
        if(k == 2)
        {
        GPIO_WriteBit(GPIOD,GPIO_Pin_2,Bit_SET); //置位或清除所選定的特定位
        }

        }
        }

        /*PA.13和PA.15端口控制PD.2的LED燈的亮和滅*********************************************
        *****************************************************************************/



        關鍵詞: STM32LEDKE

        評論


        技術專區(qū)

        關閉
        主站蜘蛛池模板: 通辽市| 张家口市| 九龙城区| 阳泉市| 射阳县| 醴陵市| 兰考县| 麻阳| 齐齐哈尔市| 特克斯县| 巴林左旗| 蓝山县| 胶州市| 荆州市| 禹城市| 自贡市| 南乐县| 中方县| 德化县| 哈巴河县| 永昌县| 渑池县| 汤原县| 尉犁县| 鱼台县| 承德县| 钟祥市| 抚顺市| 米脂县| 宝清县| 福泉市| 板桥市| 安义县| 璧山县| 三河市| 石楼县| 利辛县| 丹阳市| 垦利县| 休宁县| 诏安县|