编辑: Mckel0ve 2016-05-16

while(1) { display(0,1,2,3,4);

} } void display(uchar one,uchar two,uchar three,uchar four,uchar five) { dula=1;

P0=table[one];

dula=0;

wela=1;

P0=0xfe;

wela=0;

delay(time);

dula=1;

P0=table[two];

dula=0;

wela=1;

P0=0xfd;

wela=0;

delay(time);

dula=1;

P0=table[three];

dula=0;

wela=1;

P0=0xfb;

wela=0;

delay(time);

dula=1;

P0=table[four];

dula=0;

wela=1;

P0=0xf7;

wela=0;

delay(time);

dula=1;

P0=table[five];

dula=0;

wela=1;

P0=0xef;

wela=0;

delay(time);

} void delay(uint z) { uint x,y;

for(x=z;

x>

0;

x--) { for(y=110;

y>

0;

y--) {} } } 秒表 #include #define uint unsigned int #define uchar unsigned char sbit dula = P2^6;

sbit wela=P2^7;

uchar code table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71};

uchar code table1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

void display(uchar,uchar,uchar);

void delay(uint z) { uint x,y;

for(x=z;

x>

0;

x--) { for(y=110;

y>

0;

y--) {} } } uchar a,time,ge,shi,bai,numwe,j;

uchar temp;

void main() { TMOD=0X01;

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

EA=1;

ET0=1;

TR0=1;

while(1) { time=50;

display(bai,shi,ge);

} } void display(uchar bai,uchar shi,uchar ge) { dula=1;

P0=table[bai];

dula=0;

wela=1;

P0=0xfe;

wela=0;

delay(time);

dula=1;

P0=table[shi];

dula=0;

wela=1;

P0=0xfd;

wela=0;

delay(time);

dula=1;

P0=table[ge];

dula=0;

wela=1;

P0=0xfb;

wela=0;

delay(time);

} void timer0() interrupt

1 { TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

a++;

if(a==20) { a=0;

temp++;

if(temp==100) { temp=0;

//if(j0;

x--) { for(y=110;

y>

0;

y--) {} } } uchar a,time,ge,shi,bai,numwe,j;

uchar temp=10;

void main() { TMOD=0X01;

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

EA=1;

ET0=1;

TR0=1;

while(1) { time=50;

display(bai,shi,ge);

} } void display(uchar bai,uchar shi,uchar ge) { dula=1;

P0=table[bai];

dula=0;

wela=1;

P0=0xfe;

wela=0;

delay(time);

dula=1;

P0=table[shi];

dula=0;

wela=1;

P0=0xfd;

wela=0;

delay(time);

dula=1;

P0=table[ge];

dula=0;

wela=1;

P0=0xfb;

wela=0;

delay(time);

} void timer0() interrupt

1 { TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

a++;

if(a==20) { a=0;

temp--;

if(temp==0) { //if(j0;

y--);

} uchar keyscan();

void display(uchar aa);

void main() { num=16;

// 扫描函数没有返回值时,熄灭所有数码管 //dula=1;

//P0=0;

//dula=0;

wela=1;

P0=0xc0;

wela=0;

while(1) { display(keyscan());

} } void display(uchar aa) { dula=1;

P0=table[aa];

dula=0;

} uchar keyscan() { P3=0xfe;

temp=P3;

temp=temp&

0xf0;

while(temp!=0xf0) { delay(5);

temp=P3;

temp=temp&

0xf0;

while(temp!=0xf0) { temp=P3;

//重新读端口 switch(temp) { case 0xee:num=10;

//显示0;

这儿的0xee是端口的值 break;

case 0xde:num=7;

//显示1 break;

case 0xbe:num=4;

//显示2 break;

case 0x7e:num=1;

//显示3 break;

} while(temp!=0xf0)//松手检测,不能少 { temp=P3;

temp=temp&

0xf0;

} } } P3=0xfd;

temp=P3;

temp=temp&

0xf0;

while(temp!=0xf0) { delay(5);

temp=P3;

temp=temp&

0xf0;

while(temp!=0xf0) { temp=P3;

switch(temp) { case 0xed:num=0;

//显示4 break;

case 0xdd:num=8;

//显示5 break;

case 0xbd:num=5;

//显示6 break;

case 0x7d:num=2;

下载(注:源文件不在本站服务器,都将跳转到源网站下载)
备用下载
发帖评论
相关话题
发布一个新话题