#include <AT89X52.H>
unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code digittab[10][8]={
{0x00,0x00,0x21,0x7f,0x01,0x00,0x00,0x00}, //1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00}, //9
{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00} //0
};
unsigned int timecount;
unsigned char cnta;
unsigned char cntb;
unsigned char temp;
unsigned char count;
unsigned char location = 2;
unsigned int flag = 1;
bit flag_2 = 1;
void delayms(unsigned int m)
{
unsigned int i,j;
for(i = m; i > 0; i--)
for(j = 110; j > 0; j--)
;
}
void putchar(unsigned char data1)
{
SBUF = data1; //将待发送的字符送入发送缓冲器
while(TI == 0); //等待发送完成
TI = 0; //发送中断标志请0
}
//字符串发送函数
void putstring(unsigned char *dat)
{
while(*dat != '\0') //判断字符串是否发送完毕
{
putchar(*dat); //发送单个字符
dat++; //字符地址加1,指向先下一个字符
}
}
void send_char()
{
SCON = 0x50; //串口工作方式设置
TMOD = 0x20; //定时器工作方式设置
TH1 = 0xfd; //
TI = 0; // 清0发送中断标志
TR1 = 1; //开启定时器
ES = 1;
EA = 1;
putstring("now,8*8 show 1,2,3,4,5,6,7,8,9,0\0");
}
void main(void)
{
TMOD=0x01;
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
TR0=1;
ET0=1;
PT0 = 0;
EA=1;
EX0 = 1;
PX0 = 1;
while(1)
{;
}
}
void button() interrupt 0
{
delayms(10);
flag_2 = ~flag_2;
}
void t0(void) interrupt 1 using 0
{
if(~flag_2){
if(flag)
{
send_char();
flag = 0;
}
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
P0=tab[cnta];
if(temp == 0)
{
if(cnta < 5)
{
P2=digittab[cntb][cnta+2];
}else{
P2 = 0x00;
}
}else{
if(count != temp)
{
P2 = 0x00;
count++;
}else{
if(location < 7)
{
P2=digittab[cntb][location];
location++;
}else{
P2 = 0x00;
}
}
}
cnta++;
if(cnta==8)
{
count = 0;
location = 2;
cnta=0;
}
timecount++;
if(timecount%200 == 0)
{
temp++;
}
if(timecount==1600)
{
timecount=0;
cntb++;
temp = 0;
if(cntb==10)
{
cntb=0;
}
}
}
}