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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PC與單片機(jī)通訊(89c52 VB 控制LED)

          PC與單片機(jī)通訊(89c52 VB 控制LED)

          作者: 時(shí)間:2016-11-22 來源:網(wǎng)絡(luò) 收藏
          //單片機(jī)c代碼

          #include
          #include
          #define INBUF_LEN 4 //數(shù)據(jù)長(zhǎng)度
          unsigned char inbuf1[INBUF_LEN];
          unsigned char checksum,count3;
          bit read_flag= 0 ;
          sbit p1=P1^0;
          sbit p2=P1^1;
          sbit p3=P1^2;
          sbit p4=P1^3;
          sbit p5=P1^4;
          sbit p6=P1^5;
          sbit p7=P1^6;
          sbit p8=P1^7;
          void init_serialcomm( void )
          {
          SCON = 0x50 ; //SCON: serail mode 1, 8-bit UART, enable ucvr
          TMOD |= 0x20 ; //TMOD: timer 1, mode 2, 8-bit reload
          PCON |= 0x80 ; //SMOD=1;
          TH1 = 0xF4 ; //Baud:4800 fosc=11.0592MHz
          IE |= 0x90 ; //Enable Serial Interrupt
          TR1 = 1 ; // timer 1 run
          // TI=1;
          }

          本文引用地址:http://www.ex-cimer.com/article/201611/319687.htm

          //串口接收中斷函數(shù)
          void serial () interrupt 4 using 3
          {
          if (RI)
          {
          unsigned char ch;
          RI = 0 ;
          ch=SBUF;
          if (ch==1 )
          {
          //if (P1==0xff)
          //P1=0x0e;
          //else
          //P1=0xff;
          p1=0;
          }
          if (ch==2 )
          {
          p2=0;
          }
          if (ch==3 )
          {
          p3=0;
          }
          if (ch==4 )
          {
          p4=0;
          }
          if (ch==5 )
          {
          p5=0;
          }
          if (ch==6 )
          {
          p6=0;
          }
          if (ch==7 )
          {
          p7=0;
          }
          if (ch==8 )
          {
          p8=0;
          }
          if (ch==11 )
          {
          p1=1;
          }
          if (ch==12 )
          {
          p2=1;
          }
          if (ch==13 )
          {
          p3=1;
          }
          if (ch==14 )
          {
          p4=1;
          }
          if (ch==15 )
          {
          p5=1;
          }
          if (ch==16 )
          {
          p6=1;
          }
          if (ch==17 )
          {
          p7=1;
          }
          if (ch==18 )
          {
          p8=1;
          }

          }
          }
          main()
          {
          init_serialcomm(); //初始化串口
          while ( 1 )
          {
          if (read_flag) //如果取數(shù)標(biāo)志已置位,就將讀到的數(shù)從串口發(fā)出
          {
          read_flag= 0 ; //取數(shù)標(biāo)志清0
          }
          }
          }

          上位機(jī)(VB)代碼

          添加command數(shù)組1,2,各8個(gè),command1(i),command2(i)

          添加MSComm控件

          Private Sub Command1_Click(Index As Integer)
          MSComm1.Output = Chr(Index + 1)
          End Sub

          Private Sub Command2_Click(Index As Integer)
          MSComm1.Output = Chr(Index + 11)
          End Sub

          Private Sub Form_Load()
          For i = 0 To 7
          Command1(i).Caption = "ON_LED_" & Str(i + 1)
          Command2(i).Caption = "OFF_LED_" & Str(i + 1)
          Next i
          Me.BorderStyle = 4
          Me.Caption = "LED控制"
          MSComm1.CommPort = 4 端口號(hào)根據(jù)自己電腦設(shè)置
          MSComm1.Settings = "4800,n,8,1"
          MSComm1.PortOpen = True 打開通信口
          End Sub




          評(píng)論


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

          關(guān)閉
          看屁屁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); })();