?? 數(shù)字鐘程序.c
字號:
#include <AT89X51.H>
//以下是0,1,2,3,4,5,6,7,8,9,A,b,c,d,E,F的字模;
unsigned char code display[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0xee,0x3e,0x9c,0x7a,0x9e,0x8e,0X00,0x02,0xff};
//以下是數(shù)碼管的位選;
unsigned char weixuan[]={0xf7,0xfb,0xfd,0xfe,0x7f,0xbf,0xdf,0xef};
//unsigned char weixuan[]={0xef,0xdf,0xbf,0x7f,0xfe,0xfd,0xfb,0xf7};
unsigned char shuzhu0[8]={0,0,0,0,0,0,0,0};
unsigned char shuzhu1[8]={0,0,0,0,0,0,0,0};
unsigned int count,count0,count1;
unsigned char second,minute,hour,t;
unsigned char day,month,year;
bit flag,flag0;
sbit PR=P3^7;
//以下是延時程序
void delay(void)
{
unsigned char i,j;
for(i=20;i>0;i--)
for(j=248;j>0;j--);
}
//主函數(shù)
void main(void)
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
ET0=1;
EA=1;
TR0=1;
flag=0;
P1_1=1;
P1_0=0;
flag0=1;
while(1)
{
/*********************報時程序*****************************/
if(((minute==30)||(minute==0))&&(count<4000)&&(second==0)) P1_3=1;
else P1_0=0;
//語音程序
if(P3_5==0)
{
delay();
if(P3_5==0)
{
PR=0;
P1_7=0;
P1_6=0;
}
while(P3_5==0);
P1_7=1;
P1_6=1;
}
if(P3_6==0)
{
delay();
if(P3_6==0)
{ PR=1;
P1_7=0;
P1_6=0;
}
while(P3_6==0);
P1_7=1;
P1_6=1;
}
/********當這個鍵按下P1_0=0時才能調整時間當P1_0=1時不能調整時間日期***************************************/
if(P3_4==0)
{
delay();
if(P3_4==0)
{
P1_1=~P1_1;
if(P1_1==1) flag0=1; else if(P1_1==0) flag0=0;
}
while(P3_4==0);
}
/***************時間\日期切換程序***********************************/
if(P3_0==0)
{
delay();
if(P3_0==0)
{
flag=~flag;
}
while(P3_0==0);
}
/***************秒\天調整程序***********************************************/
if((P3_1==0)&&(flag==0)&&( P1_1==0))
{
delay();
if((P3_1==0)&&(flag==0)&&( P1_1==0))
{
second++;
if(second==60)
{
second=0;
}
while(P3_1==0);
}
}
else if((P3_1==0)&&(flag==1)&&( P1_1==0))
{
delay();
if((P3_1==0)&&(flag==1)&&( P1_1==0))
{
day++;
if(day==32)
{
day=0;
}
while(P3_1==0);
}
}
/*****************分\月調整程序****************************/
if((P3_2==0)&&(flag==0)&&( P1_1==0))
{
delay();
if((P3_2==0)&&(flag==0)&&( P1_1==0))
{
minute++;
if(minute==60)
{
minute=0;
}
while(P3_2==0);
}
}
else if((P3_2==0)&&(flag==1)&&( P1_1==0))
{
delay();
if((P3_2==0)&&(flag==1)&&( P1_1==0))
{
month++;
if( month==13)
{
month=0;
}
while(P3_2==0);
}
}
/*************時\年調整程序*************************************/
if((P3_3==0) &&(flag==0)&&( P1_1==0))
{
delay();
delay();
if((P3_3==0) &&(flag==0)&&( P1_1==0))
{
hour++;
if(hour==24)
{
hour=0;
}
while(P3_3==0);
}
}
else if((P3_3==0) &&(flag==1)&&( P1_1==0))
{
delay();
if((P3_3==0) &&(flag==1)&&( P1_1==0))
{
year++;
if(year==99)
{
year=0;
}
while(P3_3==0);
}
}
/*****************************************************/
}
}
/**************中斷***************************************/
void t0(void) interrupt 1 using 0
{
count0++;
if(count0==8)
{
count0=0;
if(flag==1) {P0=display[shuzhu1[count1]];}
else P0=display[shuzhu0[count1]];
P2=weixuan[count1];
count1++;
if(count1==8)
{
count1=0;
}
}
if(flag0==1)
{
count++;
if(count==4000)
{
count=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)
{
hour=0;
day++;
if(day==32)
{
day=0;
month++;
if(month==13)
{
month=0;
year++;
if(year==99)
{
year=0;
second=0;
minute=0;
hour=0;
day=0;
month=0;
}
}
}
}
}
}
}
}
/*************************時間顯示數(shù)組****************************/
shuzhu0[0]=second%10;
shuzhu0[1]=second/10;
shuzhu0[3]=minute%10;
shuzhu0[4]=minute/10;
shuzhu0[6]=hour%10;
shuzhu0[7]=hour/10;
shuzhu0[2]=17;
shuzhu0[5]=17;
/***********年月顯示數(shù)組******************************************/
shuzhu1[0]=day%10;
shuzhu1[1]=day/10;
shuzhu1[3]=month%10;
shuzhu1[4]=month/10;
shuzhu1[6]=year%10;
shuzhu1[7]=year/10;
shuzhu1[2]=16;
shuzhu1[5]=18;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -