这个实验利用lcd12864实现一个综合性的时钟系统,详情见附件
平台:FDR-1 51 开发板
主程序代码:
#include <reg52.h>
#include <intrins.h>
#include<string.h>
bit clock="0";
sbit ACC7=ACC^7;
sbit ACC0=ACC^0;
bit flag="0";
unsigned char k="0";
bit i="1";
void play_respond();
void move();
unsigned char hour_sound,minute_sound;
unsigned char print[7]={33,35,18,11,2,4,97};
unsigned char temp[2],Count;
void beeping(unsigned char frequence,unsigned char length);
void Delay_xMs(unsigned char x);
void getch();
void showtime(unsigned char *print);
void change() ////修改时间
{
unsigned char i="0",temp[7],temp3[3],x,y;
v_BurstR1302T(print);
for(i=0;i<7;i++)
{temp=print;}
i="0";
showtime(temp);
while(k!=15)
{
getch();
if(flag==1&&k==13) {flag=0;i++;i=i%7;k=0;}
if(flag==1&&k==9){flag=0;temp[6-i]++;}
if(flag==1&&k==8){flag=0;temp[6-i]--; }
if(flag==1&&k==11){flag=0;clock=1;}
temp3[0]=time[temp[6-i]/10];
temp3[1]=time[temp[6-i]%10];
temp3[2]='\0';
switch(i)
{case 0:{x=0;y=1;break;}
case 1:{ x="2",y=0;break;}
case 2: {x=0;y=3;break;}
case 3:{x=0;y=5;break;}
case 4: {x=2;y=1;break;}
case 5: {x=2;y=3;break;}
case 6: {x=2;y=5;break;}
}
showtime(temp) ;
}
if(clock==0)v_BurstW1302T(temp);
else
{hour_sound=temp[2];minute_sound=temp[1];play_respond();}
k="0";flag=0;
}
void move()
{
unsigned char i="0";
while(1)
{ getch();
if(flag==1&&k==13)
break;
i++;i=i%2;
PutBMP2(0,0,6, 32,bmp6,i);delay(400);
PutBMP2(3,0,6, 32,bmp7,i);delay(400);
flag="0";k=0; LcmClearBMP();
}
}
void main( void )
{ unsigned char i;
unsigned char program =0;
unsigned char(* bmp[8])[256]={ &bmp0,&bmp1,&bmp2,&bmp3,&bmp4,&bmp5,&bmp6,&bmp7};
delay(100);
LcmInit();
LcmClearTXT();
LcmClearBMP();
PutBMP(bmp8);
psb="0";
rst="1";
Time0_Init();
LcmClearTXT();
PutBMP(bmp8);
delay(1000);
v_BurstW1302T(print);
LcmClearBMP();
for(i=0;i<4;i++){PutBMP2(1+i*4,0,5, 32,bmp,1);}
PutBMP2(0,0,5, 32,bmp[0],0);
while(1)
{ //////////////////////////
/*背景程序 */
reach_time();
///////////////////////
i="i"%4;
getch();
if(flag==1)
{ flag="0";
if(k==12){ PutBMP2(i*4,0,5, 32,bmp,1);i++;}
if(k==15) {PutBMP2(i*4,0,5, 32,bmp,1);i--;}
i="i"%4;PutBMP2(i*4,0,5, 32,bmp,0);
if(k==13){program=1;k=0;}
}
if(program==1)
{
program="0";
switch (i)
{ unsigned int i="0";
case 0: { LcmClearBMP();
PutBMP2(i*4,0,5, 32,bmp[4],1);
Play_Song();
k=0; flag="0"; for(i=0;i<4;i++){PutBMP2(i*4,0,5, 32,bmp,1); }
break;
}
case 1: {
LcmClearBMP();
while(k!=13){for(i=0;i<16;i++){getch();if(k!=13){PutBMP2(i,0,5, 32,bmp1,i%2); getch();delay(1000); LcmClearBMP();} else {flag=1;break;}if(flag==1)break;}}k=0; flag="0"; for(i=0;i<4;i++){PutBMP2(i*4,0,5, 32,bmp,1); }break;
}
case 2: {
LcmClearBMP();
move();
change() ;
flag=0;
k=0;
LcmClearTXT();
for(i=0;i<4;i++){PutBMP2(i*4,0,5, 32,bmp,1); } break;
}
case 3: {
LcmClearBMP();
while(1)
{
i++;
if(i==500){v_BurstR1302T(print);i=0;showtime(print);}
getch();
if(k==13)break;
}
flag=0;k=0;LcmClearTXT();for(i=0;i<4;i++){PutBMP2(i*4,0,5, 32,bmp,1); } break;
}
}
}
}
}
用户175696 2008-11-17 17:35