日本a√视频在线,久久青青亚洲国产,亚洲一区欧美二区,免费g片在线观看网站

        <style id="k3y6c"><u id="k3y6c"></u></style>
        <s id="k3y6c"></s>
        <mark id="k3y6c"></mark>
          
          

          <mark id="k3y6c"></mark>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > AVR和51單片機(jī)串口通信簡(jiǎn)單實(shí)驗(yàn)

          AVR和51單片機(jī)串口通信簡(jiǎn)單實(shí)驗(yàn)

          作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
          //AVR作為發(fā)送機(jī),控制51的喇叭發(fā)聲和2極管發(fā)光
          //AVR發(fā)送方代碼 //采用2400波特率
          #include
          #include
          #define uchar unsigned char
          #define uint unsigned int
          #define k1 PIND_Bit4 //設(shè)置為喇叭
          #define k3 PIND_Bit6 //設(shè)置為發(fā)光管
          #define k4 PIND_Bit7 //發(fā)送控制命令
          #define UDRE 5
          #define RXC 7
          uchar dat=48;
          void delay(uint k)
          {
          uint i,j;
          for(i=0;ifor(j=0;j<1140;j++);
          }
          #include "1602.h"
          void port_init()
          {
          PORTA=0xff;
          DDRA=0xff;
          PORTB=0xff;
          DDRB=0xff;
          PORTC=0xff;
          DDRC=0xff;
          PORTD=0xff;
          DDRD=0x0f;
          }
          void serial_init()
          {
          UCSRB=0x00;
          UCSRA=0x02; //雙倍速
          UCSRC=0x06; //8位字符模式
          UBRRH=0x01; //2400波特率
          UBRRL=0xa0;
          UCSRB=0x18;
          }
          void send(uchar k) //串口發(fā)送函數(shù)
          {
          while(!(UCSRA&(1<UDR=k;

          }
          void key1()
          {
          static uint i,j;
          if(k1==0)
          {
          if(i==0)
          {
          j++;
          if(j>10)
          {
          if(k1==0)
          {
          i=1;j=0;
          dat=49;
          }
          }
          }
          }
          else
          {
          i=0;j=0;
          }
          }
          void key3()
          {
          static uint i,j;
          if(k3==0)
          {
          if(i==0)
          {
          j++;
          if(j>10)
          {
          if(k3==0)
          {
          i=1;j=0;
          dat=50;
          }
          }
          }
          }
          else
          {
          i=0;j=0;
          }
          }

          void main()
          {
          port_init();
          serial_init();
          init1602();
          delay(1000);
          while(1)
          {
          displayonechar(1,6,dat);
          if(k4==0)
          {
          send(dat);
          }
          key1(); //喇叭發(fā)聲
          key3(); //2極管發(fā)光
          }
          }
          //----------1602庫(kù)函數(shù)-----------
          #define RS PORTB_Bit0
          #define RW PORTB_Bit1
          #define EN PORTB_Bit2
          #define DATA PORTA
          #define busy 0x80

          void wait()
          {
          uchar val;
          DATA=0xff;
          RS=0;
          RW=1;
          __no_operation();
          __no_operation();
          EN=1;
          __no_operation();
          __no_operation();
          DDRA=0x00;
          val=PINA;
          while(val&busy)
          {
          val=PINA;
          }
          EN=0;
          DDRA=0xff;
          }

          void writecmd(uchar cmd)
          {
          wait();
          RS=0;
          RW=0;
          __no_operation();
          DATA=cmd;
          __no_operation();
          EN=1;
          __no_operation();
          __no_operation();
          EN=0;
          }
          上一頁 1 2 下一頁

          關(guān)鍵詞: AVR51單片機(jī)串口通

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉