LCM_EN=1; //置LCM_EN端为高电平,读使能
while(P1&Busy); /*检测忙信号。当P1口内容与Busy(80H)相与后不为零时,程序原地踏步*/
return(DATAPORT); //返回P1口的内容
} // ReadStatusLCM函数结束
/*--------------------------LCM初始化子函数----------------------------*/
void InitLcd() //函数名为InitLcd 的LCM初始化子函数
{ // InitLcd函数开始
WriteCommandLCM(0x38,1);//8位数据传送,2行显示,5*7字形,检测忙信号
WriteCommandLCM(0x08,1);//关闭显示,检测忙信号
WriteCommandLCM(0x01,1);//清屏,检测忙信号
WriteCommandLCM(0x06,1);//显示光标右移设置,检测忙信号
WriteCommandLCM(0x0c,1);//显示屏打开,光标不显示、不闪烁,检测忙信号
} // InitLcd函数结束
/*-------------------显示指定座标的一个字符子函数---------------------------*/
void DisplayOneChar(uchar X,uchar Y,uchar DData)
{
Y&=1;
X&=15;
if(Y)X|=0x40;
X|=0x80;
WriteCommandLCM(X,0);
WriteDataLCM(DData);
}
/*--------------------显示指定座标的一串字符子函数----------------------*/
void DisplayListChar(uchar X,uchar Y,uchar code *DData)
{
uchar ListLength=0;
Y&=0x1;
X&=0xF;
while(X<=15)
{
DisplayOneChar(X,Y,DData[ListLength]);
ListLength++;
X++;
}
}
//=================================================
void init_timer0(void) //定时器T0初始化
{
TMOD=0x01;
TH0=-(50235/256);
TL0=-(50235%256);
TR0=1;
ET0=1;EA=1;
}
//==================================================
void time_zd0(void) interrupt 1 using 1 //定时器T0中断子函数
{
TH0=-(50235/256);
TL0=-(50235%256);
deda++;cnt++;
if(deda>=20){sec++;deda=0;}
if(sec>=60){min++;sec=0;}
if(min>=60){hour++;min=0;}
if(hour>=24){hour=0;}
if(cnt>=6)cnt=0;
key(); //扫描键盘
}
//==================================
void fun0(void) //液晶显示子函数0
{
WriteCommandLCM(0x0c,1);//显示屏打开,光标不显示、不闪烁,检测忙信号
DisplayListChar(0,0,str0);
DisplayListChar(0,1,str1);
//===============================
DisplayOneChar(3,0,hour/10+0x30);// 液晶上显示小时
DisplayOneChar(4,0,hour%10+0x30);
//=========================
DisplayOneChar(6,0,min/10+0x30); // 液晶上显示分
DisplayOneChar(7,0,min%10+0x30);
//==============================
DisplayOneChar(9,0,sec/10+0x30); // 液晶上显示秒
DisplayOneChar(10,0,sec%10+0x30);
//=================================
DisplayOneChar(4,1,T/10+0x30); // 液晶上显示设定的温度值
DisplayOneChar(5,1,T%10+0x30);
//=================================
DisplayOneChar(11,1,temp1/10+0x30); // 液晶上显示测得的温度值
DisplayOneChar(12,1,temp1%10+0x30);
DisplayOneChar(14,1,temp2+0x30);
//================================
if(ON_OFF==0)// 若控温标志为0
{
DisplayOneChar(14,0,0x4f);// 液晶上显示不控温的图标
DisplayOneChar(15,0,0x46);
}
else
{
DisplayOneChar(14,0,0x4f); // 否则液晶上显示控温的图标
DisplayOneChar(15,0,0x4e);
if(outflag==1)DisplayOneChar(0,0,0x7c);
else DisplayOneChar(0,0,0xef);
}
//============================
}
/*******************************************/
void fun1(void) //液晶显示子函数1
{
WriteCommandLCM(0x0c,1);//显示屏打开,光标不显示、不闪烁,检测忙信号
DisplayListChar(0,0,str0);
DisplayListChar(0,1,str1);
//=========================
DisplayOneChar(6,0,min/10+0x30);
DisplayOneChar(7,0,min%10+0x30);
//==============================
DisplayOneChar(9,0,sec/10+0x30);
DisplayOneChar(10,0,sec%10+0x30);
//=================================
DisplayOneChar(4,1,T/10+0x30);
DisplayOneChar(5,1,T%10+0x30);
//=================================
DisplayOneChar(11,1,temp1/10+0x30);
DisplayOneChar(12,1,temp1%10+0x30);
DisplayOneChar(14,1,temp2+0x30);
//=================================
WriteCommandLCM(0x0f,1);//显示屏打开,光标显示、闪烁,检测忙信号
DisplayOneChar(3,0,hour/10+0x30);
DisplayOneChar(4,0,hour%10+0x30);
}
/********************************************/
void fun2(void) //液晶显示子函数2
{
WriteCommandLCM(0x0c,1);//显示屏打开,光标不显示、不闪烁,检测忙信号
DisplayListChar(0,0,str0);
DisplayListChar(0,1,str1);
//=========================
DisplayOneChar(3,0,hour/10+0x30);
DisplayOneChar(4,0,hour%10+0x30);
//=================================
DisplayOneChar(9,0,sec/10+0x30);
上一页 [1] [2] [3] [4] 下一页
本文关键字:程序 51单片机,单片机-工控设备 - 51单片机