完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
目的:上位机(vb编写)发送一个数据给单片机,单片机接收到数据后,将数据加一后返回给上位机,
现象:发送正常,接收时,不论你发送是什么数据,单片机返回给上位机的数据一直是1??? 大家帮忙看看我那里错了。 下面是我的vb程序 Private Sub Command1_Click() Dim outbyte(0) As Byte Dim number As Integer number = Val(Text1.Text) outbyte(0) = CByte(number) MSComm1.Output = outbyte End Sub Private Sub Command2_Click() MSComm1.PortOpen = False Unload Me End Sub Private Sub Form_Load() Form1.AutoRedraw = True MSComm1.CommPort = 1 MSComm1.Settings = "9600,n,8,1" MSComm1.InputLen = 0 ' 设置或返回一次从接收缓冲区中读取字节数,0表示一次读取所有数据 MSComm1.InBufferCount = 0 MSComm1.OutBufferCount = 0 MSComm1.RThreshold = 1 ' 每个字符到接收缓冲区都触发接收事件 MSComm1.InputMode = comInputModehexadecimal '采用二进制传输 MSComm1.PortOpen = True Text1 = "" Text2 = "" End Sub Private Sub MSComm1_OnComm() Dim BytReceived(0) As Byte Dim strBuff As Variant Select Case MSComm1.CommEvent Case comEvReceive strBuff = MSComm1.InBufferCount BytReceived(0) = strBuff Text2 = BytReceived(0) End Select End Sub 下面是我单片机程序 #include #define uint unsigned int #define uchar unsigned char uchar a,flag; void main() { TMOD=0X20; TL1=0XFD; TH1=0XFD; SCON=0X50; TR1=1; EA=1; ES=1; while(1) { if(flag) { ES=0; flag=0; SBUF=a+1; while(!TI); TI=0; ES=1; } } } void xx() interrupt 4 { RI=0; a=SBUF; P0=0XF0|a; flag=1; } |
|
相关推荐
9 个讨论
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:1:}
|
|
|
|
|
|
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-2 19:16 , Processed in 0.617733 second(s), Total 57, Slave 48 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号