<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > STM32串口通信和I/O口簡單代碼

          STM32串口通信和I/O口簡單代碼

          作者: 時間:2016-11-30 來源:網(wǎng)絡 收藏
          #include
          #include "sys.h"
          #include "delay.h"
          #include "usart.h"
          #include "led.h"



          int main(void)
          {
          u8 k; //點亮的燈位數(shù)
          u8 i;
          Stm32_Clock_Init(9); //系統(tǒng)時鐘初始化
          delay_init(72); //延時初始化
          uart_init(72,9600); //串口初始化
          led_init(); //燈I/O配置初始化
          while(1)
          {
          if(USART_RX_STA&0x80) //接受到數(shù)據(jù)判斷
          {
          printf("you send massage is :");
          for(i=0;i<(USART_RX_STA&0x3f);i++)
          {
          USART1->DR=USART_RX_BUF[i]; //把接受到的數(shù)據(jù)傳給電腦
          k=USART_RX_BUF[2]-0x30; //接受到要開發(fā)的燈泡值
          }
          USART_RX_STA=0; //接受位清零
          }
          if(k==1)LED1=0; //判斷點亮那個燈
          if(k==2)LED2=0;
          if(k==3)LED3=0;
          if(k==4)LED4=0;
          if(k==5)LED5=0;
          if(k==6)LED6=0;
          if(k==7)LED7=0;
          if(k==8)LED8=0;

          }
          }

          //-------------------------------------燈配置庫函數(shù)---------------

          #include
          #include "led.h"


          void led_init()
          {
          RCC->APB2ENR|=1<<3; //時能PORTB時鐘
          GPIOB->CRL&=0x00000000; //清空寄存器值
          GPIOB->CRL|=0x33333333; //推挽輸出
          GPIOB->ODR=0xffff;

          }


          #ifndef _led_h
          #define _led_h


          void led_init(void);
          #define LED1 PBout(0)
          #define LED2 PBout(1)
          #define LED3 PBout(2)
          #define LED4 PBout(3)
          #define LED5 PBout(4)
          #define LED6 PBout(5)
          #define LED7 PBout(6)
          #define LED8 PBout(7)

          #endif



          關鍵詞: STM32串口通信IO

          評論


          技術專區(qū)

          關閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();