51单片机的液晶显示温度计程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
51单片机的液晶显示温度计程序
51单片机的液晶显示温度计程序#include
<reg51.h>
#include <intrins.h>sbit RST = P2^0;
sbit CLK = P2^1;
sbit DQ = P2^2;
sbit TSOR = P2^3;
sbit ALERT =P2^4;
sbit RS = P2^7;
sbit RW = P2^6;
sbit EN = P2^5;
/*------------------------------------------全局变量
-------------------------------------------------------*/
static unsigned char temp1,temp2; //温度值的整数部分、小数部分
static unsigned char pos,posset; //数字电位器电位值、设定值
static unsigned char min,sec; //分钟、秒static unsigned char count; //Timer0中断计数
static unsigned char minset; //设定的分钟
数
static unsigned char status1,status2; //状态标志
bit stop,timeover; //定时停止、结束
static char line0[] =" 00:00 ";
static char line1[] =" . C
W";/*-------------------------------------------------------------------------------------------------------------*/
void InitInterupt();
void KeyboardDelay();
/*-------------------------------------------LCD驱动函数
------------------------------------------------*/
void DelayL();
void DelayS();
void WriteCommand(unsigned char c);
void WriteData(unsigned char c);
void ShowChar(unsigned char pos,unsigned char c); void ShowString(unsigned char line,char *ptr);
void InitLcd();
/*----------------------------------------------键盘-程序
--------------------------------------------------*/
unsigned char GetKey();
/*---------------------------------------------数字温度计驱动
-------------------------------------------*/
void ChangePos(bit sel,unsigned char pos1,unsigned char pos2);
/*------------------------------------------温度传感器驱动----------------------------------------------*/
void Delay15();
void Delay60();
void Delay100ms();
void Write0TS();
void Write1TS();
bit ReadTS();
void ResetTS();
void WriteByteTS(unsigned char byte); unsigned char ReadByteTS();
void InitTS();
void GetTempTS();
/*-------------------------------------------------主程序
---------------------------------------------------*/
void main (void) {
char code str1[] =" Hello World! ";
char code str2[] =" 2002-10-20 "; unsigned char i; SP=0x50;
ALERT=0; //报警灯灭
TSOR=1; //1-wire总线释放DelayL();
InitLcd(); //初始化LCD
DelayL();
ShowString(0,str1); //启动画面
ShowString(1,str2);
for(i=0;i<15;i++)
Delay100ms();
InitInterupt(); //初始化中断设置
minset=10; //缺省定时10分钟
posset=0; //缺省电位器值0
min=minset; //初始化数据
pos=posset;
sec=0;
count=0;
P1=0xF0;
status1=0;
status2=0;
stop=1;
timeover=0; ChangePos(0,255-pos,255-pos); //设置电位器InitTS(); //初始化温度计