旋转时钟程序.docx
《旋转时钟程序.docx》由会员分享,可在线阅读,更多相关《旋转时钟程序.docx(18页珍藏版)》请在冰豆网上搜索。
旋转时钟程序
旋转时钟
#include
sbitgate11=P3^0;
sbitgate12=P3^1;
unsignedcharBUFFER[]={0,0,0,0,1,1,7};
unsignedcharM[]={31,28,31,30,31,30,31,31,30,31,30,31};
unsignedcharmaxnum[]={59,23,31,12,99};
unsignedcharminnum[]={0,0,1,1,0};
unsignedcharyy[34];
unsignedcharcodeNUM1[]=
{
0x80,0x7F,0xC0,0xFF,0x40,0x90,0x40,0x8C,//-0-
0x40,0x82,0xC0,0xFF,0x80,0x7F,0x00,0x00,
0x00,0x00,0x00,0x81,0x80,0x81,0xC0,0xFF,//-1-
0xC0,0xFF,0x00,0x80,0x00,0x80,0x00,0x00,
0x80,0xE0,0xC0,0xF0,0x40,0x98,0x40,0x8C,//-2-
0x40,0x86,0xC0,0xC3,0x80,0xC1,0x00,0x00,
0x80,0x40,0xC0,0xC0,0x40,0x84,0x40,0x84,//-3-
0x40,0x84,0xC0,0xFF,0x80,0x7B,0x00,0x00,
0x00,0x0C,0x00,0x0E,0x00,0x0B,0x80,0x89,//-4-
0xC0,0xFF,0xC0,0xFF,0x00,0x88,0x00,0x00,
0xC0,0x47,0xC0,0xC7,0x40,0x84,0x40,0x84,//-5-
0x40,0x8C,0x40,0xFC,0x40,0x78,0x00,0x00,
0x00,0x7F,0x80,0xFF,0xC0,0x84,0x40,0x84,//-6-
0x40,0x84,0x00,0xFC,0x00,0x78,0x00,0x00,
0xC0,0x00,0xC0,0x00,0x40,0xF0,0x40,0xF8,//-7-
0x40,0x0C,0xC0,0x07,0xC0,0x03,0x00,0x00,
0x80,0x7B,0xC0,0xFF,0x40,0x84,0x40,0x84,//-8-
0x40,0x84,0xC0,0xFF,0x80,0x7B,0x00,0x00,
0x80,0x03,0xC0,0x87,0x40,0x84,0x40,0x84,//-9-
0x40,0xC4,0xC0,0x7F,0x80,0x3F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,//-:
-
0x00,0x63,0x00,0x00,0x00,0x00,0x00,0x00,
};
unsignedcharcodeNUM2[]=
{
0x00,0x00,0x7f,0x80,0xff,0xc0,0x82,0x40,//-0-
0x8c,0x40,0x90,0x40,0xff,0xc0,0x7f,0x80,
0x00,0x00,0x00,0x00,0x20,0x40,0x60,0x40,//-1-
0xff,0xc0,0xff,0xc0,0x00,0x40,0x00,0x40,
0x00,0x00,0x41,0xc0,0xc3,0xc0,0x86,0x40,//-2-
0x8c,0x40,0x98,0x40,0xf0,0xc0,0x60,0xc0,
0x00,0x00,0x40,0x80,0xc0,0xc0,0x88,0x40,//-3-
0x88,0x40,0x88,0x40,0xff,0xc0,0x77,0x80,
0x00,0x00,0x0c,0x00,0x1c,0x00,0x34,0x00,//-4-
0x64,0x40,0xff,0xc0,0xff,0xc0,0x04,0x40,
0x00,0x00,0xf8,0x80,0xf8,0xc0,0x88,0x40,//-5-
0x88,0x40,0x8c,0x40,0x8f,0xc0,0x87,0x80,
0x00,0x00,0x3f,0x80,0x7f,0xc0,0xc8,0x40,//-6-
0x88,0x40,0x88,0x40,0x0f,0xc0,0x07,0x80,
0x00,0x00,0xc0,0x00,0xc0,0x00,0x83,0xc0,//-7-
0x87,0xc0,0x8c,0x00,0xf8,0x00,0xf0,0x00,
0x00,0x00,0x77,0x80,0xff,0xc0,0x88,0x40,//-8-
0x88,0x40,0x88,0x40,0xff,0xc0,0x77,0x80,
0x00,0x00,0x70,0x00,0xf8,0x40,0x88,0x40,//-9-
0x88,0x40,0x88,0xc0,0xff,0x80,0x7f,0x00,
0x00,0x00,0x00,0xc0,0x01,0x80,0x03,0x00,//-/-
0x06,0x00,0x0c,0x00,0x18,0x00,0x30,0x00,
};
unsignedcharcodeHZ_12[]=
{
0x80,0x00,0x88,0x1F,0x30,0x48,0x00,0x24,//"调"
0xF0,0x1F,0x10,0x01,0x50,0x1D,0xF0,0x15,
0x50,0x1D,0x10,0x41,0xF8,0x7F,0x10,0x00,
0x00,0x02,0x00,0x41,0x80,0x41,0x60,0x31,//"分"
0x18,0x0F,0x00,0x01,0x00,0x21,0x38,0x41,
0x40,0x3F,0x80,0x00,0x00,0x01,0x00,0x01,
0xE0,0x1F,0x20,0x09,0x20,0x09,0x20,0x09,//"时"
0xE0,0x1F,0x40,0x00,0x40,0x01,0x40,0x26,
0x40,0x40,0xF8,0x7F,0x40,0x00,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x3F,//"日"
0x10,0x11,0x10,0x11,0x10,0x11,0x10,0x11,
0x10,0x11,0xF8,0x3F,0x10,0x00,0x00,0x00,
0x00,0x40,0x00,0x20,0x00,0x10,0xF8,0x0F,//"月"
0x48,0x02,0x48,0x02,0x48,0x22,0x48,0x42,
0x48,0x42,0xF8,0x3F,0x00,0x00,0x00,0x00,
0x80,0x04,0x40,0x04,0x20,0x04,0x98,0x07,//"年"
0x90,0x04,0x90,0x04,0xF0,0x7F,0x90,0x04,
0x90,0x04,0x98,0x04,0x90,0x04,0x10,0x04
};
unsignedintdisp1,disp2,key1,key2,key;
unsignedintii,jj;
unsignedinti,w,n,xz,CM,TZ,BZ;
voidDelay(unsignedintms){
ms=ms*3;
while(--ms);
}
voidnum_led(intaa,intbb)
{
intkk;
for(kk=0;kk<8;kk++){
gate11=key1;gate12=key2;
P2=~NUM1[aa+kk*2];P1=~NUM1[aa+1+kk*2];
Delay(20);
P1=0xff;P2=0xff;
gate11=key2;gate12=key1;
P2=~NUM2[bb+15-kk*2];P1=~NUM2[bb+14-kk*2];
Delay(20);
P1=0xff;P2=0xff;
}
}
voiddisplay_clock(void)
{
key1=key;key2=!
key;
disp1=BUFFER[3]/10;disp2=BUFFER[4]-(BUFFER[4]/10)*10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
disp1=BUFFER[3]-disp1*10;disp2=BUFFER[4]/10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
ii=160;jj=160;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
disp1=BUFFER[2]/10;disp2=BUFFER[5]-(BUFFER[5]/10)*10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
disp1=BUFFER[2]-disp1*10;disp2=BUFFER[5]/10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
ii=160;jj=160;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
disp1=BUFFER[1]/10;disp2=BUFFER[6]-(BUFFER[6]/10)*10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
disp1=BUFFER[1]-disp1*10;disp2=BUFFER[6]/10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
}
voiddisplay_TZ(void)
{
gate11=key;gate12=!
key;
for(jj=0;jj<16;jj++){
P2=0xff;P1=0xff;
Delay(40);
}
for(jj=0;jj<12;jj++){
P2=~HZ_12[jj*2];P1=~HZ_12[1+jj*2];
Delay(40);
P1=0xff;P2=0xff;
}
for(jj=0;jj<12;jj++){
P2=~HZ_12[TZ*24+jj*2];P1=~HZ_12[TZ*24+1+jj*2];
Delay(40);
P1=0xff;P2=0xff;
}
for(jj=0;jj<8;jj++){
P2=~NUM1[160+jj*2];P1=~NUM1[160+1+jj*2];
Delay(40);
P1=0xff;P2=0xff;
}
disp1=BUFFER[TZ+1]/10;
for(jj=0;jj<8;jj++){
P2=~NUM1[disp1*16+jj*2];P1=~NUM1[disp1*16+1+jj*2];
Delay(40);
P2=0xff;P1=0xff;
}
Delay(60);
disp1=BUFFER[TZ+1]-disp1*10;
for(jj=0;jj<8;jj++){
P2=~NUM1[disp1*16+jj*2];P1=~NUM1[disp1*16+1+jj*2];
Delay(40);
P2=0xff;P1=0xff;
}
Delay(60);
}
voidintersvr0(void)interrupt0
{
key=!
key;
if(w==0)w=1;
}
voidintersvr1(void)interrupt2
{
TH1=0;TL1=0;
}
voidtimer1(void)interrupt3using1
{
}
voidtimer0(void)interrupt1using1
{
TH0=-(5000/256);
TL0=-(5000%256);
TR0=1;
BUFFER[0]=BUFFER[0]+1;
if(BUFFER[6]%4==0)M[1]=M[1]+1;
if(BUFFER[0]>201+xz){
BUFFER[0]=0;
BUFFER[1]=BUFFER[1]+1;
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;
BUFFER[4]=BUFFER[4]+1;
if(BUFFER[4]>M[BUFFER[5]-1]){
BUFFER[4]=1;
BUFFER[5]=BUFFER[5]+1;
if(BUFFER[5]>12){
BUFFER[5]=1;
BUFFER[6]=BUFFER[6]+1;
if(BUFFER[6]>99){
BUFFER[6]=0;
M[1]=M[1]-1;
}
}
}
}
}
}
}
}
voidJm(void)
{
unsignedintkk,mm;
CM=0x00;
for(kk=0;kk<30;kk++){
mm=0;
while((P3&0x80)==0x00){};
while((P3&0x80)==0x80){mm++;};
if((mm>350)&&(mm<100)){CM=0x00;break;};
yy[kk]=mm;
}
for(kk=17;kk<22;kk++){
CM=CM<<1;
if((yy[kk]>65)&&(yy[kk+8]<65)){CM=CM|0x01;}
else{if((yy[kk]>65)||(yy[kk+8]<65)){CM=0x00;break;}
}
}
}
voidmain(void)
{
xz=8;TZ=1;BZ=0;
key1=0;key2=1;
EA=1;
IT0=1;EX0=1;
EX1=1;
IT1=1;ET0=1;
TMOD=0x11;
TH0=-5000/256;TL0=-5000%256;
TR0=1;
TH1=0;TL1=0;
TR1=1;
for(;;){
w=0;CM=0;
Delay(50);
if(w==2){EX1=0;Jm();Delay(1200);EX1=1;w=0;};
if(BZ==1)if(w==1){display_TZ();n=1;}
if(BZ==0)if(w==1){display_clock();n=1;}
if(CM==9){BUFFER[1]=0;Delay(1200);BZ=!
BZ;w=0;CM=0;}
if(CM==11){Delay(1200);key=!
key;w=1;BZ=0;w=0;CM=0;}
if(CM==23)if(BZ==1){if(BUFFER[TZ+1] if(CM==19)if(BZ==1){if(BUFFER[TZ+1]>minnum[TZ-1])BUFFER[TZ+1]--;elseBUFFER[TZ+1]=maxnum[TZ-1];Delay(1200);w=0;CM=0;}
if(CM==31)if(BZ==1){if(TZ<5)TZ++;elseTZ=1;Delay(1200);w=0;CM=0;}
if(CM==15)if(BZ==1){if(TZ>1)TZ--;elseTZ=5;Delay(1200);w=0;CM=0;}
n++;if(n>10)w=1;
}
}
一。
旋转电机的制作
从制作成本与方便考虑,选用旧电脑用的大软驱上的直流无刷电机,只是对局部进行改造。
就是这种古董软驱
软驱上的直流无刷电机
拆开后的电机
仔细拆开直流电机,将带圆盘的铝轴从中开孔,让它刚好能插入一个插头。
将旋转轴加工成这样
装配好以后
按拆开时的顺序,反序将轴安装直流电机上。
电机装配完成后
用两片铜片做的电刷
电刷装好后的侧面图
将电路板上较突出的元件改焊在反面,
电机的电源接法。
从电路板标注的符号看,“+”为电源正,“G”为电源负,
“C”与“M”端分别与电源正相连匀可使电机运转
将一张旧唱片按电机座的位置开孔,而定位用的挡光板应根据电路板上感光组件的位置确定。
二。
电路板的制作
本制作品用51单片机控制,具体电原理图如下:
用Protel99设计制作了电路板。
最后得到完成的作品。
遥控器用的是松下车载机的,只用了其中的六个键。
四。
运行效果
从开机,调整到最后完成。
开机时
调时状态