没有发现编译错误,下载程序如下:
#define uint unsigned int
#define uchar unsigned char
#define DUAN P0
#include <reg52.h>
unsigned char code tab[]={0xa0,0xbb,0x62,0x2a,0x39,0x2c,0x24,0xba,0x20,0x28,0xff};
unsigned char code tab_dian[]={0x80,0x9b,0x42,0x0a,0x19,0x0c,0x04,0x9a,0x00,0x08,0xdf};
uchar pdata tt[51];
uchar scale=20,rsd_sec;
char min,sec;
bit bdata flag_auto,ss,flag_bs,flag_rsd,flag_jiejin=1;
uchar flag_set=0;
uchar lum;
void delay(uchar i);
sbit LED = P3^4;
sbit change= P2^3;
sbit set = P2^2;
sbit add = P2^1;
sbit sub = P2^0;
sbit rsd = P3^6;
sbit jiejin=P3^5;
sbit buzz=P3^7;
sbit W0=P2^7;
sbit W1=P2^6;
sbit W2=P2^5;
sbit W3=P2^4;
void display()
{
if(flag_set==0)
{
DUAN=tab[min/10];
W0=0;
delay(1);
W0=1;
DUAN=tab_dian[min%10];
W1=0;
delay(1);
W1=1;
DUAN=tab[sec/10];
W2=0;
delay(1);
W2=1;
DUAN=tab[sec%10];
W3=0;
delay(1);
W3=1;
}
else if(flag_set==1)
{
if(ss==1)
{
DUAN=~tab[min/10];
W0=0;
delay(1);
W0=1;
DUAN=~tab_dian[min%10];
W1=0;
delay(1);
W1=1;
}
else
{
DUAN=~tab[10];
W0=0;
delay(1);
W0=1;
DUAN=~tab_dian[10];
W1=0;
delay(1);
W1=1;
}
DUAN=~tab[sec/10];
W2=0;
delay(1);
W2=1;
DUAN=~tab[sec%10];
W3=0;
delay(1);
W3=1;
}
else
{
DUAN=~tab[min/10];
W0=0;
delay(1);
W0=1;
DUAN=~tab_dian[min%10];
W1=0;
delay(1);
W1=1;
if(ss==1)
{
DUAN=~tab[sec/10];
W2=0;
delay(1);
W2=1;
DUAN=~tab[sec%10];
W3=0;
delay(1);
W3=1;
}
else
{
DUAN=~tab[10];
W2=0;
delay(1);
W2=1;
DUAN=~tab[10];
W3=0;
delay(1);
W3=1;
}
}
}
void KEY()
{
uint lum_mean,lum_all;
uchar b,c;
if(change==0)
{
delay(10);
if(change==0)
{
buzz=0;
flag_auto=!flag_auto;
if(flag_auto==1)
scale=20;
}
while(!change) display();buzz=1;
}
if(jiejin==0&&flag_jiejin==1)
{
buzz=0;
flag_jiejin=0;
}
if(jiejin!=flag_jiejin)
{
buzz=1;
flag_jiejin=1;
}
if(set==0)
{
delay(10);
if(set==0)
{
buzz=0;
flag_set++;
if(flag_set==3)
flag_set=0;
flag_bs=0;
}
while(!set) display(); buzz=1;
}
if(flag_set==1)
{
if(add==0)
{
delay(10);
if(add==0)
{
buzz=0;
min++;
if(min>=60)
min=0;
}
while(!add) display(); buzz=1;
}
if(sub==0)
{
delay(10);
if(sub==0)
{
buzz=0;
min--;
if(min>0)
min=59;
}
while(!sub) display(); buzz=1;
}
}
if(flag_set==2)
{
if(add==0)
{
delay(10);
if(add==0)
{
buzz=0;
sec++;
if(sec>=60)
sec=0;
}
while(!add) display(); buzz=1;
}
if(sub==0)
{
delay(10);
if(sub==0)
{
buzz=0;
sec--;
if(sec<0)
sec=59;
}
while(!sub) display(); buzz=1;
}
while(!sub);
}
if(flag_auto==0)
{
if(flag_rsd==1)
{
for(b=0;b<49;b++)
{
tt=tt[b+1];
}
for(c=0;c<50;c++)
{
lum_all=lum_all+tt[c];
}
lum_mean=lum_all/50;
if(lum_mean<=30) scale=1;
else if(lum_mean>=150) scale=41;
else scale=((lum_mean-30)/3)+1;
}
else
scale=1;
}
else
{
if(flag_set==0)
{
if(add==0)
{
delay(10);
if(add==0)
{
// buzz=0;
scale++;
if(scale>=41)
scale=41;
display();
}
}
if(sub==0)
{
delay(10);
if(sub==0)
{
scale--;
if(scale>1)
scale=1;
display();
}
}
}
}
}
void init()
{
TMOD=0x11;
TH1=0x3c;
TL1=0xb0;
TH0=0xff;
TL0=0xe7;
ET0=1;
ET1=1;
EA=1;
TR0=1;
TR1=0;
}
void main()
{
init();
flag_auto=1;
rsd=0;
delay(500);
while(1)
{
KEY();
display();
}
}
void delay(uchar i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void time0() interrupt 1
{
uchar n;
TH0=0xff;
TL0=0xe7;
n++;
if(n>scale)
{
LED=1;
}
else if(n<=scale)
{
LED=0;
}
if(n==40)
{
n=0;
}
else ;
}
void time1() interrupt 3
{
uchar m;
TH1=0x3c;
TL1=0xb0;
m++;
if((m==10||m==20)&&flag_set!=0)
{
ss=!ss;
}
if(m==20)
{
m=0;
if(rsd==0)
rsd_sec++;
if(rsd_sec<=30&&rsd==1)
{
rsd_sec=0;
flag_rsd=1;
}
else if(rsd_sec>30&&rsd==0)
{
flag_rsd=0;
rsd_sec=0;
}
if(flag_set==0&&flag_bs==0&&((min+sec)!=0))
{
sec--;
if(sec<0)
{
sec=59;
min--;
}
if(min<=0&&sec==0)
{
min=0;
flag_bs=1;
buzz=0;
}
}
}
}
|