/*------------------------------------------------
温度数字显示表
--------------------------------------------------*/
uchar code NumTab[]=
{
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00, /*"0",0*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, /*"1",1*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00, /*"2",2*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00, /*"3",3*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00, /*"4",4*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00, /*"5",5*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00, /*"6",6*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, /*"7",7*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00, /*"8",8*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, /*"9",9*/
0x00,0x1C,0xF0,0x08,0x08,0x08,0x30,0x00,
0x00,0x00,0x0F,0x10,0x20,0x30,0x10,0x00, /*"℃",10*/
0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, /*"|",11*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /*" ","12"*/
};
/*---------------------------------------------------
曲线显示表
----------------------------------------------------*/
uchar code DotTable[32]=
{
0x80,0x00,0x40,0x00,0x20,0x00,0x10,0x00,
0x08,0x00,0x04,0x00,0x02,0x00,0x01,0x00,
0x00,0x80,0x00,0x40,0x00,0x20,0x00,0x10,
0x00,0x08,0x00,0x04,0x00,0x02,0x00,0x01
};
/*----------------------------------------------------
汉字显示表
-----------------------------------------------------*/
uchar code HZTab[]=
{
0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,
0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,
0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,
0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00, /*"温",0*/
0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,
0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,
0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,
0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00, /*"度",1*/
0x00,0x00,0x7E,0x00,0x00,0xFF,0x20,0x10,
0x0F,0x1A,0x68,0xC8,0x08,0x08,0x08,0x00,
0x40,0x40,0x7E,0x42,0x42,0x7E,0x42,0x42,
0x7E,0x42,0x42,0x42,0x7E,0x40,0x40,0x00, /*"监",2*/
0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,
0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,
0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,
0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00, /*"测",3*/
0x00,0x00,0x02,0x22,0xB2,0xAA,0x66,0x62,
0x22,0x11,0x4D,0x81,0x01,0x01,0x00,0x00,
0x00,0x40,0x21,0x13,0x09,0x05,0x41,0x81,
0x7F,0x01,0x05,0x09,0x13,0x62,0x00,0x00, /*"系",4*/
0x20,0x30,0x2C,0xA3,0x60,0x10,0x84,0xC4,
0xA4,0x9D,0x86,0x84,0xA4,0xC4,0x84,0x00,
0x20,0x22,0x23,0x12,0x12,0x92,0x40,0x30,
0x0F,0x00,0x00,0x3F,0x40,0x41,0x70,0x00, /*"统",5*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,
0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,
0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,
0x40,0x40,0x40,0x40,0x40,0x60,0x40,0x00, /*"上",6*/
0xFE,0x02,0x32,0x4E,0x82,0x00,0xFE,0x4A,
0xCA,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,
0xFF,0x00,0x02,0x04,0x03,0x00,0xFF,0x40,
0x20,0x03,0x0C,0x12,0x21,0x60,0x20,0x00, /*"限",7*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*":",8*/
0x00,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,
0x22,0x62,0xC2,0x82,0x02,0x03,0x02,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,
0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00 /*"下",9*/
};
"Delay.h"
/*本头文件中定义了一些常用的延时函数*/
/*---------------------------------------------------
延时函数,供18b20采集温度等待的调用
----------------------------------------------------*/
void delay(uint x)
{
uint i;
while(x-->0)
for(i=0;i<110;i++);
}
/*----------------------------------------
18B20延迟函数
------------------------------------------*/
void delay18B20(uint i)
{
while(i--);
}
"LCD12232.h"
/*本头文件定义了对JCM12232B操作所用到的函数*/
/*----------------------------------------------------------------------------
调用方式:void OutMI(uchar i)
函数说明:发指令i到主窗口。(内函数,私有,用户不直接调用)
------------------------------------------------------------------------------*/
void OutMI(uchar i)
{
LCD_E2=0;
_nop_();
_nop_();
LCD_A0=0;
LCD_RW=0;
_nop_();
_nop_();
LCD_E2=1;
_nop_();
_nop_();
DATA=i;
_nop_();
_nop_();
LCD_E2=0;
_nop_();
_nop_();
}
/*--------------------------------------------------------------------------------
调用方式:void OutMD(uchar i)
函数说明:发数据i到主窗口。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void OutMD(uchar i)
{
LCD_E2=0;
_nop_();
_nop_();
LCD_A0=1;
LCD_RW=0;
_nop_();
_nop_();
LCD_E2=1;
_nop_();
_nop_();
DATA=i;
_nop_();
_nop_();
LCD_E2=0;
_nop_();
_nop_();
}
/*--------------------------------------------------------------------------------
调用方式:void OutSI(uchar i)
函数说明:发指令i到从窗口。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void OutSI(uchar i)
{
LCD_E1=0;
_nop_();
_nop_();
LCD_A0=0;
LCD_RW=0;
_nop_();
_nop_();
LCD_E1=1;
_nop_();
_nop_();
DATA=i;
_nop_();
_nop_();
LCD_E1=0;
_nop_();
_nop_();
}
/*--------------------------------------------------------------------------------
调用方式:void OutSD(uchar i)
函数说明:发数据i到从窗口。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void OutSD(uchar i)
{
LCD_E1=0;
_nop_();
_nop_();
LCD_A0=1;
LCD_RW=0;
_nop_();
_nop_();
LCD_E1=1;
_nop_();
_nop_();
DATA=i;
_nop_();
_nop_();
LCD_E1=0;
_nop_();
_nop_();
}
/*--------------------------------------------------------------------------------
调用方式:void LcdIni(void)
函数说明:12232点阵液晶初始化,开机后仅调用一次。
---------------------------------------------------------------------------------*/
void LcdIni(void)
{
LCD_RST=0;
delay(100);
LCD_RST=1; //LCD复位
OutMI(0XE2);OutSI(0XE2);//复位
OutMI(0XAE);OutSI(0XAE);//POWER SAVE
OutMI(0XA4);OutSI(0XA4);//动态驱动
OutMI(0XA9);OutSI(0XA9);//1/32占空比
OutMI(0XA0);OutSI(0XA0);//时钟线输出,设置显示方向
OutMI(0XEF);OutSI(0XEF);//写模式
OutMI(0X00);OutMI(0XC0);
OutSI(0X00);OutSI(0XC0);
OutMI(0XAF);OutSI(0XAF);
}
/*--------------------------------------------------------------------------------
调用方式:void SetMP(uchar pageM)
函数说明:设置主显示页为0-3页。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void SetMP(uchar pageM)
{
OutMI(0xB8|pageM);
}
/*--------------------------------------------------------------------------------
调用方式:void SetSP(uchar pageS)
函数说明:设置从显示页为0-3页。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void SetSP(uchar pageS)
{
OutSI(0xB8|pageS);
}
/*--------------------------------------------------------------------------------
调用方式:void SetPage(uchar page0,uchar page1)
函数说明:同时设置主从显示页为0-3页。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void SetPage(uchar pageM,uchar pageS)
{
OutMI(0xB8|pageS);
OutSI(0xB8|pageM);
}
/*--------------------------------------------------------------------------------
调用方式:void SetMA(uchar AddressM)
函数说明:设置右半窗列地址为61-121。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void SetMA(uchar AddressM)
{
OutMI(AddressM&0x7F);
}
/*--------------------------------------------------------------------------------
调用方式:void SetSA(uchar AddressS)
函数说明:设置左半窗列地址为0-60。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void SetSA(uchar AddressS)
{
OutSI(AddressS&0x7F);
}
/*--------------------------------------------------------------------------------
调用方式:void SetAddress(uchar address0,uchar address1)
函数说明:同时设置左半窗和右半窗列地址为0-121。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void SetAddress(uchar address0,uchar address1)
{
OutMI(address1&0x7F);
OutSI(address0&0x7F);
}
/*--------------------------------------------------------------------------------
调用方式:void PutCharS(uchar ch)
函数说明:在左页当前地址画一个字节8个点。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void PutCharS(uchar ch)
{
OutSD(ch);
}
/*--------------------------------------------------------------------------------
调用方式:void PutCharM(uchar ch)
函数说明:在右页当前地址画一个字节8个点。(内函数,私有,用户不直接调用)
---------------------------------------------------------------------------------*/
void PutCharM(uchar ch)
{
OutMD(ch);
}
/*--------------------------------------------------------------------------------
调用方式:void DrawBmp(uchar x,bit layer,uchar width,uchar *bmp)
函数说明:写一个字符,横坐标是x0,layer表示上下窗,layer=0为上窗,layer=1为下窗,
width是字符的宽,都是16,bmp是字符指针,使用zimo21软件,采用纵向取模得到bmp数据。
---------------------------------------------------------------------------------*/
void DrawBmp(uchar x0,bit layer,uchar width,uchar *bmp)
{
uchar x,address,i=0; //address表示显存的物理地址
uchar page=0;
bit window=0; //page表示上下两页,window表示左右两半屏
if (layer) page=2;
for (x=x0;x<x0+width;x++)
{
if (x>61) //判断是否到右半屏
{
window=1;//对右窗操作
address=x%61;
}
else
{
address=x;
SetSP(page);
SetSA(address);
}
if (window) //画汉字的上半部分
{
SetMP(page);
SetMA(address);
PutCharM(bmp[i]);//在右页当前地址画一个字节8个点
}
else
{
PutCharS(bmp[i]);//在左页当前地址画一个字节8个点
}
if (window) //画汉字的下半部分
{
SetMP(page+1);
SetMA(address);
PutCharM(bmp[i+width]);
}
else
{
SetSP(page+1);
SetSA(address);
PutCharS(bmp[i+width]);
}
i++;
}
}
/*---------------------------------------------
曲线绘制函数
----------------------------------------------*/
void Draw_Wave(uchar X,uchar Y,uchar *pTab)
{
uchar page=2;
if(Y>15)//温度上限越屏处理
Y=15;
if(Y<0)//温度下限越屏处理
Y=0;
if (X>61)
{
X=X%61;
SetMP(page+1);
SetMA(X);
OutMD(pTab[2*Y]);
SetMP(page);
SetMA(X);
OutMD(pTab[2*Y+1]);
}
else
{
SetSP(page+1);
SetSA(X);
OutSD(pTab[2*Y]);
SetSP(page);
SetSA(X);
OutSD(pTab[2*Y+1]);
}
}
/*--------------------------------------------
调用方式:void clrscr(void)
函数说明:清整个屏
----------------------------------------------*/
void clrscr(void)
{
uchar i;
uchar page;
for (page=0;page<4;page++)
{
SetPage(page,page);
SetAddress(0,0);
for (i=0;i<61;i++)
{
PutCharS(0);
PutCharM(0);
}
}
}
/*----------------------------------------
图形采集满屏时,清下屏
-----------------------------------------*/
void ClaerDS()
{
uchar i;
uchar page;
for (page=2;page<4;page++)
{
SetPage(page,page);
SetAddress(0,0);
for (i=0;i<61;i++)
{
PutCharS(0);
PutCharM(0);
}
}
}
"DS18B20.h"
/*本头文件定义对DS18B20操作所用到的函数*/
/*----------------------------------------
DS18B20初始化函数
-----------------------------------------*/
Init_DS18B20(void)
{
DQ = 1; //DQ复位
delay18B20(5); //稍做延时
DQ = 0; //单片机将DQ拉低
delay18B20(80); //xx延时大于480us
DQ = 1; //拉高总线
delay18B20(15);
Flag18b20=DQ; //稍做延时后 如果Flag18b20=0,则初始化成功,Flag18b20=1则初始化失败
delay18B20(20);
DQ=1;
}
/*----------------------------------------
从DS18B20读出一个字节的数据
-----------------------------------------*/
ReadOneChar(void)
{
uchar i=0;
uchar dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 给脉冲信号
// delay18B20(10);
dat>>=1;
DQ = 1; // 给脉冲信号
if(DQ)
dat|=0x80;
delay18B20(5);
}
return(dat);
}
/*-----------------------------------------
写一个字节的数据到DS18B20
----------------------------------------*/
WriteOneChar(uchar dat)
{
uchar i=0;
for (i=8;i>0;i--)
{
DQ = 0;
// delay18B20(10);
DQ = dat&0x01;
delay18B20(5);
DQ = 1;
dat>>=1;
}
delay18B20(5);
}
/*--------------------------------------------
配置DS18B20
--------------------------------------------*/
void Config18b20()
{
Init_DS18B20();
WriteOneChar(0xcc); //skip rom
WriteOneChar(0x4e); //write scratchpad
WriteOneChar(0x55); //上限
WriteOneChar(0x00); //下限
WriteOneChar(0x1f); //set 9 bit (0.5)
Init_DS18B20();
WriteOneChar(0xcc); //skip rom
WriteOneChar(0x48); //保存设定值
Init_DS18B20();
WriteOneChar(0xcc); //skip rom
WriteOneChar(0xb8); //回调设定值
}
/*--------------------------------------------
读取采集到温度
---------------------------------------------*/
uint ReadTemperature()
{
uchar a,b;
uint g;
Config18b20();//配置18b20
Init_DS18B20();//18b20初始化
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
delay(200); //延时足够长,延时短会出现{dy}次采集温度为85℃情况
Init_DS18B20();
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
a=ReadOneChar(); //读取温度值低位
b=ReadOneChar(); //读取温度值高位
DQ=1;
g=b<<8; //最终数据在a和b中
g=g|a;
g=g*0.0625; //这是转换成具体温度值,1点代表0.0625°C
return g;
}
"Init.h"
/*本头文件定义了整个系统初始化时所用到的函数*/
/*----------------------------------------------
定时器0的初始化
-----------------------------------------------*/
void Timer0Init()
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void Init() //系统的初始化
{
LcdIni();
clrscr();
for(HZNum=0;HZNum<6;HZNum++)
DrawBmp(16*HZNum,0,16,HZTab+32*HZNum); //初始化"温度检测系统"六个汉字
DrawBmp(96,0,8,NumTab+16*11);//初始化"|"字符
DrawBmp(114,0,8,NumTab+16*10);//初始化"℃"字符
Timer0Init();//定时器0初始化
ClaerDS();//清下半屏
}
"TempSet.h"
/*本头文件定义了温度上下限设置操作所用到的函数*/
void InitSetTemp()//设置温度的初始化函数
{
DrawBmp(0,1,16,HZTab+32*6);
DrawBmp(16,1,16,HZTab+32*7);
DrawBmp(32,1,16,HZTab+32*8);
DrawBmp(36,1,8,NumTab+16*(MaxTemp/10));
DrawBmp(44,1,8,NumTab+16*(MaxTemp%10));
DrawBmp(52,1,8,NumTab+16*10);
DrawBmp(62,1,16,HZTab+32*9);
DrawBmp(78,1,16,HZTab+32*7);
DrawBmp(94,1,16,HZTab+32*8);
DrawBmp(98,1,8,NumTab+16*(MinTemp/10));
DrawBmp(106,1,8,NumTab+16*(MinTemp%10));
DrawBmp(114,1,8,NumTab+10*16);
}
void SetTempMax()//设置温度上限的函数
{
DrawBmp(36,1,8,NumTab+16*(MaxTemp/10));
DrawBmp(44,1,8,NumTab+16*(MaxTemp%10));
}
void SetTempMin()//设置温度下限的函数
{
DrawBmp(98,1,8,NumTab+16*(MinTemp/10));
DrawBmp(106,1,8,NumTab+16*(MinTemp%10));
}
void keyscan()//键盘扫描程序
{
if(SetSelt==0)//SetSelt键扫描
{
delay(5);//按键消抖
if(SetSelt==0)
{
// TR0=0; //关闭定时器,停止温度采集
SetSeltnum++; //记录SetSelt被按下的次数
while(!SetSelt);//等待键的释放
InitSetTemp();
if(SetSeltnum==3)//第三次按下设置键
{
SetSeltnum=0;
ClaerDS();//清下半屏
TimeX=0;//从零开始绘图
// TR0=1; //开定时器,继续温度采集
}
}
}
if(PlusTempSet==0) //PlusTempSe键扫描
{
delay(5); //按键消抖
if(PlusTempSet==0)
{
while(!PlusTempSet); //松手检测
if(SetSeltnum==1)
{
MaxTemp++;
SetTempMax();
}
else if(SetSeltnum==2)
{
MinTemp++;
SetTempMin();
}
}
}
if(MinusTempSet==0) //MinusTempSet按键扫描
{
delay(5); //按键消抖
if(MinusTempSet==0)
{
while(!MinusTempSet); //松手检测
if(SetSeltnum==1)
{
MaxTemp--;
SetTempMax();
}
else if(SetSeltnum==2)
{
MinTemp--;
SetTempMin();
}
}
}
}