lcd12864带中文字库的128X64 是一种具有4 位/8 位并行、2 线或3 线串行多种接口方式,内部含有国标一级、二级简体 中文字库的点阵图形液晶显示模块;其显示分辨率为128×64, 内置8192 个16*16 点汉字,和128 个16*8 点ASCII 字符 集。利用该模块灵活的接口方式和简单、方便的 *** 作指令,可构成全中文人机交互图形界面。可以显示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;//数据/命令选择sbitLCD_RW=P2^6;//读写控制sbitLCD_EN=P2^5;//片选信号
#defineLCD_DATAP0//8bit数据线#defineLOW0#defineHIGH1
//初始化指令
#defineCLEAR_SCREEN0x01//清屏指令:清屏且AC值为00H#defineAC_INIT0x02//将AC设置为00H。且游标移到原点位置
#defineCURSE_ADD0x06//设定游标移到方向及图像整体移动方向(默认游标右移,图像整体不动)
#defineFUN_MODE0x30//工作模式:8位基本指令集
#defineDISPLAY_ON0x0c//显示开,显示游标,且游标位置反白#defineDISPLAY_OFF0x08//显示关
#defineCURSE_DIR0x14//游标向右移动:AC=AC+1
#defineSET_CG_AC0x40//设置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;
/********************************************************************************************
*函数名称:DS18B20_Delay()
*功能:DS18B20软件延时专用
*入口参数:count延时参数,值越大,延时越长
*出口参数:无
*********************************************************************************************/
voidDS18B20_Delay(uintcount)//延时函数{
while(count--);}
/********************************************************************************************
*函数名称:DS18B20_Init()*功能:DS18B20初始化*入口参数:无
*出口参数:返回值为1则初始化成功*返回值为0则初始化失败
*********************************************************************************************/
ucharDS18B20_Init(void){
ucharx=0;
DQ=1;
//DQ复位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);}
/********************************************************************************************
*函数名称:DS18B20_Read1Byte()*功能:从DS18B20读一个字节*入口参数:无
*出口参数:从DS18B20读出的一个字节
*********************************************************************************************/
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);}
/********************************************************************************************
*函数名称:DS18B20_Write1Byte()
*功能:向DS18B20写一个字节
*入口参数:dat要写入DS18B20的一字节数据
*出口参数:无
*********************************************************************************************/
voidDS18B20_Write1Byte(uchardat){
uchari=0;
for(i=8;i》0;i--){
DQ=0;
DQ=dat&0x01;DS18B20_Delay(5);
DQ=1;dat》》=1;}}
/********************************************************************************************
*函数名称:Read_Disp_Temperature()*功能:读取并显示温度*入口参数:无*出口参数:无
*********************************************************************************************/
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);//启动温度转换
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;
}
//*****************************************************************//函数名称:delay(uintt)延时函数。对于12M晶振大约延时1ms//入口参数:t//出口参数:无
//*****************************************************************voiddelay(uintt){
uinTI;while(t--){
for(i=0;i《125;i++);}}
////////////////////////////////////////////////////////////////蜂鸣器鸣叫voidFM(){
BEEP=0;delay(100);BEEP=1;}
//*****************************************************************//函数名称:write_cmd(uintlcd_cmd)写指令//入口参数:lcd_cmd//返回参数:无
//*****************************************************************voidWriteCmd12864(ucharlcd_cmd){
LCD_RS=LOW;LCD_RW=LOW;LCD_EN=HIGH;
LCD_DATA=lcd_cmd;LCD_EN=LOW;}
//****************************************************************
//函数名称:write_data(uintlcd_data)写数据
//入口参数:current_data
//返回参数:无
//****************************************************************
voidWriteData12864(ucharlcd_data)
{
LCD_RS=HIGH;
LCD_RW=LOW;
LCD_EN=HIGH;
LCD_DATA=lcd_data;
LCD_EN=LOW;}
/****************************************************************
函数名称:Write12864(uint)写数据
入口参数:cmd,data
返回参数:无
****************************************************************/
voidWrite12864(ucharlcd_cmd,ucharlcd_data)
{
WriteCmd12864(lcd_cmd);
WriteData12864(lcd_data);
}
//****************************************************************
//函数名称:ReadBusy()判忙
//入口参数:无
//返回参数:
“1”忙;
“0”不忙
//****************************************************************
voidReadBusy(void)
{
uchari=5;
while(i--);}
/****************************************************************
函数名称:LcdInit()初始化
入口参数:无
返回参数:无
****************************************************************/
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);}
/****************************************************************
函数名称:LcdClear()清屏
入口参数:无
返回参数:无
****************************************************************/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)//调时间时界面显示{
//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;//小数位
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();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)