按键是设置时间的
void main()
{
unsigned char i;
Int0Configuration();
LcdInit();
Ds1302Init();
while(1)
{
if(SetState==0)
{
Ds1302ReadTime();
}
else
{
if(K1==0) //¼ì2a°′¼üK1êÇ·ñ°′ÏÂ
{
Delay10ms(); //Ïû3y¶¶¶ˉ
if(K1==0)
{
SetPlace++;
if(SetPlace>=7)
SetPlace=0;
}
while((i<50)&&(K1==0)) //¼ì2a°′¼üêÇ·ñËé¿a
{
Delay10ms();
i++;
}
i=0;
}
if(K2==0) //¼ì2a°′¼üK2êÇ·ñ°′ÏÂ
{
Delay10ms(); //Ïû3y¶¶¶ˉ
if(K2==0)
{
TIME[SetPlace]++;
if((TIME[SetPlace]&0x0f)>9) //»»3éBCDÂë¡£
{
TIME[SetPlace]=TIME[SetPlace]+6;
}
if((TIME[SetPlace]>=0x60)&&(SetPlace<2)) //·ÖÃëÖ»Äüμ½59
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x24)&&(SetPlace==2)) //D¡ê±Ö»Äüμ½23
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x32)&&(SetPlace==3)) //èÕÖ»Äüμ½31
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x13)&&(SetPlace==4)) //ÔÂÖ»Äüμ½12
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x7)&&(SetPlace==5)) //ÖüÖ»Äüμ½7
{
TIME[SetPlace]=1;
}
// if(SetPlace==5) //ÔÂÖ»Äüμ½12
// {
// TIME[SetPlace]=;
// }
}
while((i<50)&&(K2==0)) //¼ì2a°′¼üêÇ·ñËé¿a
{
Delay10ms();
i++;
}
i=0;
}
}
LcdTimeDisplay();
LcdTempDisplay(Ds18b20ReadTemp());
}
}
void LcdTimeDisplay()
{
LcdWriteCom(0x80+0X40);
LcdWriteData('0'+TIME[2]/16); //ê±
LcdWriteData('0'+(TIME[2]&0x0f));
LcdWriteData('-');
LcdWriteData('0'+TIME[1]/16); //·Ö
LcdWriteData('0'+(TIME[1]&0x0f));
LcdWriteData('-');
LcdWriteData('0'+TIME[0]/16); //Ãë
LcdWriteData('0'+(TIME[0]&0x0f));
LcdWriteCom(0x80);
LcdWriteData('2');
LcdWriteData('0');
LcdWriteData('0'+TIME[6]/16); //Äê
LcdWriteData('0'+(TIME[6]&0x0f));
LcdWriteData('-');
LcdWriteData('0'+TIME[4]/16); //ÔÂ
LcdWriteData('0'+(TIME[4]&0x0f));
LcdWriteData('-');
LcdWriteData('0'+TIME[3]/16); //èÕ
LcdWriteData('0'+(TIME[3]&0x0f));
LcdWriteCom(0x8D);
LcdWriteData('0'+(TIME[5]&0x07)); //DÇÆú
}
void LcdTempDisplay(int temp)
{
unsigned char i, datas[] = {0, 0, 0, 0, 0}
float tp;
if(temp< 0)
{
LcdWriteCom(0x80);
SBUF='-'
while(!TI);
TI=0;
LcdWriteData('-');
temp=temp-1;
temp=~temp;
tp=temp;
temp=tp*0.0625*100+0.5;
}
else
{
LcdWriteCom(0x4a+0x80);
LcdWriteData('+');
SBUF='+'
while(!TI);
TI=0;
tp=temp
temp=tp*0.0625*100+0.5;
}
datas[0] = temp / 10000;
datas[1] = temp % 10000 / 1000;
datas[2] = temp % 1000 / 100;
datas[3] = temp % 100 / 10;
datas[4] = temp % 10;
LcdWriteCom(0x4b+0x80);
LcdWriteData('0'+datas[1])
SBUF = '0'+datas[1]
while (!TI);
TI = 0;
LcdWriteCom(0x4c+0x80);
LcdWriteData('0'+datas[2]);
SBUF = '0'+datas[2]
while (!TI);
TI = 0;
LcdWriteCom(0x4d+0x80);
LcdWriteData('.');
SBUF = '.'
while (!TI);
TI = 0;
LcdWriteCom(0x4e+0x80);
LcdWriteData('0'+datas[3])
SBUF = '0'+datas[3]
while (!TI);
TI = 0;
LcdWriteCom(0x4f+0x80);
LcdWriteData('0'+datas[4])
SBUF = '0'+datas[4]
while (!TI);
TI = 0;
for(i=0; i<6; i++)
{
SBUF = CNCHAR[i]
while (!TI);
TI = 0;
}
}
|