流程图如图所示。
参考程序设计
#include<REGX52.H>
#define uchar unsigned char
#define uint unsigned int
uchar code SEG7[1 0]={0×3f,O×06,0×5b,
0×4f,0×66,0×6d,0×7d,0×07,0×7f,0×6f}:
sbit L0=P1^0;
sbit L1=P1^1;
sbit L2=P1^2;
sbit L3=P1^3;
sbit L4=P1^4;
sbit L5=P1^5;
sbit L6=P1^6;
sbit L7=P1^7;
sbit H0=P2^0;
sbit H1=P2^1;
sbit H2=P2^2;
sbit H3=P2^3;
sbit H4=P2^4;
sbit H5=P2^5;
sbit H6=P2^6;
sbit H7=P2^7;
sbit GATE=P3^0;
sbit S1=P3^1;
uchar L10=0;
uchar L11;
uchar L12;
uchar L13;
//键消抖的延时函数
uint T.S;
void delays(T)
{
uint i;
uint j;
for(i=T;i>0:i——);
for(j=200;j>0;j——);
}
//蜂鸣器响
void bells(S)
{uint k;
uint l;
for(k=S;k>0;k——);
for(1=2;l>0;l——);
{if(L10==1)GATE=1;else GATE=0:}
}
//显示P0口
void disp(void)
{
uchar a=0;
if(L0==0)a=0;
if(L1==O)a=1;
if(L2==0) a=2;
if(L3==0)a=3;
P0=SEG7[a];
void main(void)
{
disp():
if(S1==O){L10++;if(L10>=2)L10=0;};
if(LO==0)
{L4=O;
H0=0;
delays(300);
delays(3000);
delays(3000):
delays(3000);
delays(3000);
L4=1;
}
;
if(L1==O)
{
L5=0;
H0=0;
H1=0:
delays(3000);
delays(3000);
delays(3000);
delays(3000);
delays(3000);
L5=1;
}
if(L2==0)
{L6=0;
H0=0;
Ht=0;
H2=0;
delays(3000);
delays(3000);
delays(3000);
delays(3000);
delays(3000);
L6=1;
}
if(L3==0)
{L7=0;
H0=0;
H1=0:
H2=0;
H3=0;
delays(3000);
delays(3000);
delays(3000);
delays(3000);
delays(3000);
bells(1);
L7=1;
}
//P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
}
上一页 [1] [2]