單片機(jī)設(shè)計(jì)LCD數(shù)字鐘(萬年歷)
case 0xd0: //按下確認(rèn)鍵
{
k=0;
TR0=1;
n=-3;
m=-3;
f=0;
} break;
case 0xb0: //按下加1鍵
{
if(k==1)
{
if(f==0)
{
if(n==0){year++;if(year==100) year=0;}
else if(n==3) {month++;if(month==13) month=1;}
else {day++;if(day==32) day=1;}
dispd(); //調(diào)用第一行顯示函數(shù)
lcd_w_cmd(0x0d); //光標(biāo)閃爍
lcd_w_cmd(0x86+n);//返回設(shè)置值顯示地址
}
else
{
if(m==0){hour++;if(hour==24) hour=0;}
else if(m==3) {min++;if(min==60) min=0;}
else if(m==6){sec++;if(sec==60) sec=0;}
else {week++;if(week==7) week=0;}
dispt(); //調(diào)用第二行顯示函數(shù)
lcd_w_cmd(0x0d); //光標(biāo)閃爍
lcd_w_cmd(0xc4+m);//返回設(shè)置值顯示地址
}
}
} break;
case 0x70: //按下減1鍵
{
if(k==1)
{
if(f==0)
{
if(n==0){year--;if(year
/*****定時(shí)中斷函數(shù)*****/
void timer0() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
count++;
if(count==10)
{
count=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
week++;
day++;
if(week==7) week=0;
if(day==29month==2year%4!=0) {day=1;month++;}
else if(day==30month==2year%4==0) {day=1;month++;}
else if(day==31(month==4||month==6||month==9||month==11)) {day=1;month++;}
else if(day==32(month==1||month==3||month==5||month==7||month==8||month==10||month==12)) {day=1;month++;}
if(month==13)
{
month=1;
year++;
if(year==100) year=0;
}
}
}
}
}
}
/*按鍵掃描函數(shù)*/
unsigned char keys()
{
unsigned char cod,del;
P3=0xf0;
cod=P30xf0; //讀入P3口鍵值
if(cod!=0xf0) //先檢測(cè)有無按鍵按下
{
delay(100); //去抖
if(cod!=0xf0)
{
cod=P30xf0; //讀入鍵值
do //等待鍵釋放
{
P3=0xf0;
del=P30xf0;
}while(del!=0xf0);
return(cod);//返回鍵值
}
}
return(0xf0); //返回該值
}
/*第一行顯示日期函數(shù)*/
void dispd()
{
lcd_w_cmd(0x0c); //設(shè)置光標(biāo)不顯示、不閃爍
delay(20);
lcd_w_cmd(0x83); //第一行起始顯示地址0x80+0x03
delay(20);
lcd_w_dat('2');
delay(2);
lcd_w_dat('0');
delay(2);
lcd_w_dat(lcdd[year/10]);
delay(2);
lcd_w_dat(lcdd[year%10]);
delay(2);
lcd_w_dat('-');
delay(2);
lcd_w_dat(lcdd[month/10]);
delay(2);
lcd_w_dat(lcdd[month%10]);
評(píng)論