#include"reg51.h"
#include"stdio.h"
unsigned char Pos;
unsigned char number;
unsigned char i;
unsigned char NUM[10]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,0x80,0x90};
void Timer0_init ();
void xio() ;
void display_num(unsigned char num,unsigned char Pos) ;
void main()
{
Timer0_init ();
while(1);
}
void Timer0_init ()
{
EA=1;
ET0=1;
TMOD=0x02;
TH0=0xfe;
TL0=0x0c;
TR0=1;
Pos=0x01;
}
void xio() interrupt 1
{
for(i=1;i<=8;i++)
{
display_num(i,Pos);
Pos=Pos<<1;
display_num(i,0);
}
}
void display_num(unsigned char num,unsigned char Pos)
{
if(number!=0)
P0=NUM[num];
P2=Pos;
}
数码管显示程序
|