#include "reg52.h"
#include "intrins.h"
#include "iic.h"
#include "ds1302.h"
sbit S7=P3^0;
sbit S6=P3^1;
sbit S5=P3^2;
sbit S4=P3^3;
bit flag=0,jia=0,jian=0; //????????λ
unsigned char code SMG_Nodot[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};
unsigned char code SMG_Isdot[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
unsigned char yi,er,san,si,wu,liu,qi,ba;
unsigned char shidu;
unsigned char shiyan;
unsigned char yuzhi;
unsigned char TIME[]={0x00,0x30,0x08,0x00,0x00,0x00,0x00};
unsigned char code write_add[]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};
unsigned char code read_add[]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
extern unsigned char TIME[];
void SelectHC138(unsigned char n)
{
switch(n)
{
case 4:P2=(P2&0x1f)|0x80;break;
case 5:P2=(P2&0x1f)|0xa0;break;
case 6:P2=(P2&0x1f)|0xc0;break;
case 7:P2=(P2&0x1f)|0xe0;break;
}
}
//********************************************************
void allinit()
{
SelectHC138(4);
P0=0xff;
SelectHC138(5);
P0=0x00;
SelectHC138(6);
P0=0xff;
SelectHC138(7);
P0=0xff;
}
void delay(unsigned int t)
{
while(t--);
}
void SMG_bit(unsigned char pos,unsigned char value)
{
SelectHC138(6);
P0=0x01<<pos;
SelectHC138(7);
P0=value;
}
void DisplaySMG()
{
SMG_bit(0,SMG_Nodot[yi]);delay(500);P0=0xff;
SMG_bit(1,SMG_Nodot[er]);delay(500);P0=0xff;
SMG_bit(2,SMG_Nodot[san]);delay(500);P0=0xff;
SMG_bit(3,SMG_Nodot[si]);delay(500);P0=0xff;
SMG_bit(4,SMG_Nodot[wu]);delay(500);P0=0xff;
SMG_bit(5,SMG_Nodot[liu]);delay(500);P0=0xff;
SMG_bit(6,SMG_Nodot[qi]);delay(500);P0=0xff;
SMG_bit(7,SMG_Nodot[ba]);delay(500);P0=0xff;
}
//*************????????************************************
void keyscan()
{
if(S7==0)
{
delay(100);
while(S7==0);
yi=1;
}
else if(S6==0)
{
delay(100);
if(S6==0)
{
if(flag==0) //S6?????? ????ж?s6??????0??s6????????0?? s6=0???s6=1 ????s6=1???s6=0
{
flag=1;
}
else if(flag==1)
{
flag=0;
// EEPROM_write(0x10,yuzhi);
}
}
while(!S6);
}
else if(S5==0)
{
delay(100);
while(S5==0);
jia=1;
}
else if(S4==0)
{
delay(100);
if(S4==0)
{
jian=1;
}
while(!S4);
}
}
void main()
{
allinit();
DS_init();
// yi=0;er=1;san=2;si=3;wu=4;liu=11;qi=11;ba=11;
//EEPROM_write(0x10,50);
yuzhi=EEPROM_read(0x10);
while(1)
{
DS_get();
//yuzhi=EEPROM_read(0x10);
shidu=AD_read(0x03);
shidu=shidu*0.39;
if(shidu<yuzhi)
{
SelectHC138(5);
P0=0x10;
}
else
{
SelectHC138(5);
P0=0x00;
}
if(flag==1)
{
if(jia==1)
{
jia=0;
yuzhi=yuzhi+1;
}
if(jian==1)
{
jian=0;
yuzhi=yuzhi-1;
}
yi=10;er=10;san=11;si=11;wu=11;liu=11;qi=yuzhi/10;ba=yuzhi%10;
}
else if(flag==0)
{
yi=TIME[2]/16;er=TIME[2]&0x0f;san=10;si=TIME[1]/16;
wu=TIME[1]&0x0f; liu=11; qi=shidu/10;ba=shidu%10;
}
// shiyan=EEPROM_read(0x10);
// EEPROM_write(0x10,100);
//
// yi=shiyan/100;er=shiyan%100/10;san=shiyan%10;
// shidu=AD_read(0x03);
// liu=shidu/100;qi=shidu%100/10;ba=shidu%10;
// DS_get();
// yi=TIME[2]/16;er=TIME[2]&0x0f;san=10;si=TIME[1]/16;
// wu=TIME[1]&0x0f;
keyscan();
DisplaySMG();
}
} |