把两个程序合在一起温度就只显示00.00了,按键是设置时间的,这是主函数,大家看看
void main()
{
unsigned char i;
Int0Configuration();
LcdInit();
Ds1302Init();
while(1)
{
if(SetState==0)
{
Ds1302ReadTime();
}
else
{
if(K1==0)
{
Delay10ms();
if(K1==0)
{
SetPlace++;
if(SetPlace>=7)
SetPlace=0;
}
while((i<50)&&(K1==0))
{
Delay10ms();
i++;
}
i=0;
}
if(K2==0)
{
Delay10ms();
if(K2==0)
{
TIME[SetPlace]++;
if((TIME[SetPlace]&0x0f)>9)
{
TIME[SetPlace]=TIME[SetPlace]+6;
}
if((TIME[SetPlace]>=0x60)&&(SetPlace<2))
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x24)&&(SetPlace==2))
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x32)&&(SetPlace==3))
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x13)&&(SetPlace==4))
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x7)&&(SetPlace==5))
{
TIME[SetPlace]=1;
}
// if(SetPlace==5)
// {
// TIME[SetPlace]=;
// }
}
while((i<50)&&(K2==0))
{
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));
}
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;
}
}
|