标题: VB上位机控制单片机8位led灯亮灭 [打印本页]

作者: 瞧瞧泥    时间: 2017-5-17 15:47
标题: VB上位机控制单片机8位led灯亮灭
本例实现用VB上位机来控制51单片机8位led灯的亮和灭

单片机端的程序:
  1. #include<reg52.h>
  2. sbit LED1=P0^0;
  3. sbit LED2=P0^1;
  4. sbit LED3=P0^2;
  5. sbit LED4=P0^3;
  6. sbit LED5=P0^4;
  7. sbit LED6=P0^5;
  8. sbit LED7=P0^6;
  9. sbit LED8=P0^7;
  10. void Uartconfiguration();
  11. void main()
  12. {
  13. Uartconfiguration();
  14. while(1);

  15. }
  16. void ser() interrupt 4
  17. {
  18.   if(RI)
  19.         {
  20.          RI=0;
  21.          if(SBUF=='1')
  22.          LED1=~LED1;
  23.          else if(SBUF=='2')
  24.          {LED2=~LED2;}
  25.    else if(SBUF=='3')
  26.          {LED3=~LED3;}
  27.          else if(SBUF=='4')
  28.          {LED4=~LED4;}
  29.          else if(SBUF=='5')
  30.          LED5=~LED5;
  31.          else if(SBUF=='6')
  32.          LED6=~LED6;
  33.          else if(SBUF=='7')
  34.          LED7=~LED7;
  35.          else if(SBUF=='8')
  36.          LED8=~LED8;
  37.          }
  38.          else
  39.           TI=0;
  40. }
  41. void Uartconfiguration()
  42. {
  43.   TMOD=0x20;
  44.         TH1=0xfd;
  45.         TL1=0xfd;
  46.         PCON=0x00;
  47.         TR1=1;
  48.         EA=1;
  49.         ES=1;
  50.   SCON=0x50;
  51. }
复制代码



VB上位机程序
Private Sub Command1_Click()               
strBuff = "1"                             
MSComm1.Output = strBuff                  
End Sub                                    

Private Sub Command2_Click()         
strBuff = "2"
MSComm1.Output = strBuff
End Sub

Private Sub Command3_Click()
strBuff = "3"
MSComm1.Output = strBuff
End Sub

Private Sub Command4_Click()
strBuff = "4"
MSComm1.Output = strBuff
End Sub

Private Sub Command5_Click()
strBuff = "5"
MSComm1.Output = strBuff
End Sub

Private Sub Command6_Click()
strBuff = "6"
MSComm1.Output = strBuff
End Sub

Private Sub Command7_Click()
strBuff = "7"
MSComm1.Output = strBuff
End Sub

Private Sub Command8_Click()
strBuff = "8"
MSComm1.Output = strBuff
End Sub

Private Sub Command9_Click()
End
End Sub

Private Sub Form_Load()
form1.WindowState = 2 '界面设置为最大
MSComm1.Settings = "9600,n,8,1"
MSComm1.OutBufferSize = 2   '设置MSComm1发送缓冲区为2字节
MSComm1.OutBufferCount = 0 '清除发送缓冲区
MSComm1.CommPort = 4  '指定使用com4
MSComm1.PortOpen = True '打开接口


End Sub
Private Sub Form_Resize()
Me.PaintPicture Me.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub


作者: zqy181818    时间: 2017-5-18 00:27
要是有个截图就好了,方便初学者
作者: dpj121    时间: 2017-5-18 00:59
本例实现用VB上位机来控制51单片机8位led灯的亮和灭
作者: 283635892    时间: 2017-12-5 18:01
谢谢呵呵学习一下
作者: 丨黑丨    时间: 2018-5-25 15:08
前来学习
作者: bg3irm    时间: 2018-12-27 22:46
感谢分享,谢谢楼主,收藏了。




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1