数码管.c

来自「Proteus的数码管仿真电路」· C语言 代码 · 共 58 行

C
58
字号
#include<AT89X51.H>
unsigned char code tab0[]={0x00,0x01,0x02,0x03,
                          0x04,0x05,0x06,0x07,
						  0x08,0x09};
unsigned int second;
unsigned char tcount;
unsigned int a,b,c;
void delay(unsigned int n)
{
 unsigned int i,j;
 for(i=n;i>0;i--)
  for(j=112;j>0;j--);
}
void main(void)
{
 TMOD=0x01;
 TH0=(65536-50000)/256;
 TL0=(65536-50000)%256;
 TR0=1;
 ET0=1;
 EA=1;
 tcount=0;
 second=0;
 a=0;
 b=0;
 c=0;
 while(1)
 {
    P2=tab0[second%10];
	P2_7=1;
	delay(2);
	P2=tab0[second/10];
	P2_6=1;
	delay(2);
    P2=tab0[second/100];
	P2_5=1;
	delay(2);
	P2=tab0[second/1000];
	P2_4=1;
	delay(2);
 }
}
void t0(void) interrupt 1 using 0
{
   tcount++;
   if(tcount==20)
   {
    tcount=0;
    second++;
    if(second==10000)
    {
     second=0;
    }
   }
  TH0=(65536-50000)/256;
  TL0=(65536-50000)%256;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?