lcd12864帶中文字庫的128X64 是一種具有4 位/8 位并行、2 線或3 線串行多種接口方式,內(nèi)部含有國標(biāo)一級、二級簡體 中文字庫的點陣圖形液晶顯示模塊;其顯示分辨率為128×64, 內(nèi)置8192 個16*16 點漢字,和128 個16*8 點ASCII 字符 集。利用該模塊靈活的接口方式和簡單、方便的操作指令,可構(gòu)成全中文人機交互圖形界面??梢燥@示8×4 行16×16 點 陣的漢字。 也可完成圖形顯示。低電壓低功耗是其又一顯著特點。
lcd12864萬年歷程序
#include《reg52.H》#include《intrins.h》#include《math.h》
////////////////////////////////////////DS18B20#defineucharunsignedchar#defineuintunsignedintsbitDQ=P1^0;
//定義DS18B20的單總線
#defineLcd_BusP0
sbitLCD_RS=P2^7;//數(shù)據(jù)/命令選擇sbitLCD_RW=P2^6;//讀寫控制sbitLCD_EN=P2^5;//片選信號
#defineLCD_DATAP0//8bit數(shù)據(jù)線#defineLOW0#defineHIGH1
//初始化指令
#defineCLEAR_SCREEN0x01//清屏指令:清屏且AC值為00H#defineAC_INIT0x02//將AC設(shè)置為00H。且游標(biāo)移到原點位置
#defineCURSE_ADD0x06//設(shè)定游標(biāo)移到方向及圖像整體移動方向(默認游標(biāo)右移,圖像整體不動)
#defineFUN_MODE0x30//工作模式:8位基本指令集
#defineDISPLAY_ON0x0c//顯示開,顯示游標(biāo),且游標(biāo)位置反白#defineDISPLAY_OFF0x08//顯示關(guān)
#defineCURSE_DIR0x14//游標(biāo)向右移動:AC=AC+1
#defineSET_CG_AC0x40//設(shè)置AC,范圍為:00H~3FH
#defineSET_DD_AC0x80
#defineFUN_MODEK0x36//擴展指令集,8位指令
#defineX1address0x80//上半屏X軸起始地址
#defineX2address0x88//下半屏X軸起始地址
#defineYaddress0x80//Y軸起始地址
#defineSet_Column0x40#defineSet_Page0xB8
ucharcodeshu[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
ucharcodexingqi[]=“星期”;
ucharcodehanzishu[]=“一二三四五六日”;unsignedcharTempData=0;doubleDS18B20Data;uintjiemian=0;
//////////////////////////////////////////DS1302sbitDS1302_RST=P1^4;sbitDS1302_IO=P1^3;sbitDS1302_SCK=P1^2;
unsignedchartable[]={0X00,0X18,0X0c,0X15,0X06,0X01,0X0a};//0s24min12hour14ri5yue5zhou2010nianunsignedchardatatable1[7];
//ucharcodetable2[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};ucharcodeshuzi[]={
0x00,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,};
unsignedcharaa,bb;
ucharmiaoge,miaoshi,fenge,fenshi,shige,shishi,rige,rishi,yuege,yueshi,zhou,niange,nianshi;
ucharshezhinum=0;
//unsignedcharshi,ge;
////////////////////////////////////////////////鍵盤掃描
sbitkey_mnue=P3^7;
sbitkey_jia=P2^0;
sbitkey_jian=P2^1;
sbitkey_enter=P2^2;
ucharkey_number=0;
//intnian,yue,ri,shi,fen;
/////////////////////////////////////////////////紅外
sbitHW_IRQ=P3^2;//定義38KHz一體化紅外接收頭與
CPU的連接unsignedchar
DT;
staticunsignedchardataIRCode[3],IRCON,IRCON2;
//////////////////////////////////////////////////蜂鳴器sbitBEEP=P1^1;
/********************************************************************************************
*函數(shù)名稱:DS18B20_Delay()
*功能:DS18B20軟件延時專用
*入口參數(shù):count延時參數(shù),值越大,延時越長
*出口參數(shù):無
*********************************************************************************************/
voidDS18B20_Delay(uintcount)//延時函數(shù){
while(count--);}
/********************************************************************************************
*函數(shù)名稱:DS18B20_Init()*功能:DS18B20初始化*入口參數(shù):無
*出口參數(shù):返回值為1則初始化成功*返回值為0則初始化失敗
*********************************************************************************************/
ucharDS18B20_Init(void){
ucharx=0;
DQ=1;
//DQ復(fù)位DS18B20_Delay(8);
//稍做延時
DQ=0;
//單片機將DQ拉低DS18B20_Delay(80);//精確延時,大于480usDQ=1;
//拉高總線DS18B20_Delay(14);//稍做延時后
x=DQ;//若x=0則初始化成功,若x=1則
初始化失敗
DS18B20_Delay(20);
return(~x);}
/********************************************************************************************
*函數(shù)名稱:DS18B20_Read1Byte()*功能:從DS18B20讀一個字節(jié)*入口參數(shù):無
*出口參數(shù):從DS18B20讀出的一個字節(jié)
*********************************************************************************************/
ucharDS18B20_Read1Byte(void){
uchari=0;uchardat=0;for(i=8;i》0;i--){
DQ=0;//給脈沖信號dat》》=1;DQ=1;
//給脈沖信號
if(DQ)dat|=0x80;DS18B20_Delay(4);}
return(dat);}
/********************************************************************************************
*函數(shù)名稱:DS18B20_Write1Byte()
*功能:向DS18B20寫一個字節(jié)
*入口參數(shù):dat要寫入DS18B20的一字節(jié)數(shù)據(jù)
*出口參數(shù):無
*********************************************************************************************/
voidDS18B20_Write1Byte(uchardat){
uchari=0;
for(i=8;i》0;i--){
DQ=0;
DQ=dat&0x01;DS18B20_Delay(5);
DQ=1;dat》》=1;}}
/********************************************************************************************
*函數(shù)名稱:Read_Disp_Temperature()*功能:讀取并顯示溫度*入口參數(shù):無*出口參數(shù):無
*********************************************************************************************/
doubleRead_Disp_Temperature(void){
uinta=0,b=0,c=0,d=0,e=0,t=0;doublett=0;
DS18B20_Init();
DS18B20_Write1Byte(0xCC);//跳過讀序號列號的操作
DS18B20_Write1Byte(0x44);//啟動溫度轉(zhuǎn)換
DS18B20_Init();
DS18B20_Write1Byte(0xCC);//跳過讀序號列號的操作
DS18B20_Write1Byte(0xBE);//讀取溫度寄存器
a=DS18B20_Read1Byte();
b=DS18B20_Read1Byte();
t=b;
t《《=8
t=t|a;
//tt=t*0.0625;
returnt;
}
//*****************************************************************//函數(shù)名稱:delay(uintt)延時函數(shù)。對于12M晶振大約延時1ms//入口參數(shù):t//出口參數(shù):無
//*****************************************************************voiddelay(uintt){
uinti;while(t--){
for(i=0;i《125;i++);}}
////////////////////////////////////////////////////////////////蜂鳴器鳴叫voidFM(){
BEEP=0;delay(100);BEEP=1;}
//*****************************************************************//函數(shù)名稱:write_cmd(uintlcd_cmd)寫指令//入口參數(shù):lcd_cmd//返回參數(shù):無
//*****************************************************************voidWriteCmd12864(ucharlcd_cmd){
LCD_RS=LOW;LCD_RW=LOW;LCD_EN=HIGH;
LCD_DATA=lcd_cmd;LCD_EN=LOW;}
//****************************************************************
//函數(shù)名稱:write_data(uintlcd_data)寫數(shù)據(jù)
//入口參數(shù):current_data
//返回參數(shù):無
//****************************************************************
voidWriteData12864(ucharlcd_data)
{
LCD_RS=HIGH;
LCD_RW=LOW;
LCD_EN=HIGH;
LCD_DATA=lcd_data;
LCD_EN=LOW;}
/****************************************************************
函數(shù)名稱:Write12864(uint)寫數(shù)據(jù)
入口參數(shù):cmd,data
返回參數(shù):無
****************************************************************/
voidWrite12864(ucharlcd_cmd,ucharlcd_data)
{
WriteCmd12864(lcd_cmd);
WriteData12864(lcd_data);
}
//****************************************************************
//函數(shù)名稱:ReadBusy()判忙
//入口參數(shù):無
//返回參數(shù):
“1”忙;
“0”不忙
//****************************************************************
voidReadBusy(void)
{
uchari=5;
while(i--);}
/****************************************************************
函數(shù)名稱:LcdInit()初始化
入口參數(shù):無
返回參數(shù):無
****************************************************************/
voidLcdInit()
{
delay(50);
WriteCmd12864(FUN_MODE);delay(1);
//WriteCmd12864(FUN_MODE);//delay(1);
WriteCmd12864(DISPLAY_ON);delay(1);
//WriteCmd12864(AC_INIT);//delay(1);
WriteCmd12864(CLEAR_SCREEN);delay(20);
WriteCmd12864(CURSE_ADD);delay(1);}
/****************************************************************
函數(shù)名稱:LcdClear()清屏
入口參數(shù):無
返回參數(shù):無
****************************************************************/voidLcdClear(void){
ReadBusy();
WriteCmd12864(CLEAR_SCREEN);delay(3);}
voidwrite_date(uchardate){
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
P0=date;delay(5);
LCD_EN=1;delay(5);
LCD_EN=0;
}
voidinput1byte(unsignedchardate)
{
unsignedchari;for(i=0;i《8;i++)
{
DS1302_IO=date&0x01;DS1302_SCK=0;DS1302_SCK=1;date》》=1;}}
unsignedcharread1byte(){
unsignedchari,date=0;for(i=0;i《8;i++){
date》》=1;
DS1302_SCK=1;DS1302_SCK=0;DS1302_IO=1;
if(DS1302_IO)date=date|0x80;}
returndate;}
voidwrite1302(unsignedcharaddress,unsignedchardate){
DS1302_RST=0;DS1302_SCK=0;DS1302_RST=1;input1byte(address);input1byte(date);DS1302_RST=0;DS1302_SCK=1;}
unsignedcharread1302(unsignedcharaddress){
unsignedcharucdat;
DS1302_RST=0;
DS1302_SCK=0;
DS1302_RST=1;
input1byte(address);
ucdat=read1byte();
DS1302_RST=0;
DS1302_SCK=1;
returnucdat;
}
voidset1302(unsignedcharaddress,unsignedchartable[],unsignedcharn){
unsignedchari;
write1302(0x8e,0x00);for(i=0;i《n;i++){
write1302(address,table[i]);address+=2;}
write1302(0x8e,0x80);}
voidread1302xulie(unsignedcharaddress,unsignedcharn){
unsignedchari;for(i=0;i《n;i++){
table1[i]=read1302(address);address+=2;}}
voidinit1302(){
DS1302_RST=0;DS1302_SCK=0;
write1302(0x8e,0x00);//取消寫保護
write1302(0x90,0x00);//清零涓流充電寄存器
}
voidchuli()
{
unsignedcharaa,bb,i;
for(i=0;i《7;i++)
{
aa=table[i]/10;
bb=table[i]%10;
table[i]=(aa《《4)|bb;
}
}
voidchuli2(unsignedcharz){
aa=table1[z]&0x0f;
//年
bb=(table1[z]&0xf0)》》4;table1[z]=bb*10+aa;}
voidjiashijian(){
switch(key_number)
{
case0:break;case1:table1[6]++;
//if(table1[6]==10)table1[6]=5;
write1302(0x8e,0x00);
write1302(0x8c,table[6]);
write1302(0x8e,0x80);_nop_();
_nop_();break;
case2:table1[4]++;
if(table1[4]==13)table1[4]=1;
write1302(0x8e,0x00);
write1302(0x88,table1[4]);
write1302(0x8e,0x80);
_nop_();
_nop_();
break;
case3:table1[3]++;
if(table1[3]==31)table1[3]=1;
write1302(0x8e,0x00);
write1302(0x86,table1[3]);
write1302(0x8e,0x80);
_nop_();
_nop_();
break;
case4:table1[5]++;
if(table1[5]==8)table1[5]=1;
write1302(0x8e,0x00);
write1302(0x8a,table1[5]);
write1302(0x8e,0x80);
_nop_();
_nop_();
break;
case5:table1[2]++;
if(table1[2]==24)table1[2]=0;
write1302(0x8e,0x00);
write1302(0x84,table1[2]);
write1302(0x8e,0x80);
_nop_();
_nop_();
break;case6:
table1[1]++;
if(table1[1]==61)table1[1]=0;
write1302(0x8e,0x00);
write1302(0x82,table1[1]);
table1[0]=0;
write1302(0x80,0);
write1302(0x8e,0x80);
_nop_();
_nop_();
break;
}
}
voidjianshijian(){
switch(key_number)
{
case0:break;case1:table1[6]--;
if(table1[6]》99)table1[6]=99;
write1302(0x8e,0x00);
write1302(0x8c,table1[6]);
write1302(0x8e,0x80);
_nop_();
_nop_();
break;
case2:table1[4]--;
if(table1[4]==0)table1[4]=12;
write1302(0x8e,0x00);
write1302(0x88,table1[4]);
write1302(0x8e,0x80);_nop_();
_nop_();
break;
case3:table1[3]--;
if(table1[3]==0)table1[3]=31;
write1302(0x8e,0x00);
write1302(0x86,table1[3]);
write1302(0x8e,0x80);
_nop_();
_nop_();
break;
case4:table1[5]--;
if(table1[5]==0)table1[5]=7;
write1302(0x8a,table1[5]);write1302(0x8e,0x80);_nop_();_nop_();break;case5:
table1[2]--;
if(table1[2]==-1)table1[2]=0;write1302(0x8e,0x00);write1302(0x84,table1[2]);write1302(0x8e,0x80);_nop_();
_nop_();break;case6:
table1[1]--;
if(table1[1]》60)table1[1]=60;write1302(0x8e,0x00);write1302(0x82,table1[1]);table1[0]=0;
write1302(0x80,0);write1302(0x8e,0x80);_nop_();
_nop_();break;
}
}keyscan(){
if(key_mnue==0){
delay(10);
if(key_mnue==0){FM();
key_number++;}
if(key_number==7)
{FM();
key_number=1;}}
while(!key_mnue);if(key_jia==0){
delay(10);if(key_jia==0){
FM();
jiashijian();}}
while(!key_jia);if(key_jian==0){
delay(10);
if(key_jian==0){
FM();
jianshijian();}
}
while(!key_jian);if(key_enter==0){
delay(10);
if(key_enter==0){FM();
key_number=0;}}
while(!key_enter);
jiemian++;
if(jiemian==15){
ReadBusy();jiemian=0;
switch(key_number)//調(diào)時間時界面顯示{
//case0:WriteCmd12864(0x08);
break;case1:WriteCmd12864(0x83);
ReadBusy();
WriteData12864(0x5f);ReadBusy();
WriteData12864(0x5f);break;
case2:WriteCmd12864(0x84);
ReadBusy();
WriteData12864(0x5f);ReadBusy();
WriteData12864(0x5f);break;
case3:WriteCmd12864(0x85);
ReadBusy();
WriteData12864(0x5f);ReadBusy();
WriteData12864(0x5f);break;
case4:WriteCmd12864(0x95);
ReadBusy();
WriteData12864(0x5f);ReadBusy();
WriteData12864(0x5f);break;
case5:WriteCmd12864(0x8a);
ReadBusy();
WriteData12864(0x5f);ReadBusy();
WriteData12864(0x5f);break;
case6:WriteCmd12864(0x8b);
ReadBusy();
WriteData12864(0x3a);ReadBusy();
WriteData12864(0x5f);ReadBusy();
WriteData12864(0x5f);break;}}}
voidmain(void){
uinta=0,b=0,c=0,t=0,tt;ucharerhang=0;
TMOD=0x01;
//定時器0方式1
EA=1;//允許CPU中斷IT0=1;
//INT0下降沿有效EX0=1;
//開INT0中斷
init1302();//chuli();
//set1302(0x80,table,7);
LcdClear();
while(1){
LcdInit();
//液晶初始化
LcdClear();
delay(100);
WriteCmd12864(FUN_MODE);
LcdClear();
ReadBusy();
while(1){
tt=Read_Disp_Temperature();
DS18B20Data=tt*0.0625;
t=DS18B20Data*10+0.5;
//放大10倍
輸出并四舍五入
a=t/100;
//十位b=t/10-a*10;//個位//DS_20[1]=0x24;c=t-a*100-b*10;//小數(shù)位
read1302xulie(0x81,7);
chuli2(0);
//miaomiaoshi=table1[0]/10;
miaoge=table1[0]%10;
chuli2(1);
//minfenshi=table1[1]/10;
fenge=table1[1]%10;
chuli2(2);
//hourshishi=table1[2]/10;
shige=table1[2]%10;
chuli2(3);
//ririshi=table1[3]/10;
rige=table1[3]%10;
chuli2(4);
//yueyueshi=table1[4]/10;
yuege=table1[4]%10;
chuli2(5);
//xingqi
zhou=table1[5];
chuli2(6);
//年nianshi=table1[6]/10;
niange=table1[6]%10;
ReadBusy();
WriteCmd12864(0x9b);
//第四行顯示ReadBusy();
WriteData12864(shu[a]);
ReadBusy();
WriteData12864(shu[b]);
//WriteCmd12864(0x9d);
ReadBusy();
WriteData12864(0x2e);
ReadBusy();
WriteData12864(shu[c]);
ReadBusy();
//WriteCmd12864(0x9e);
ReadBusy();
WriteData12864(0x60);
ReadBusy();
WriteData12864(0x43);
ReadBusy();
keyscan();
ReadBusy();
WriteCmd12864(0x92);
//第二行顯示
ReadBusy();
for(erhang=0;
erhang《4;erhang++)
{
write_date(xingqi[erhang]);
ReadBusy();
}
WriteCmd12864(0x95);
ReadBusy();
for(erhang=0;erhang《2;
erhang++)
{
write_date(hanzishu[erhang+zhou*2-2]);
ReadBusy();}
ReadBusy();
keyscan();
ReadBusy();
WriteCmd12864(0x82);
//第一行顯示ReadBusy();
WriteData12864(shu[2]);
ReadBusy();
WriteData12864(shu[0]);
ReadBusy();
WriteData12864(shu[nianshi]);
ReadBusy();
WriteData12864(shu[niange]);
//WriteCmd12864(0x9d);
ReadBusy();
WriteData12864(shu[yueshi]);
ReadBusy();
WriteData12864(shu[yuege]);
ReadBusy();
//WriteCmd12864(0x9e);
ReadBusy();
WriteData12864(shu[rishi]);
ReadBusy();
WriteData12864(shu[rige]);
ReadBusy();
keyscan();
ReadBusy();
第19頁共19頁
WriteCmd12864(0x8a);
//第三行顯示ReadBusy();
WriteData12864(shu[shishi]);
ReadBusy();
WriteData12864(shu[shige]);
//WriteCmd12864(0x9d);
ReadBusy();
WriteData12864(0x3a);
ReadBusy();
WriteData12864(shu[fenshi]);
ReadBusy();
//WriteCmd12864(0x9e);
ReadBusy();
WriteData12864(shu[fenge]);
ReadBusy();
WriteData12864(0x3a);
ReadBusy();
WriteData12864(shu[miaoshi]);
ReadBusy();
//WriteCmd12864(0x9e);
ReadBusy();
WriteData12864(shu[miaoge]);
ReadBusy();
ReadBusy();
keyscan();
ReadBusy();
ReadBusy();
評論
查看更多