//用计数器统计的数量,用定时器在数码管上显示数量,用外部中断清空
//师傅的意思是想让我们把显示函数丢到中断里边好从delay中解脱出来,可楼主太菜了,悟不到555
#include<reg51.h>
#include<stdio.h>
unsigned char dis;
//sbit relay = P1^0;
unsigned char code nondis[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//0-9
//延时
void delay(unsigned int n)
{
unsigned int i=0,j=0;
for(i=0;i<n;i++)
{
for(j=0;j<120;j++);
}
}
//显示函数
void display()
{
unsigned char gewei,shiwei,baiwei;
// num1=256-TL0;
// num=9-num1;
baiwei=TL0/100;
gewei=TL0%10;
shiwei=(TL0/10)%10;
P2=nondis[gewei];//个位
P0=0x80;
delay(10);
P2=0xff;
P2=nondis[shiwei];//十位
P0=0x40;
delay(10);
P2=0xff;
P2=nondis[baiwei];//百位
P0=0x20;
delay(10);
P2=0xff;
}
void main(void)
{
P0=0x80;
EA = 1;
ET0 = 1;
EX0 = 1;
IT0 = 1;
ET0 = 0;
TMOD = 0x06;
TH0 = 0;//9
TL0 = 0;//9
TR0 = 1;
while(1)
{
display();//显示函数
}
}
void int0() interrupt 0 // 清空
{
TL0 = 0 ;
}
//void counter1() interrupt 1
//{
// relay = ~relay;
//}
|