#include <STC89C5xRC.H>
#include "onewire.h"
#include"intrins.h" //左移右移.h文件
void shizhong();
void Delay1ms(); //@11.0592MHz 2ms显示
void display_time();
unsigned char key();
void anjian();
unsigned char key_var();
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
void xianshi();
u8 code shijian[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0x00}; //数码管显示0-9 0x40表示杠杠,0x00全灭 后面取反
unsigned char com[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //com口从左到右
unsigned char shifenmiao[]={10,10,10,10,10,10,10,10,};
unsigned int temp,Low=25,High=29;
int num,flag,set=0,varue,key_flag=0;
void main()
{
P2=0xa0;P0=0;P2=0;//设备初始化 //关闭声音
P2=0x80;P0=0xff;P2=0;//设备初始化 //关闭LED灯
while(1)
{
temp=rd_temperature();
shizhong();
key_var();
anjian();
}
}
void shizhong()
{
static unsigned char q=0;
P2=0xc0;
P0=com[q];
P2=0;
P2=0xe0;
P0=~shijian[shifenmiao[q]];
P2=0;
Delay1ms();
++q;
if(q==8)
q=0;
}
void Delay1ms() //@11.0592MHz 2ms显示
{
unsigned char i, j;
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
void display_time()
{
if(temp<Low)
shifenmiao[1]=0;
if(temp<=High && temp>=Low)
shifenmiao[1]=1;
if(temp>High)
shifenmiao[1]=2;
shifenmiao[0]=10;
shifenmiao[2]=10;
shifenmiao[3]=11;
shifenmiao[4]=11;
shifenmiao[5]=11;
shifenmiao[6]=temp/10;
shifenmiao[7]=temp%10;
}
void anjian() //11是设置,10是删除
{
if(set==11)
{ P2=0x80;P0=0xfe;P2=0;
shifenmiao[0]=10;
shifenmiao[1]=11;
shifenmiao[2]=11;
shifenmiao[3]=11;
shifenmiao[4]=11;
shifenmiao[5]=10;
shifenmiao[6]=11;
shifenmiao[7]=11;
}
else
display_time();
}
unsigned char key() //按键扫描函数
{ unsigned char key_loop;
unsigned char key_var=0xff,key_ini=0xfe;
for(key_loop=0;key_loop<4;key_loop++) //循环扫描四次
{
P3=key_ini; //P3口赋初值
if(P3!=key_ini||P42==0||P44==0) //如果按键被按下了 就进入函数
{ P2=0x80;P0=0xfe;P2=0;
key_var=(P3&0x3f)|((P4&0x04)<<4)|((P4&0x10)<<3); // 把P42与P44按位与到P36 P37上
break;
}
key_ini=_crol_(key_ini,1); //每次循环左移一次 由0xfe 到0xf7
}
return key_var;
}
unsigned char key_var()
{
varue=key(); //进入按键扫描函数
if(varue!=0xff&&key_flag==0) //当按键被按下 且防抖动标志为0时
{
key_flag=1; //改变防抖动标志
switch(varue) //判断是哪个按键被按下 后改变按键标志 然后在定时器中判断按键标志 执行相应程序
{
case 0x7e: flag=0; break;
case 0x7d: flag=3; break;
case 0x7b: flag=6; break;
case 0x77: flag=9; break;
case 0xbe: flag=1; break;
case 0xbd: flag=4; break;
case 0xbb: flag=7; break;
case 0xb7: set=11; break;
case 0xde: flag=2; break;
case 0xdd: flag=5; break;
case 0xdb: flag=8; break;
case 0xd7: set=12; break;
default:break;
}
}
if(varue==0xff){key_flag=0;} //当按键没被按下 还原防抖动标志
return flag;
return set;
}
|