新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > stm32 中斷串口控制LED燈

        stm32 中斷串口控制LED燈

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

        #include "usart.h"
        #include "led.h"
        #include

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

        /***********************************************************************
        ***********************************************************************/
        void RCC_Configuration(void);
        void GPIO_Configuration(void);
        void NVIC_Configuration(void);
        //void delay(vu32 nCount) //軟件延時
        // {
        // for(; nCount != 0; nCount--);
        // }
        /***********************************************************************
        ************************************************************************/

        main()
        {
        u8 a;

        RCC_Configuration();//系統時鐘配置

        NVIC_Configuration();//中斷配置

        GPIO_Configuration();//GPIO口配置

        LED_Init();

        while(1)
        {
        while(usart_rx_sta&0x80)
        {
        a=usart_rx_buf[1];
        if(a == 0x01)
        {
        GPIO_WriteBit(GPIOD,GPIO_Pin_2,Bit_SET);
        GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_RESET);
        // usart_rx_sta=0;
        // usart_rx_time=0;
        // usart_tx_buf[0]=0x01; //將接收到的串口數據,發送出
        // usart_tx_time=1;
        // USART1_SEND();
        printf("綠燈滅,紅燈亮");
        usart_rx_buf[1]=0x00;
        }
        if(a == 0x02)
        {
        GPIO_WriteBit(GPIOD,GPIO_Pin_2,Bit_RESET);
        GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_SET);
        // usart_rx_sta=0;
        // usart_rx_time=0;
        // usart_tx_buf[0]=0x02; //將接收到的串口數據,發送出
        // usart_tx_time=1;
        // USART1_SEND();
        printf("綠燈亮,紅燈滅");
        usart_rx_buf[1]=0x00;
        }
        else
        {
        usart_rx_sta=0;
        usart_rx_time=0;
        }
        }
        }
        }
        //發送AA 01 AB BB(注:串口助手發 使用16進制);綠燈滅,紅燈亮(注:串口助手收 不使用16進制)
        //發送AA 02 A8 BB(注:串口助手發 使用16進制);綠燈亮,紅燈滅(注:串口助手收 不使用16進制)
        /*****************************************************************************
        *****************************************************************************/

        注:使用的ALIENTEK開發板,參考正點原子部分子程序



        關鍵詞: stm32中斷串口LED

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 舞阳县| 瑞金市| 黄骅市| 建德市| 冷水江市| 抚州市| 论坛| 本溪市| 天峻县| 乐亭县| 巢湖市| 朔州市| 萝北县| 墨竹工卡县| 沂源县| 县级市| 保亭| 通榆县| 长子县| 曲阜市| 九寨沟县| 依安县| 牡丹江市| 庆元县| 旬阳县| 岳池县| 嘉鱼县| 菏泽市| 平谷区| 普宁市| 太谷县| 色达县| 云安县| 富蕴县| 九江市| 天柱县| 阿坝| 嘉定区| 宝山区| 南昌县| 临清市|