硬件设计
链接:https://pan.baidu.com/s/1OKhXA_rhCJotATu8nzzxLQ
提取码:qcmg
仿真图:
代码设计
主程序:
#include <reg52.h>
#include "lcd.h"
#include "disp_temp.h"
#include "read_temp.h"
bit up_temp = 0;
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x0B1;
TL0 = 0x0E0;
EA = 1;
ET0 = 1;
TR0 = 1;
}
main()
{
uint tem_buf, temp[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
uchar i;
InitLcd1602();
InitTimer0();
while(1)
{
if(up_temp)
{
EA = 0;
up_temp = 0;
for(i=0; i<8; i++)
{
tem_buf = read_tem(i);
if(tem_buf!=temp[i])
{
temp[i] = tem_buf;
dis_tem(i, temp[i]);
}
EA = 1;
}
}
}
}
void Timer0Interrupt(void) interrupt 1
{
static uchar count = 0;
TH0 = 0x0B1;
TL0 = 0x0E0;
if(count >=100)
{
count = 0;
up_temp = 1;
}
else
count++;
}
显示部分:
#include "lcd.h"
void Read_Busy() //忙检测函数,判断bit7是0,允许执行;1禁止
{
unsigned char sta; //
LCD1602_DB = 0xff;
LCD1602_RS = 0;
LCD1602_RW = 1;
do
{
LCD1602_EN = 1;
sta = LCD1602_DB;
LCD1602_EN = 0; //使能,用完就拉低,释放总线
}while(sta & 0x80);
}
void Write_Cmd(unsigned char cmd) //写命令
{
Read_Busy();
LCD1602_RS = 0;
LCD1602_RW = 0;
LCD1602_DB = cmd;
LCD1602_EN = 1;
LCD1602_EN = 0;
}
void Write_Data(unsigned char dat) //写数据
{
Read_Busy();
LCD1602_RS = 1;
LCD1602_RW = 0;
LCD1602_DB = dat;
LCD1602_EN = 1;
LCD1602_EN = 0;
}
void InitLcd1602() //1602初始化
{
Write_Cmd(0x38); //打开,5*8,8位数据
Write_Cmd(0x0c);
Write_Cmd(0x06);
Write_Cmd(0x01); //清屏
}
.
.