#include <AT89X51.H>
#include <intrins.h> //_nop_();
/*宏定义*/
#define uchar unsigned char
#define uint unsigned int
//#define N 5
//sbit CLK=P2^4;
sbit OE=P2^6;
sbit EOC=P3^7;
sbit ST=P2^5;
sbit SET=P2^7;
sbit LED1=P3^4;
sbit LED2=P3^5;
sbit LED3=P3^6;
sbit LED4=P3^7;
sbit p20=P2^0;
sbit cong1=P2^1;
sbit cong2=P2^2;
sbit feng1=P2^3;
sbit feng2=P2^4;
bit flag;
bit flag1;
/*全局变量*/
uchar led_bit;
//uchar dat;
uchar dat1[2];
uchar d[5];
uchar a[4];
uchar count1;
uchar get_char;
//uchar i;
/*全局变量*/
uchar counter;
uchar second;
uchar min,min1;
uchar hour,hour1;
/*标准LED共阴字形代码*/
unsigned char code numb0[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0xbf,0xff}; //0xaf为‘-’的代码
/*标准LED共阳字形代码*/
//unsigned char code numb1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x40,0x00};
/*延时程序*/
delay(uchar m)
{
for(m;m>0;m--);
}
void time_init(void)
{
ST=0;
OE=0;
TMOD=0x01; //16位定时器
EA=1;
ET0=1;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TR0=1;
}
/*
void pais(uchar a[])
{uchar i,j,min0;
uchar tem0;
for(i=0;i<N;i++)
/*sort ten num*/
/* for(i=0;i<N-1;i++)
{
min0=i;
for(j=i+1;j<N;j++)
if(a[min0]>a[j])
min0=j;
tem0=a[i];
a[i]=a[min0];
a[min0]=tem0;
}
}
*/
/*定时器0中断程序*/
void timer0(void) interrupt 1 using 2
{TL0=(65535-50000)%256;
TH0=(65535-50000)/256;
counter++;
if(counter==20)
{counter=0;
second++;
}
}
/*时间处理*/
void proccess(void)
{if(second==60)
{second=0;
min++;
}
if(min==60)
{min=0;
if(hour<23)
hour++;
else
hour=0;
}
}
/*时间处理*/
void proccess1(void)
{if(second==60)
{second=0;
min1++;
}
if(min1==60)
{min1=0;
if(hour1<23)
hour1++;
else
hour1=0;
}
}
void show(void)
{
a[0]=numb0[1];
a[1]=numb0[hour];
a[2]=numb0[(min/10)];
a[3]=numb0[(min%10)];
}
void show1(void)
{
a[0]=numb0[2];
a[1]=numb0[hour1];
a[2]=numb0[(min1/10)];
a[3]=numb0[(min1%10)];
}
/*
void fun(void)
{
d[count1]=dat;
if(count1>4)
{
count1=0;
pais(d);
get=dat;
}
get=dat;
}
*/
void just(void)
{
// if(i>10)
// {i=0;
if(EOC)
{
OE=1;
_nop_();
_nop_();
_nop_();
_nop_();
get_char=P0;
_nop_();
_nop_();
_nop_();
_nop_();
OE=0;
// get_char=170;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
ST=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
ST=0;
// }
// i++;
}
}
main()
{//uchar j;
time_init();
flag=1;
flag1=1;
ST=1;
ST=0;
cong1=1;
cong2=1;
feng1=0;
feng2=0;
// dat=0xff;
while(1)
{
if((second%4)==0)
{SET=0;
just();
if(p20==1) //为镍氢电池
{
flag=1;
if(get_char<190) //<1.85
{cong1=0;feng1=0;//cong
proccess();
show();
}
else
{
cong1=1;feng1=0;
}//stop
}
else
{
if((get_char>102)&flag)
{cong1=1;feng1=1;}//feng
else
{
flag=0;
if(get_char<190) //<1.85
{
cong1=0;feng1=0;//cong
proccess();
show();
}
else
{cong1=1;feng1=0;}//stop
}
}
}
/**************************/
if(second%4==2)
{SET=1;
just();
if(p20)
{if(get_char<190) //<1.85
{cong2=0;feng2=0;//cong
proccess();
show();
}
else
{cong1=2;feng2=0;}//stop
}
else
{
if((get_char>102)&flag1)
{cong2=1;feng2=1;}//feng
else
{
flag1=0;
if(get_char<190) //<1.85
{
cong2=0;feng2=0;//cong
proccess1();
show1();
}
else
{cong1=1;feng1=0;}//stop
}
}
}
switch(led_bit)
{
case 3:P1=a[led_bit];P3=P3|0x0f;P3=P3&0xfe;/*P3=P3|0x80;*/break;
case 2:P1=a[led_bit];P3=P3|0x0f;P3=P3&0xfd;break;
case 1:P1=a[led_bit];P3=P3|0x0f;P3=P3&0xfb;break;
case 0:P1=a[led_bit];P3=P3|0x0f;P3=P3&0xf7;break;
default:;break;
}
P1=get_char;
if(led_bit<3)
led_bit++;
else
led_bit=0;
delay(2);
}
}