51和VB數(shù)字量簡(jiǎn)易測(cè)試
//51代碼
#include
#define uchar unsigned char
#define uint unsigned int
#define uint unsigned int
void delay(uint k)
{
while(k--);
}
{
while(k--);
}
uchar rec;//接受到的數(shù)據(jù)
sbit q1=P1^0; //輸出點(diǎn)
sbit q2=P1^1; //輸出點(diǎn)
sbit q3=P1^2; //輸出點(diǎn)
sbit q4=P1^3; //輸出點(diǎn)
sbit fk=P1^4; //反饋點(diǎn)
sbit j1=P2^4;//反饋發(fā)光指示
sbit q2=P1^1; //輸出點(diǎn)
sbit q3=P1^2; //輸出點(diǎn)
sbit q4=P1^3; //輸出點(diǎn)
sbit fk=P1^4; //反饋點(diǎn)
sbit j1=P2^4;//反饋發(fā)光指示
void light()
{
if(rec==1)q1=0;
else if(rec==2)q2=0;
else if(rec==3)q3=0;
else if(rec==4)q4=0;
else if(rec==5)q1=1;
else if(rec==6)q2=1;
else if(rec==7)q3=1;
else if(rec==8)q4=1;
}
void serial_init() //串口初始化
{
SM2=0;
SM1=1;
SM0=0;
TMOD|=0x20; //自動(dòng)重裝載
TH1=TL1=253;
TR1=1;
REN=1;
}
{
SM2=0;
SM1=1;
SM0=0;
TMOD|=0x20; //自動(dòng)重裝載
TH1=TL1=253;
TR1=1;
REN=1;
}
void str_init()//串口中斷初始化
{
EA=1;
ES=1;
{
EA=1;
ES=1;
}
void str_send(uchar u) //串口發(fā)送函數(shù)
{
bit es;
es=ES; //保存現(xiàn)場(chǎng)
ES=0;
SBUF=u;
while(TI==0);
TI=0;
ES=es;
}
{
bit es;
es=ES; //保存現(xiàn)場(chǎng)
ES=0;
SBUF=u;
while(TI==0);
TI=0;
ES=es;
}
void str_event() interrupt 4
{
if(RI)
{
rec=SBUF;
RI=0;
}
else
{
;
}
}
{
if(RI)
{
rec=SBUF;
RI=0;
}
else
{
;
}
}
void main()
{
serial_init();
str_init();
fk=0;
while(1)
{
if(fk==1) //正常
{
str_send(9);
j1=0;
delay(400);
}
if(fk==0)
{
str_send(a); //故障
j1=1;
delay(400);
}
light();
}
}
51單片機(jī)端口全部源碼可以
從這里http://www.51hei.com/f/51vbcs.rar下載.
從這里http://www.51hei.com/f/51vbcs.rar下載.
//---------- VB代碼--------------------------------------------------------
Private Sub Command1_Click()
On Error GoTo errline:
MSComm1.Output = "1"
Shape1.FillColor = vbGreen
Exit Sub
Shape1.FillColor = vbGreen
Exit Sub
errline:
If Err.Number = 8018 Then
Text3.Text = "串口已關(guān)"
End If
Err.Clear
End Sub
If Err.Number = 8018 Then
Text3.Text = "串口已關(guān)"
End If
Err.Clear
End Sub
Private Sub Command10_Click()
On Error GoTo errline:
On Error GoTo errline:
MSComm1.Output = "5"
MSComm1.Output = "6"
MSComm1.Output = "7"
MSComm1.Output = "8"
Shape1.FillColor = vbRed
Shape2.FillColor = vbRed
Shape3.FillColor = vbRed
Shape4.FillColor = vbRed
MSComm1.PortOpen = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
關(guān)鍵詞:
51VB數(shù)字
相關(guān)推薦
技術(shù)專區(qū)
- FPGA
- DSP
- MCU
- 示波器
- 步進(jìn)電機(jī)
- Zigbee
- LabVIEW
- Arduino
- RFID
- NFC
- STM32
- Protel
- GPS
- MSP430
- Multisim
- 濾波器
- CAN總線
- 開(kāi)關(guān)電源
- 單片機(jī)
- PCB
- USB
- ARM
- CPLD
- 連接器
- MEMS
- CMOS
- MIPS
- EMC
- EDA
- ROM
- 陀螺儀
- VHDL
- 比較器
- Verilog
- 穩(wěn)壓電源
- RAM
- AVR
- 傳感器
- 可控硅
- IGBT
- 嵌入式開(kāi)發(fā)
- 逆變器
- Quartus
- RS-232
- Cyclone
- 電位器
- 電機(jī)控制
- 藍(lán)牙
- PLC
- PWM
- 汽車電子
- 轉(zhuǎn)換器
- 電源管理
- 信號(hào)放大器
評(píng)論