您的位置 首页 数字

51和VB数字量简易测验

51代码includereg52h>defineucharunsignedchardefineuintunsignedintvoiddelay(uintk){while(k–);}ucharr

//51代码
#include
#define uchar unsigned char
#define uint unsigned int
void delay(uint k)
{
while(k–);
}
uchar rec;//接受到的数据
sbit q1=P1^0; //输出点
sbit q2=P1^1; //输出点
sbit q3=P1^2; //输出点
sbit q4=P1^3; //输出点
sbit fk=P1^4; //反应点
sbit j1=P2^4;//反应发光指示
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; //主动重装载
TH1=TL1=253;
TR1=1;
REN=1;
}
void str_init()//串口中止初始化
{
EA=1;
ES=1;
}
void str_send(uchar u) //串口发送函数
{
bit es;
es=ES; //保存现场
ES=0;
SBUF=u;
while(TI==0);
TI=0;
ES=es;
}
void str_event() interrupt 4
{
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单片机端口悉数源码能够
从这儿http://www.51hei.com/f/51vbcs.rar下载.
//———- VB代码——————————————————–
Private Sub Command1_Click()
On Error GoTo errline:
MSComm1.Output = “1”
Shape1.FillColor = vbGreen
Exit Sub
errline:
If Err.Number = 8018 Then
Text3.Text = “串口已关”
End If
Err.Clear
End Sub
Private Sub Command10_Click()
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

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/shuzi/318401.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部