資源簡介
用ds18b20測量溫度并在帶中文字庫的12864液晶屏上顯示,設(shè)置上限溫度用于防火報(bào)警。
代碼片段和文件信息
/***************************lcd12864部分******************************/
#include?
#define?uint??unsigned?int
#define?uchar?unsigned?char
#define?x1????0x80
#define?x2????0x88
#define?y?????0x80
#define?comm??0
#define?dat???1
sbit?rs?=?P3^7;???//H=data;?L=command;
sbit?rw?=?P3^6;???//H=read;?L=write;
sbit??e?=?P3^5;???//input?enable;
sbit?psb=?P0^3;???//H=并口;?L=串口;
sbit?rst=?P0^1;???//Reset?Signal?低電平有效
//并行數(shù)據(jù)口接P2口
//還可以另外定義一個(gè)lcd?busy?bit可用于接指示燈等指示lcd忙狀態(tài)
//部分函數(shù)聲明:
void?wr_lcd?(uchar?dat_commuchar?content);
void?chk_busy?(void);
void?delayus(uint?us);
void?delayms(uint?ms);
/******************************************************************************************
*?函數(shù)名稱????:delay
*?功能描述????:延時(shí)10*us?
******************************************************************************************/
void?delayus(uint?us)???//delay?time
{
?? while(us--);
}
/******************************************************************************************
*?函數(shù)名稱????:delayms
*?功能描述????:?延時(shí)ms毫秒
******************************************************************************************/
void?delayms(uint?ms)
{
?? uint?ij;
?? for(i=0;i ?? for(j=0;j<15;j++)
?? delayus(1);
}
/******************************************************************************************
*?函數(shù)名稱????:init_lcd
*?功能描述????:?初始化
******************************************************************************************/
void?init_lcd(void)
{
?? rst=1;
?? psb=1;
?? wr_lcd(comm0x30);??/*30---基本指令動(dòng)作*/???
?? wr_lcd(comm0x01);??/*清屏,地址指針指向00H*/
?? wr_lcd(comm0x06);??/*光標(biāo)的移動(dòng)方向*/
?? wr_lcd(comm0x0c);??/*開顯示,關(guān)游標(biāo)*/
}
/******************************************************************************************
*?函數(shù)名稱:locate_lcd
*?功能描述:?lcd定位顯示
******************************************************************************************/
void?locate_lcd(unsigned?char?poxunsigned?char?poy)//行數(shù)pox=1-4;每行
???????????????????????????????????????????????????//有8個(gè)poy=1-8?????
{???unsigned?char?data?pos;
????if(pox&0x01)?//第一、三行,pox=0x010x03
?????{??
?????????pos=poy|0x80;
?????????if(pox&0x02)?pos+=0x07;//pos=poy+0x80+0x07第三行
?????????else??pos-=0x01;?//pos=poy+0x80-0x01第一行???????????
??????
??????}
????else
{
?????pos=poy|0x90;
?????if(pox&0x02)?pos-=0x01;//pos=poy+0x90-0x01第二行
?????else?pos+=poy|0x07;?//pos=poy+0x90+0x07第四行
}
?????wr_lcd(commpos);
}
/******************************************************************************************
*?函數(shù)名稱????:wr_lcd
*?功能描述????:寫控制命令或顯示數(shù)據(jù)
******************************************************************************************/
void?wr_lcd(uchar?dat_commuchar?content)
{
?? chk_busy();
?? if(dat_comm)
??? {
???? rs=1;???//data
???? rw=0;???//write
??? }
?? else?
??? {
???? rs=0;???//command
???? rw=0;???//write
??? }
?? P2=content;???//output?data?or?comm
?? e=1;
?? ;
?? e=0;
}
/***********************************************************************
評論
共有 條評論