#include
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
unsigned char LedChar[]={
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90};
unsigned char c[6]={
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0};
unsigned char LedBuff[5][8]={ {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,},
{0xC3,0xE7,0xE7,0xE7,0xE7,0xE7,0xC3,0xFF,},
// 0xFF,0xE7,0xC3,0x81,0x00,0x00,0x00,0x99,*//*
{0x99,0x00,0x00,0x00,0x81,0xC3,0xE7,0xFF,}, //向上移动
//0xFF,0xC3,0x81,0x99,0x99,0x99,0x99,0x99,/*
{0x99,0x99,0x99,0x99,0x99,0x81,0xC3,0xFF,},
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
unsigned char a[8]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
unsigned char b[1]={0xFE};
unsigned int flag1s = 0;
unsigned int wc = 0;
unsigned int j = 0;
void main(){
unsigned long sec = 0;
ENLED = 0;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
TR0 = 1; //打开定时器
EA = 1; //打开中断器
ET0 = 1;
while(1){
if(flag1s == 1){//一秒执行一次。
flag1s = 0;
sec++;
c[0] = LedChar[sec%10];
c[1] = LedChar[sec/10%10];
c[2] = LedChar[sec/100%10];
c[3] = LedChar[sec/1000%10];
c[4] = LedChar[sec/10000%10];
c[5] = LedChar[sec/100000%10];
b[0] = a[wc];
wc++;
}
if(wc>=8){
wc = 0;
}
}
}
void InterruptTime0() interrupt 1 { //中断函数
static unsigned int cnt = 0;
static unsigned int i = 0;
static unsigned int index = 0;
TH0 = 0xFC; //x*12/11059200=0.001 65536-x=y, y转化16进制 = 0xFC。
TL0 = 0x67;
cnt++;
if(cnt>=1000){//到达1秒后进行。
cnt = 0;
flag1s = 1;
}
P0=0xFF;
//led点阵显示刷新
P1 = (P1 & 0xF0)|i ;
if((i >= 0)&&(i <= 7))
{
P0 = LedBuff[index][i];
}
if((i >= 8)&&(i <= 13))
{
P0 = c[i-8];
}
if(i == 14)
{
P0 = b[0];
}
if(i<15)
{
i++;
}
else
i = 0;
j++;
if(j>1000){
j = 0;
index++;
if(index >= 4){
index = 0;
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)