程序是网上8x16点阵滚动时钟修改而来,在此谢谢原创。
#include <REGX51.H> unsigned char sec=0,min=0,hou=12,st=0x00,timecount=0,oldP1=0xff,setting=0;
bit point=1,K1_old,K2_old;
unsigned char code dis_code[]=
{ 0x3E,0x41,0x41,0x3E,0x21,0x7F,0x01,0x00,//0与1
0x23,0x45,0x49,0x31,0x22,0x41,0x49,0x36, //2与3
0x1E,0x22,0x7F,0x02,0x72,0x51,0x51,0x4E, //4与5
0x3E,0x49,0x49,0x26,0x60,0x40,0x4F,0x70, //6与7
0x36,0x49,0x49,0x36,0x32,0x49,0x49,0x3E, //8与9
0x3E,0x2A,0x3E,0x40,0x49,0xFE,0x40,0x00, //时
0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,0x00, //+
0x3E,0x2A,0x3E,0x40,0x49,0xFE,0x40,0x00, //时
0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x00, //-
0x10,0x21,0x4A,0x0C,0x49,0x2F,0x20,0x00, //分
0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,0x00, //+
0x10,0x21,0x4A,0x0C,0x49,0x2F,0x20,0x00, //分
0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x00, //-
0x32,0x49,0x49,0x26,0x00,0x40,0x7F,0x40, //st
0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,0x00, //+
0x32,0x49,0x49,0x26,0x00,0x40,0x7F,0x40, //st
0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x00, //-
};
unsigned char code disp_code[]=
{ 0x7F,0x41,0x7F,0x00,0x00,0x08,0x00,0x00,
0x00,0x41,0x00,0x00,0x01,0x08,0x40,0x00,
0x41,0x00,0x41,0x00,0x41,0x08,0x41,0x00,
0x45,0x00,0x45,0x00,0x15,0x20,0x45,0x00,
0x55,0x00,0x55,0x00,0x49,0x49,0x49,0x00,
0x3E,0x2A,0x3E,0x40,0x49,0xFE,0x40,0x00, //时
0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,0x00, //+
0x3E,0x2A,0x3E,0x40,0x49,0xFE,0x40,0x00, //时
0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x00, //-
0x10,0x21,0x4A,0x0C,0x49,0x2F,0x20,0x00, //分
0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,0x00, //+
0x10,0x21,0x4A,0x0C,0x49,0x2F,0x20,0x00, //分
0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x00, //-
0x32,0x49,0x49,0x26,0x00,0x40,0x7F,0x40, //st
0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,0x00, //+
0x32,0x49,0x49,0x26,0x00,0x40,0x7F,0x40, //st
0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x00, //-
};
sbit K1=P1^7;
sbit K2=P1^6;
void time50ms(void);
void delay_ms(void);
void timedeal(void);
/*******************************************************************/
void main(void)
{
unsigned char num,disnum,x,y,offset=0,dis_p,scantimes=0;
IE=0x82; //允许定时器0工作
TMOD=0x01; //timer0为模式1
TR0=1; //定时器0可以工作
TH0 = 0x4c;
TL0 = 0x00|(st);
do
{
if(setting==0) //正常显示状态
{
for(x=0;x<16;x++) //
{
dis_p=x;
if(dis_p==3|| dis_p==8|| dis_p==10|| dis_p==15||dis_p>15) //空列
{
y=0;
}
else if(dis_p<=2) //0~2为时的十位
{
num=hou/10;
if(num>0)
y=dis_code[num*4+dis_p];
else
y=0;
}
else if(dis_p<=7) //4~7为时的个位
{
num=hou%10;
y=dis_code[num*4+dis_p-4];
}
else if(dis_p<=9) //9为冒号的显示位
{
if(point)
y=0x63;
else
y=0;
}
else if(dis_p<=14) //11~14为分的十位
{
num=min/10;
y=dis_code[num*4+dis_p-11];
}
P3=0;
P1=x|0xE0;
P3=y;
delay_ms();
}
for(x=0;x<16;x++)
{
dis_p=x;
if(dis_p==4 || dis_p==6||dis_p==11||dis_p==16||dis_p>16 ) //空列
{
y=0;
}
else if(dis_p<=3) //0~3为分的个位
{
num=min%10;
y=dis_code[num*4+dis_p];
}
else if(dis_p<=5) //5为冒号的显示位
{
if(point)
y=0x63;
else
y=0;
}
else if(dis_p<=10) //7~10为秒的十位
{
num=sec/10;
y=dis_code[num*4+dis_p-7];
}
else if(dis_p<=15) //12~15为秒的个位
{
num=sec%10;
y=dis_code[num*4+dis_p-12];
}
P3=0;
P1=x|0xd0;
P3=y;
delay_ms(); //刷新
}
}
/**********************************************************************///以下麻将
else if(setting==1) //正常显示状态
{
for(x=0;x<16;x++) //
{
dis_p=x;
if(dis_p==3|| dis_p==8|| dis_p==10|| dis_p==15||dis_p>15) //空列
{
y=0;
}
else if(dis_p<=2) //0~2为时的十位
{
num=hou/10;
if(num>0)
y=disp_code[num*4+dis_p];
else
y=0;
}
else if(dis_p<=7) //4~7为时的个位
{
num=hou%10;
y=disp_code[num*4+dis_p-4];
}
else if(dis_p<=9) //9为冒号的显示位
{
if(point)
y=0x63;
else
y=0;
}
else if(dis_p<=14) //11~14为分的十位
{
num=min/10;
y=disp_code[num*4+dis_p-11];
}
P3=0;
P1=x|0xE0;
P3=y;
delay_ms();
}
for(x=0;x<16;x++)
{
dis_p=x;
if(dis_p==4 || dis_p==6||dis_p==11||dis_p==16||dis_p>16 ) //空列
{
y=0;
}
else if(dis_p<=3) //0~3为分的个位
{
num=min%10;
y=disp_code[num*4+dis_p];
}
else if(dis_p<=5) //5为冒号的显示位
{
if(point)
y=0x63;
else
y=0;
}
else if(dis_p<=10) //7~10为秒的十位
{
num=sec/10;
y=disp_code[num*4+dis_p-7];
}
else if(dis_p<=15) //12~15为秒的个位
{
num=sec%10;
y=disp_code[num*4+dis_p-12];
}
P3=0;
P1=x|0xd0;
P3=y;
delay_ms(); //刷新
}
}
/**************************************************///
else //当进入调整时间的状态,运行下面的程序段
{
for(x=0;x<16;x++)
{
if(setting==2)
if(x<16) //前16列显示汉字+时
if(point)
y=dis_code[24+setting*8+x];
else
y=0;
if(setting==3)
if(x<16) //前16列显示汉字-时
if(point)
y=dis_code[32+setting*8+x];
else
y=0;
if(setting==4)
if(x<16) //前16列显示汉字+分
if(point)
y=dis_code[40+setting*8+x];
else
y=0;
if(setting==5)
if(x<16) //前16列显示汉字-分
if(point)
y=dis_code[48+setting*8+x];
else
y=0;
if(setting==6)
if(x<16) //前16列显示汉字+st
if(point)
y=dis_code[56+setting*8+x];
else
y=0;
if(setting==7)
if(x<16) //前16列显示汉字-st
if(point)
y=dis_code[64+setting*8+x];
else
y=0;
P3=0;
P1=x|0xe0; //刷新
P3=y;
delay_ms();
}
for(x=0;x<16;x++)
{
if(setting==2||setting==3)
{
dis_p=x;
if(dis_p<=7 )
{
y=0;
}
else if(x<12) //8~11为十位
{
disnum=hou;
num=disnum/10;
y=dis_code[num*4+x-8];
}
else //12~15为个位
{
num=disnum%10;
y=dis_code[num*4+x-12];
}
}
if(setting==4||setting==5)
{
dis_p=x;
if(dis_p<=7 )
{
y=0;
}
else if(x<12) //8~11为十位
{
disnum=min;
num=disnum/10;
y=dis_code[num*4+x-8];
}
else //12~15为个位
{
num=disnum%10;
y=dis_code[num*4+x-12];
}
}
if(setting==6||setting==7)
{
dis_p=x;
if(dis_p<=7 )
{
y=0;
}
else if(x<12) //8~11为十位
{
disnum=st;
num=disnum/10;
y=dis_code[num*4+x-8];
}
else
{ //12~15为个位
num=disnum%10;
y=dis_code[num*4+x-12];
}
}
P3=0;
P1=x|0xd0;
P3=y;
delay_ms();
}
}
}
while(1);
}
/***************************************************/
void delay_ms(void) //显示刷新
{
unsigned char i,j;
for(i=0;i<4;i++)
for(j=0;j<30;j++);
}
/****************************************************/
void time50ms(void) interrupt 1
{
TH0 = 0x4c;
TL0 = 0x00|(st);
timecount++;
if(timecount==10)
{
timecount=0;
point=!point;
if(point)
{
sec++;
timedeal();
}
}
if(!K1&&K1!=K1_old)//按下模式键
{
setting++;
if(setting==8)
setting=0;
}
if(!K2 && K2!=K2_old) //按下置位键
{
if(setting==2)
{
hou++;
sec=0;
timedeal();
}
else if(setting==3)
{
if(hou==0)
hou=12;
hou--;
timedeal();
}
else if(setting==4)
{
min++;
sec=0;
timedeal();
}
else if(setting==5)
{
if(min==0)
min=60;
min--;
sec=0;
timedeal();
}
else if(setting==6)
{
st++;
if(st==100)
st=0;
}
else if(setting==7)
{
st--;
if(st==0-1)
st=99;
}
}
K1_old=K1;
K2_old=K2;
}
/****************************************************/
void timedeal(void)
{
if(sec>=60)
{
sec=0;
min++;
}
if(min>=60)
{
min=0;
hou++;
}
if(hou>12)
hou=1;
} |