#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit s1=P1^0;
sbit s2=P1^1;
sbit s3=P1^2;
sbit s4=P1^3;
sbit s5=P1^4;
sbit s6=P1^5;
sbit lcdrs=P1^6;
sbit lcden=P1^7;
char num,boxing,u,zhankong=32;
int pinlv=200,bujin=100,bujin1=100;
uchar geshu=1;
uchar code table[]="0123456789";
uchar code table1[]="pinlv:boxing:";
unsigned long int m;
int n=0;
float hc=0;
int a,b,h,num1;
uchar code sin[64]={
135,145,158,167,176,188,199,209,218,226,234,240,245,249,252,254,254,253,251,247,243,237,230,222,213,204,193,182,170,158,
146,133,121,108,96,84,72,61,50,41,32,24,17,11,7,3,1,0,0,2,5,9,14,20,28,36,45,55,66,78,90,102,114,128
};
uchar juxing[64]={255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uchar code juchi[64]={
0,4,8,12,16,20,24,28,32,36,40,45,49,53,57,61,65,69,73,77,81,85,89,93,97,101,105,109,113,117,121,125,130,134,138,142,
146,150,154,158,162,166,170,174,178,182,186,190,194,198,202,206,210,215,219,223,227,231,235,239,243,247,251,255
};
uchar code sanjiao[64]={
0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,
248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0
};
void delay(uint xms)
{
int a,b;
for(a=xms;a>0;a--)
for(b=110;b>0;b--);
}
void write_com(uchar com)
{
lcdrs=0;
P0=com;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
void write_date(uchar date)
{
lcdrs=1;
P0=date;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
void init_lcd()
{
lcden=0;
write_com(0x0f);
write_com(0x38);
write_com(0x01);
write_com(0x0c);
write_com(0x06);
write_com(0x80);
}
void initclock()
{
uint i;
TMOD=0x01;
TH0=a;
TL0=b;
EA=1;
ET0=1;
TR0=1;
for(i=6;i<13;i++)
{
write_date(table1[i]);
delay(2);
}
write_com(0x80+0x40);
for(i=0;i<6;i++)
{
write_date(table1[i]);
delay(2);
}
write_com(0x80+7);
write_date('s');
write_date('i');
write_date('n');
write_date(' ');
write_date(' ');
write_date(' ');
write_date(' ');
write_com(0x80+0x40+0xa);
write_date(' ');
write_date('1');
write_date('0');
write_date('H');
delay(2);
write_date('Z');
delay(2);
}
void display()
{
uchar shiwan,wan,qian,bai,shi,ge;
long a=0;
a=pinlv;
shiwan = a/100000;
wan=a/10000;
qian=a/1000%10;
bai=a/100%10;
shi=a%100/10;
ge=a%100%10;
write_com(0x80+0x40+8);
write_date(table[shiwan]);
delay(2);
write_date(table[wan]);
delay(2);
write_date(table[qian]);
delay(2);
write_date(table[bai]);
delay(2);
write_date(table[shi]);
delay(2);
write_date(table[ge]);
delay(2);
write_date('H');
delay(2);
write_date('Z');
delay(2);
if(boxing==0)
{
write_com(0x80+7);
write_date('s');
write_date('i');
write_date('n');
write_date(' ');
write_date(' ');
write_date(' ');
write_date(' ');
}
if(boxing==1)
{
write_com(0x80+7);
write_date('j');
write_date('u');
write_date('x');
write_date('i');
write_date('n');
write_date('g');
}
if(boxing==2)
{
write_com(0x80+7);
write_date('s');
write_date('a');
write_date('n');
write_date('j');
write_date('i');
write_date('a');
write_date('o');
}
if(boxing==3)
{
write_com(0x80+7);
write_date('j');
write_date('u');
write_date('c');
write_date('h');
write_date('i');
write_date(' ');
write_date(' ');
}
}
uchar keyscan()
{
if(s1==0)
{
EA=0;
delay(1);
if(s1==0)
{
while(!s1);
pinlv+=bujin;
if(pinlv>30000)
{
pinlv=30000;
}
geshu=pinlv/120+1;
if(pinlv>960)
{
geshu=8;
bujin=100;
bujin1=100;
}
if(pinlv>1080) geshu=10;
if(pinlv>2000) geshu=11;
hc=15625/pinlv;
m=hc*geshu;
m-=54;
m/=15;
EA=1;
display();
}
}
if(s2==0)
{
delay(1);
if(s2==0)
{
EA=0;
while(!s2);
pinlv-=bujin;
if(pinlv<0)
{
pinlv=0;
}
geshu=pinlv/120+1;
if(pinlv>960)
{
geshu=8;
bujin=100;
bujin1=100;
}
if(pinlv>1080) geshu=10;
if(pinlv>2000) geshu=11;
if(pinlv<=3100)
{hc=15625/pinlv;
m=hc*geshu;
m-=54;
m/=15;}
else
{
m=65276+(pinlv-480);
}
display();
EA=1;
}
}
if(s3==0)
{
delay(1);
if(s3==0)
{
EA=0;
while(!s3);
boxing++;
if(boxing==4)
{
boxing=0;
}
display();
EA=1;
}
}
if(s6==0)
{
delay(1);
if(s6==0)
{
EA=0;
while(!s6);
zhankong +=4;
if(zhankong>63) zhankong=32;
EA=1;
}
}
if(s5==0)
{
delay(1);
if(s5==0)
{
EA=0;
while(!s5);
zhankong -=4;
if(zhankong<0) zhankong=32;
EA=1;
}
}
return 1;
}
void change()
{
int i,j;
for(i=0;i<zhankong;i++)
{
juxing[i] = 255;
}
for(j=zhankong;j<63;j++)
{
juxing[j] = 0;
}
}
void bujindisplay()
{
uint bai,shi,ge;
bai=bujin1/100;
shi=bujin1%100/10;
ge=bujin1%100%10;
write_com(0x80+6);
write_date(table[bai]);
delay(1);
write_date(table[shi]);
delay(1);
write_date(table[ge]);
delay(1);
}
void bujinjiance()
{
if(s4==0)
{
delay(3);
if(s4==0)
{
while(!s4);
h++;
if(h==1)
{
write_com(0x01);
write_com(0x80);
write_date('b');delay(1);
write_date('u');delay(1);
write_date('j');delay(1);
write_date('i');delay(1);
write_date('n');delay(1);
write_date(':');delay(1);
bujin1=bujin;
bujindisplay();
}
if(h==2)
{
h=0;
bujin=bujin1;
init_lcd();
initclock();
display();
}
}
}
if(h==1)
{
if(s1==0)
{
delay(5);
if(s1==0)
{
while(!s1);
bujin1++;
if(bujin1==101)
{
bujin1=100;
}
bujindisplay();
}
}
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
bujin1--;
if(bujin1==0)
{
bujin1=100;
}
bujindisplay();
}
}
}
}
void main()
{
init_lcd();
hc=15625/pinlv;
m=hc*geshu;
m-=54;
m/=15;
initclock();
display();
while(1)
{
switch(boxing)
{
case 0: P2=sin[u];
break;
case 1: P2=juxing[u];change();
break;
case 2: P2=sanjiao[u];
break;
case 3: P2=juchi[u];
break;
}
u+=geshu;
n=m;
if(u>=64)
{
u=0;
}
while(n-->0);
}
}
void T0_time()interrupt 1
{
TH0=0;
TL0=0;
if(h==0)
{
keyscan();
}
bujinjiance();
}
2021-06-18
最新推荐文章于 2024-07-26 08:38:18 发布