#include<reg51.h>
#include"lcd.h"
#define uint unsigned int
#define uchar unsigned char
sbit P25=P2^5; //下降沿放音
sbit rc=P2^6;
sbit a0=P2^7;
sbit st=P2^4;
sbit start=P3^2;
sbit up=P3^3; //加
sbit down=P3^4; //减
sbit P37=P3^7;
uint add;
bit K1;
bit a;
uchar i;
uchar j;
uint cmd,cnt;
uint temp1,temp2;
uint shuchu ;
uint dianya;
uint t ;
uint baoy;
uint cw=370;
bit flay;
uchar data led[3];
uchar code number[]="0123456789.";
uchar tab1[]="abcd 36.9d";
uchar tab2[]="abcd 37.0d";
//uchar tab1[]="当前温度 36.9度";
//uchar tab1[]="aasdsd 37.0d";
//uchar tab2[]="aaddd: 36.9d";
void init(void); //中断初始化
void delay(uint k);
void ad574(void);
void key(void); //键盘
void delay(uint k)//延时 k ms
{ k=k*125;
while(k--);
}
void ad574(void)
{ rc=0;
a0=0;
while(st==1);
st=1;
rc=1;
delay(10);
temp1=P1;
delay(10);
a0=1;
temp2=P1;
shuchu=(temp1<<4)+(temp2>>4);
// shuchu=2300;
if(shuchu>=0&&shuchu<2048)
{ dianya=2048-shuchu;
flay=1 ;
}
if(shuchu>=2048&&shuchu<=4096)
{ dianya=shuchu-2047 ;
flay=0;
}
//dianya=1600;
t=dianya*9/37;
t=101;
if(t>163&&t<=405)
t=t+1;
if(t>405)
t+=2;
}
void key(void)
{if(start==0&&a==0)
{ delay(2);
if(start==0)
{ a=1; K1=~K1;}
}
if(start==1&&a==1)
a=0;
{if(K1==1)
if(up==0&&cw<500)
{ add++;
if(add==1) cw=cw+10;
if(add==250)
{cw=cw+10;add=200;}
}
else add=0;
if(down==0&&cw>0)
{ add++;
if(add==1) cw=cw-10;
if(add==250)
{ cw=cw-10;add=200;}
}
else add=0;
}
}
void init(void)
{ TMOD=0x11;
TH0=(65536-50000)/256; //定时50MS
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=1;
ET0=1;
IT0=1;
TR1=0;
ET1=1;
IT1=1;
EA=1;
}
void t0(void) interrupt 1 using 1
{ TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
cmd++;
if(cmd==300) // 1分钟定时
{ TR1=1;
cmd=0;
baoy=t;
led[0]=baoy%10;
led[1]=baoy%100/10;
led[2]=baoy/100;
P37=0;
}
}
void t1(void) interrupt 3 using 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
cnt++;
if(cnt==10) P25=1;
if(cnt==20)
{ j++;
TR0=0;
cnt=0;
if(j==1)
{ P0=88 ; P25=0; } //读温度
if(led[2]==0)
{ if(j==2)
{ P0=8*led[1];P25=0;}
if(led[0]==0)
{ if(j==3)
{ P0=104;P25=0; }
if(j==4)
{j=0;TR1=0;P0=0;P25=1;TR0=1;}
}
else
{ if(j==3)
{ P0=96;P25=0;}
if(j==4)
{ P0=8*led[0]; P25=0;}
if(j==5)
{ P0=104;P25=0;}
if(j==6)
{j=0;TR1=0;P0=0;P25=1;TR0=1;}
}
}
else
{ if(j==2)
{ P0=8*led[2];P25=0;}
if(j==3)
{ P0=80; P25=0;}
if(led[1]==0)
{ if(led[0]==0)
{ if(j==4)
{ P0=104;P25=0;}
if(j==5)
{j=0;TR1=0;P0=0;P25=1;TR0=1;}
}
else
{ if(j==4)
{ P0=96;P25=0;}
if(j==5)
{ P0=8*led[0];P25=0;}
if(j==6)
{P0=104;P25=0;}
if(j==7)
{ j=0;TR1=0;P0=0;P25=1;TR0=1;}
}
}
else
{ if(j==4)
{ P0=8*led[1]; P25=0;}
if(j==5)
{ P0=96;P25=0;}
if(j==6)
{ P0=8*led[0];P25=0;}
if(j==7)
{ P0=104 ; P25=0;}
if(j==8)
{ j=0; TR1=0; P0=0;P25=1;TR0=1;}
}
}
}
}
void main(void)
{
initlcd();//初始化
clear();//清屏
gotoxy(1,0);//显示第1行
for(i=0;i<10;i++) WRdata(tab1[i]);
gotoxy(2,0);//显示第2行
for(i=0;i<10;i++) WRdata(tab2[i]);
init();
P0=0X00;
while(1)
{
key();
ad574();
gotoxy(1,5);
WRdata(number[t/100]);
gotoxy(1,6);
WRdata(number[t%100/10]);
gotoxy(1,7);
WRdata(number[10]);
gotoxy(1,8);
WRdata(number[t%10]);
gotoxy(2,5);
WRdata(number[cw/100]);
gotoxy(2,6);
WRdata(number[cw%100/10]);
gotoxy(2,7);
WRdata(number[10]);
gotoxy(2,8);
WRdata(number[cw%10]);
if(K1==1)
{ WRdata(0x0f);
WRdata(0xc5);
gotoxy(2,5);
WRdata(number[cw/100]);
gotoxy(2,6);
WRdata(number[cw%100/10]);
delay(5);
WRdata(0x0c);
}
}
}
wdj.rar_温度计_温度计 1602
版权申诉
162 浏览量
2022-09-21
05:49:29
上传
评论
收藏 59KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/271c0f59ce4e427783f4849fb0aeba2e_weixin_42662171.jpg!1)
林当时
- 粉丝: 103
- 资源: 1万+