#include <reg51.h>
typedef unsigned char UINT8;
typedef unsigned int UINT16;
code UINT8 SEGMENT[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
code UINT8 SELECT[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
sbit abi=P1^7 ;
sbit SPK=P1^0;
UINT8 i=0;
UINT16 t,Recbuf;
extern UINT16 read_temp(void);
void Delay(UINT16 b)
{
UINT8 d;
while(b--)for(d=0;d<120;d++);
}
void Display1(UINT16 temp,UINT16 shezhi)
{
static UINT8 num=0;
P2=0xff;
switch(num)
{
case 0:
P0=SEGMENT[temp/1000];
break;
case 1:
P0=SEGMENT[temp%1000/100];
break;
case 2:
P0=SEGMENT[temp%100/10]&0x7f;
break;
case 3:
P0=SEGMENT[temp%10];
break;
case 4:
P0=0XFF;
break;
case 5:
P0=SEGMENT[shezhi%100/10];
break;
case 6:
P0=SEGMENT[shezhi%10];
break;
case 7:
P0=0xff;
break;
}
P2=SELECT[num];
num++;
num%=8;
}
void Sernial_Init(void)
{
TMOD=0x21;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SCON=0x50; //SM0 SM1 SM2 REN TB8 RB8 TI RI 方式1
IE=0x92; //EA X X ES ET1 EX1 ET0 EX0
TR0=1;
TH0=65535-50000/256;
TL0=65535-50000%256;
}
void zhongduan() interrupt 1
{
UINT16 a ;
TH0=65535-50000/256;
TL0=65535-50000%256;
if(t>=i*10&&i>=20)
{
for(a=0;a<1000;a++)
{
SPK=!SPK;
Delay(1);
}
SPK=0;
return ;
}
}
void Send(UINT8 c)
{
TI=0;
TB8=0;
SBUF=c;
while(TI==0);
TI=0;
}
void Rec(void) interrupt 4
{
if(RI==0)
return;
RI=0;
Recbuf=SBUF;
}
void main()
{
UINT8 m,n;
UINT16 x;
Sernial_Init();
while(1)
{
t=read_temp();
for(x=0;x<2200;x++)
Display1(t,i);
if(Recbuf==0x01)
{
abi=1;
m=t/256;
n=t%256;
Send(m);
Send(n);
}
else
{
abi=0;
i=Recbuf;
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>