中级会员
- 积分
- 406
- 威望
- 237
- 贡献
- 89
- 兑换币
- 131
- 注册时间
- 2012-12-3
- 在线时间
- 40 小时
|
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit a=P2^3;
sbit b=P2^2;
sbit c=P2^1;
sbit d=P2^0;
sbit fenmingqi=P1^0;
sbit zhongduan=P3^2;
sbit key0=P3^3;
uint Number;
uchar ge,shi,bai,qian,aa;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void init();
void delays(uint xms);
void display(uchar qian,uchar bai,uchar shi,uchar ge);
void switchcontrol();
void main()
{
init();
while(1)
{
display(qian,bai,shi,ge);
switchcontrol();
}
}
void init()
{
Number=0;
ge=0xc0;
shi=0xc0;
bai=0xc0;
qian=0xc0;
key0=1;
fenmingqi=1;
TMOD=0x01;
TH0=(65536-9174)/256;
TL0=(65536-9174)%256;
EA=1;
ET0=1;
TR0=0;
EX0=1;
}
void OUT1() interrupt 0
{ if((Number>300)||(Number==0))
if(zhongduan==0)
{
TR0=~TR0;
fenmingqi=0;
}
}
void TIMER1() interrupt 1
{
TH0=(65536-9174)/256; 9
TL0=(65536-9174)%256;
aa=1;
if(aa==1)
{
aa=0;
Number++;
}
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
qian=Number/1000;
bai=Number/100%10;
shi=Number%100/10;
ge=Number%10;
a=0;
if(ge==10)
ge=0;
P0=table[ge];
delays(1);
a=1;
P0=0xff;
b=0;
if(shi==10)
shi=0;
P0=table[shi];
delays(1);
b=1;
P0=0xff;
c=0;
if(bai==10)
bai=0;
P0=table[bai];
delays(1);
c=1;
P0=0xff;
d=0;
if(qian==10)
qian=0;
P0=table[qian];
delays(1);
d=1;
fenmingqi=1;
}
void switchcontrol()
{
if(key0==0)
{
delays(20);
if(key0==0)
{
TR0=0;
Number=0;
}
while(!key0)
delays(20);
while(!key0);
}
}
void delays(uint xms)
{ uint x,y;
for(x=xms;x>0;x--)
for(y=110;y>0;y--) ;
}
为什么显示的时候,输入外部中断会出现数码管只增加1
|
|