13楼
16楼
传一个用VB写的关于温度计的上位机,配合单片机串口程序在电脑端实时显示温度曲线
Public sina As Variant Public sinb As Variant Public sinc As Variant Public sind As Variant Public sine As Variant Public i As Variant Private Sub Command1_Click() If Command1.Caption = "关闭串口" Then MSComm1.PortOpen = False Command1.Caption = "打开串口" Timer1.Enabled = False Else Command1.Caption = "关闭串口" MSComm1.CommPort = Combo1.Text MSComm1.Settings = "" '"Combo2.text"'","'" combo3.text "'", "'" combo4.text "'" , "'"combo5.text "'"" MSComm1.InputMode = 0 MSComm1.PortOpen = True Timer1.Enabled = True End If End Sub Private Sub Form_Load() Dim i As Integer '生成串口号 For i = 1 To 20 With Combo1 .AddItem i End With Next Combo2.AddItem "600" Combo2.AddItem "1200" Combo2.AddItem "2400" Combo2.AddItem "4800" Combo2.AddItem "9600" Combo2.AddItem "57600" Combo2.AddItem "115200" Combo3.AddItem "n" Combo3.AddItem "e" Combo3.AddItem "o" Combo3.AddItem "s" Combo3.AddItem "m" Combo4.AddItem "8" Combo4.AddItem "9" Combo5.AddItem "1" Combo5.AddItem "1.5" Combo5.AddItem "2" i = 100 sina = 0 sind = 1400 sinc = 0 End Sub Private Sub Timer1_Timer() Dim buf$ Dim v As Double buf = Trim(MSComm1.Input) If Len(buf) <> 0 Then sina = sinc sinb = sind v = Asc(buf) + 256 '只传了低八位,所以直接加256,相当于把接受的数据& 0001 0000 0000 v = v / 10 Text1.Text = Text1.Text + Str(v) + Chr(13) + Chr(10) sinc = (sina + 100) sind = (Asc(buf) * 20) sine = Val(2000) Form1.Picture1.Line (sina, 5000 - sinb)-(sinc, 5000 - sind), sine If sinc = 10000 Then Picture1.Cls sina = 0 sinc = 0 End If End If End Sub Private Sub cmdquite_chick() MSComm1.PortOpen = False Unload Me End Sub
等一会再传一个EXE可执行文件
程序数据处理比较特殊
uint tmp() //get the temperature { float tt; uchar a,b; dsreset(); delay(1); tmpwritebyte(0xcc); tmpwritebyte(0xbe); a=tmpread(); b=tmpread(); temp=b; temp<<=8; //two byte compose a int variable temp=temp|a; tt=temp*0.0625; temp=tt*10+0.5; return temp; }
这个是单片机读18B20,传感器是12数据,但是我们只传送了低八位,因为常温状态下第九位为1,所以加256
ii =tmp(); // SBUF=ii>>8; // while(TI==0);//???????? // TI=0;//?????? // SBUF=ii; while(TI==0);//???????? TI=0;//??????
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |