|
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
#include "ziku.h"
uchar state=0;
bit tflg;
sbit cp=P3^5;
sbit dir=P2^0;
sbit rl=P2^1;
uchar b;
uchar strl[6];
uchar ktime,ktmp;
bit qd,up,dn,lsh,rsh,ent;
uchar dp;
uint cpn;
#include "l.h"
qidong()
{
qd=~qd;
if(qd)
{
zx[0]=zx[1]=zx[2]=zx[3]=zx[4]=zx[5]=0;
dir=1;
cpn=1000;
}
else
{
zx[0]=zx[1]=zx[2]=zx[3]=zx[4]=zx[5]=16;
lcdclr();
wrstring(0,0,4,hy);
cpn=0;
}
}
key()
{
P1=0XF0;
if(P1!=0XF0)
{
if(ktime<=10) ktime++;
if(ktime==10)
{
ktmp=P1;
P1=ktmp|0x0f;
ktmp=P1;
switch(ktmp)
{
case 0x77:qidong();break;
case 0x7b:if(qd) state=2;break;
case 0x7d:if(qd) up=1;break;
case 0x7e: if(qd) ent=1;break;
case 0xbb:if(qd) lsh=1;break;
case 0xbe: if(qd) rsh=1;break;
case 0xdd:if(qd) dn=1;break;
default: break;
}
}
}
else ktime=0;
}
main()
{ uint tms,a;
// uint tms4;
uchar ts,tmin,tho;
uchar k,t;
uint atmp0=0;
init();
lcdinit();
lcdclr();
wrstring(0,0,4,hy);
while(1)
{
if(tflg)
{
tflg=0;
if(qd)
{
if(cpn!=0)
{
cp=~cp;
if(state!=0) cpn--;
}
if(tms++==1000)
{
tms=0;
if(ts++==60)
{
ts=0;
if(tmin++==60)
{
tmin=0;
if(tho++==24)
tho=0;
}
}
zx[0]=ts%10;zx[1]=ts/10;
zx[2]=tmin%10;zx[3]=tmin/10;
zx[4]=tho%10;zx[5]=tho/10;
}
}
key();
switch (state)
{ case 0:
{
if(rl)
{
cpn=2800;
dir=0;
state=1;
}
if(tms==1)
{
lcdclr();
wrstring(0,0,2,shoudong);
wrstring(1,0,5,lddj);
wrnum(1,80,4,shuju);
}
}break;
case 1:
{ if(tms==400)
{ // tms1=0
lcdclr();
wrstring(0,0,2,shoudong);
wrstring(1,0,5,lddj);
wrnum(1,80,4,shuju);
}
if(cpn==0)
{ if(up)
{up=0;
a++;
cpn=280;
dir=0;
}
else if(dn)
{
dn=0;
if(a--==0) a=0;
dir=1;
cpn=280;
}
for(k=0;k<16;k++)
{
shuju[0][k]=number[a /100][k];
shuju[1][k]=number[a /10%10][k];
shuju[3][k]=number[a %10][k];
}
}
}break;
case 2:
{
if(up)
{
up=0;
if(dp--==0) dp=0;
}
if(dn)
{
dn=0;
if(dp++==2) dp=2;
}
if(ent)
{ ent=0;
switch(dp)
{
case 0: state=1;break;
case 1:state=3;break;
case 2:state=4;break;
default: break;
}
}
if(tms==20)
{
lcdclr();
wrstring(0,0,2,shoudong);
wrstring(1,0,2,zidong);
wrstring(2,0,4,dangqian);
}
}break;
case 3 :
{
if(tms==20)
{
lcdclr();
wrstring(0,0,2,zidong);
wrstring(1,0,5,lddj);
wrnum(1,80,4,shuju);
}
if(cpn==0)
{
ADC();
if(atmp>atmp0)
{
dir=0;
cpn=(atmp-atmp0)*280;
}
else
{
dir=1;
cpn=(atmp0-atmp)*280;
}
atmp0=atmp;
for(k=0;k<16;k++)
{
shuju[0][k]=number[atmp/100][k];
shuju[1][k]=number[atmp/10%10][k];
shuju[3][k]=number[atmp%10][k];
}
}
}
break;
case 4:
{
if(tms==220)
{ for(k=0;k<16;k++)
{
time[b][k]=number[strl[b]][k];
}
lcdclr();
wrnum(0,0,6,time);
}
if(rsh)
{
rsh=0;
if(b++==5) b=5;
}
if(lsh)
{
lsh=0;
if(b--==0) b=0;
}
if(up)
{
up=0;
if(t++==9) t=9;
strl[b]=t;
}
if(dn)
{
dn=0;
if(t--==0) t=0;
strl[b]=t;
}
// if(tms4++==2000)
{
// tms4=0;
if(ent)
{ ent=0;
tho=strl[0]*10+strl[1];
tmin=strl[2]*10+strl[3];
ts=strl[4]*10+strl[5];
state=2;
}
}
}
default: break;
}
}
}
}
void time0() interrupt 1
{
tflg=1;
display();
TH0=0XFC;
TL0=0X18;
} |
|