創(chuàng)意設(shè)計(jì)之DIY搖擺LED時(shí)鐘
0x10,0x7E,0x90,0x90,0x40,0x00, // -f-45
0x19,0x25,0x25,0x25,0x1E,0x00, // -g-46
0xFE,0x10,0x20,0x20,0x1E,0x00, // -h-47
0x00,0x00,0x9E,0x00,0x00,0x00, // -i-48
0x00,0x01,0x11,0x9E,0x00,0x00, // -j-49
0xFE,0x08,0x14,0x22,0x02,0x00, // -k-50
0x00,0x82,0xFE,0x02,0x00,0x00, // -l-51
0x1E,0x20,0x1E,0x20,0x1E,0x00, // -m-52
0x20,0x1E,0x20,0x20,0x1E,0x00, // -n-53
0x1C,0x22,0x22,0x22,0x1C,0x00, // -o-54
0x3F,0x24,0x24,0x24,0x18,0x00, // -p-55
0x18,0x24,0x24,0x24,0x3F,0x00, // -q-56
0x20,0x1E,0x20,0x20,0x10,0x00, // -r-57
0x12,0x2A,0x2A,0x2A,0x24,0x00, // -s-58
0x20,0xFC,0x22,0x22,0x24,0x00, // -t-59
0x3C,0x02,0x02,0x3C,0x02,0x00, // -u-60
0x38,0x04,0x02,0x04,0x38,0x00, // -v-61
0x3C,0x02,0x3C,0x02,0x3C,0x00, // -w-62
0x22,0x14,0x08,0x14,0x22,0x00, // -x-63
0x39,0x05,0x05,0x09,0x3E,0x00, // -y-64
0x22,0x26,0x2A,0x32,0x22,0x00, // -z-65
};
unsigned int TZ,Ti;
unsigned char ii,jj,nn,mm,tt, Ms;
/*延時(shí)函數(shù)*/
void DelayMs(unsigned int msec)
{
unsigned int x,y;
for(x=0; x=msec;x++)
{
for(y=0;y=110;y++);
}
}
/*鍵盤去抖處理函數(shù)*/
unsigned char ChKey(bit Key)
{
if(Key==0){
DelayMs(30);
if(Key==0) return(1);
}
}
/*定時(shí)器中斷0處理(時(shí)鐘)函數(shù)*/
void timer0(void) interrupt 1 using 1
{
TH0=-(5000/256);
TL0=-(5000%256);
TR0=1;
BUFFER[0]=BUFFER[0]+1;
if (BUFFER[0]>201){
BUFFER[0]=0; BUFFER[1]=BUFFER[1]+1;
Ms=!Ms;
if (BUFFER[1]==60){
BUFFER[1]=0;BUFFER[2]=BUFFER[2]+1;
if (BUFFER[2]==60){
BUFFER[2]=0;BUFFER[3]=BUFFER[3]+1;
if (BUFFER[3]==24) BUFFER[3]=0;
}
}
}
}
/*定時(shí)器中斷1處理(LED驅(qū)動(dòng))函數(shù)*/
void timer1(void) interrupt 3 using 1
{
TH1=(Ti+tt*15)/256; TL1=(Ti+tt*15)%256;
if((put1==1)(ii7)(Ms*w[ii]==0)) P2=~ASCIIDOC[v[ii]*6+jj]; else P2=0xff;
jj++; tt++;
if(jj>5) {ii++; jj=0;};
if(ii>10) {ii=0;put1=~put1; put2=~put2;tt=0;}
}
/*主程序*/
void main(void)
{
Ms=1;
Ti=-2100; //根據(jù)實(shí)際調(diào)整
mm=14;
put1=0;put2=1;
/*初始化定時(shí)中斷0*/
TMOD=0x11;
TH0=-5000/256; TL0=-5000%256;
TR0=1;ET0=1;
/*初始化定時(shí)中斷1*/
TH1=Ti/256; TL1=Ti%256;
TR1=1;ET1=1;
/* 七個(gè)顯示位置,中間為":" 符 */
v[0]=10;
v[1]=10;
v[2]=10;
v[3]=13;
v[4]=10;
v[5]=10;
v[6]=10;
/*正常運(yùn)行狀態(tài),讓中間":"符閃現(xiàn)*/
w[1]=0;
w[2]=0;
w[3]=1;
w[4]=0;
w[5]=0;
/*搖擺棒初始啟動(dòng)*/
do {
mm--;
DelayMs(120+mm*5);
put1=~put1; put2=~put2;
}while(mm>0);
/*啟動(dòng)顯示*/
ii=0;jj=0;
EA=1;
/*正式運(yùn)行*/
for(;;){
while(1){
/*顯示時(shí)和分*/
v[1]=BUFFER[3]/10;
v[2]=BUFFER[3]-v[1]*10;
v[4]=BUFFER[2]/10;
v[5]=BUFFER[2]-v[4]*10;
/*按鍵處理*/
if(ChKey(set0)==1){ //調(diào)整項(xiàng)鍵
if(TZ2) TZ++; else TZ=0;
/*閃現(xiàn)調(diào)整項(xiàng)*/
switch(TZ){
case 0:w[1]=0;w[2]=0;w[3]=1;w[4]=0;w[5]=0;break;//正常時(shí)秒閃
case 1:w[1]=0;w[2]=0;w[3]=0;w[4]=1;w[5]=1;break;//調(diào)分時(shí)分閃
case 2:w[1]=1;w[2]=1;w[3]=0;w[4]=0;w[5]=0;break;//調(diào)時(shí)時(shí)時(shí)閃
}
};
DelayMs(300);
if(ChKey(set1)==1){ if(BUFFER[TZ+1]
// 加法鍵
if(ChKey(set2)==1){ if(BUFFER[TZ+1]>0) BUFFER[TZ+1]--; else BUFFER[TZ+1]=maxnum[TZ-1];DelayMs(300);};
// 減法鍵
DelayMs(300);
}
}
}
四. 結(jié)語
本制作的最大問題是操聲和振動(dòng)問題,盡管做了努力,還是沒有完全解決,還有改善余地。由于設(shè)計(jì)沒有考慮回?cái)[時(shí)的顯示,顯示有明顯閃爍現(xiàn)象,也需要進(jìn)一步完善。
DIY機(jī)械鍵盤相關(guān)社區(qū):機(jī)械鍵盤DIY
評(píng)論