Private Sub hexSend()
創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站和四川服務(wù)器托管的網(wǎng)絡(luò)公司,有著豐富的建站經(jīng)驗(yàn)和案例。
On Error Resume Next
Dim outputLen As Integer
Dim outData As String
Dim SendArr() As Byte
Dim TemporarySave As String
Dim dataCount As Integer
Dim i As Integer
outData = UCase(Replace(txtSend.Text, Space(1), Space(0)))
outData = UCase(outData)
outputLen = Len(outData)
For i = 0 To outputLen-1
TemporarySave = Mid(outData, i + 1, 1)
If (Asc(TemporarySave) = 48 And Asc(TemporarySave) = 57) Or (Asc(TemporarySave) = 65 And Asc(TemporarySave) = 70) Then
dataCount = dataCount + 1
Else
Exit For
Exit Sub
End If
Next
If dataCount Mod 2 0 Then
dataCount = dataCount - 1
End If
outData = Microsoft.VisualBasic.Left(outData, dataCount)
ReDim SendArr(dataCount / 2 - 1)
For i = 0 To dataCount / 2 - 1
SendArr(i) = Val("h" + Mid(outData, i * 2+1, 2))
Next
SerialPort1.Write(SendArr, 0, 1)
End Sub
修改幾處就好用了。
絕對(duì)不行!基于x86處理器構(gòu)架的程序,是不能在不是x86構(gòu)架的單片機(jī)上運(yùn)行的。
這個(gè)可以有,是51的,用到STC8A8K64S4A12上應(yīng)該不成問題。
#include STC89.H
unsigned char tmp;
sbit shebei1=P1^0;//定義控制設(shè)備的IO口
sbit shebei2=P1^1;
sbit shebei3=P1^2;
sbit shebei4=P1^3;
sbit shebei5=P1^4;
sbit shebei6=P1^5;
void main()
{
TMOD = 0x20; // 定時(shí)器1工作于8位自動(dòng)重載模式, 用于產(chǎn)生波特率
TH1 = 0xFD; // 波特率9600
TL1 = 0xFD;
SCON = 0x50; // 設(shè)定串行口工作方式
PCON = 0xef; // 波特率不倍增
TR1 = 1; // 啟動(dòng)定時(shí)器1
IE = 0x0; // 禁止任何中斷
while(1)
{
if(RI) // 是否有數(shù)據(jù)到來
{
RI = 0;// 清接收標(biāo)志
tmp = SBUF; // 暫存接收到的數(shù)據(jù)
switch(tmp )
{
case 0x22:shebei1=0;break;//關(guān)設(shè)備1
case 0x33:shebei1=1;break;//開設(shè)備1
case 0x44:shebei2=0;break;
case 0x55:shebei2=1;break;
case 0x66:shebei3=0;break;
case 0x77:shebei3=1;break;
case 0x88:shebei4=0;break;
case 0x99:shebei4=1;break;
// case 0xaa:shebei5=0;break;
// case 0xbb:shebei5=1;break;
// case 0xcc:shebei6=0;break;
// case 0xdd:shebei6=1;break;
case 0x17:shebei5=0;break;
case 0x18:shebei5=1;break;
case 0x19:shebei6=0;break;
case 0x20:shebei6=1;break;
}
}
}
}
void delayms(unsigned char ms)
// 延時(shí)子程序
{
unsigned char i;
while(ms--)
{
for(i = 0; i 120; i++);
}
}
一個(gè)需要.net框架,一個(gè)不需要,學(xué)單片機(jī)就不要 vb.net了,vb.net一般都用于企業(yè)級(jí)軟件的開發(fā),隨著C#的普及,用 vb.net的也越來越少了。單純用好vb腳本也很不錯(cuò)