#include <stc15.h>
#include <intrins.h>
#include "ds1302.h"
unsigned char a[13]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x7f,0xbf,0xff};//0~9/./-/灭
unsigned char b[8]={0};
unsigned char s,f,m,s1,f1,m1;
void BUZZ()//初始化
{
P2=(P2&0x1f)|0x80;
P0=0xff;
P2&=0x1f;
P2=(P2&0x1f)|0xa0;
P0=0x00;
P2&=0x1f;
P2=(P2&0x1f)|0xc0;
P0=0xff;
P2&=0x1f;
P2=(P2&0x1f)|0xe0;
P0=0xff;
P2&=0x1f;
}
void SMG_xuanze()//数码管位选 段选
{
static int i=0;
P2=(P2&0x1f)|0xc0;
P0=0x01<<i;
P2&=0x1f;
P2=(P2&0x1f)|0xe0;
P0=a[b[i]];
P2&=0x1f;
i=(i+1)%8;
}
void shijianxianshi()//时间显示
{
s1=Read_Ds1302_Byte(0x85);
f1=Read_Ds1302_Byte(0x83);
m1=Read_Ds1302_Byte(0x81);
s=s1/16*10+s1%16;
f=f1/16*10+f1%16;
m=m1/16*10+m1%16;
b[0]=s/10;
b[1]=s%10;
b[2]=11;
b[3]=f/10;
b[4]=f%10;
b[5]=11;
b[6]=m/10;
b[7]=m%10;
}
void key()
{
}
void Timer0Init(void) //1毫秒@11.0592MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0xCD; //设置定时初值
TH0 = 0xD4; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0=1;
EA=1;
}
void ServiceTimer0()interrupt 1
{
SMG_xuanze();
shijianxianshi();
}
void main()
{
BUZZ();
Timer0Init();
time(20,20,1);
while(1)
{
}
}