很好用的12864驱动程序.docx
《很好用的12864驱动程序.docx》由会员分享,可在线阅读,更多相关《很好用的12864驱动程序.docx(11页珍藏版)》请在冰豆网上搜索。
![很好用的12864驱动程序.docx](https://file1.bdocx.com/fileroot1/2022-11/27/4fa0a51e-d909-4415-ad51-e08495ff7847/4fa0a51e-d909-4415-ad51-e08495ff78471.gif)
很好用的12864驱动程序
///////////////////////////////////////////////////////////
#include<>
#include<>
#defineucharunsignedchar
#defineuintunsignedint
//////////单片机与液晶显示的引脚连接/////////
sbitP32=P3^2;//RST
sbitP33=P3^3;//CS2
sbitP34=P3^4;//CS1
sbitP35=P3^5;//E
sbitP36=P3^6;//rs&DI
sbitP37=P3^7;//R/W
////////延时/////////
voiddelay(uintv)
{
while(v!
=0)v--;
}
////////复位///////////
voidreset()
{
P32=0;
delay(10);
P32=1;
delay(10);
}
////////writecode写指令///////
voidwcode(ucharc,ucharcs1,ucharcs2)
{
P34=cs1;
P33=cs2;
P37=0;
P36=0;
P1=c;
P35=0;
delay(10);
P35=1;
delay(10);
P35=0;
}
/////////writedata写数据///////////////
voidwdata(ucharc,ucharcs1,ucharcs2)
{
P34=cs1;
P33=cs2;
P37=1;
P36=0;
P1=c;
P35=0;
delay(10);
P35=1;
delay(10);
P35=0;
}
////////////setstart设置起始行/////////////
voidset_startline(uchari)//起始行。
11A5A4A3A2A1A0共有64行
//液晶显示器的最底层为第一行
{
i=0xc0+64-i;//此算法为把最顶层做为第一层
wcode(i,1,1);
}
////////////set页值设置,起始列值函数/////////////
voidset_adr(ucharx,uchary)
{
x=x+0xb8;//页地址设置。
10111A2A1A0DDRAM的8行为一页,A0~A2为页码,LCD为64行8页
y=y+0x40;//列地址设置。
01A5A4A3A2A1A0两半屏分别有64列,A0~A5送入列地址计数器,
//作为列(Y)地址指针。
每读写一次其自动加一,指向下一列DDRAM单元
wcode(x,1,1);
wcode(y,1,1);
}
///////////on/off开/关显示函数//////////////
voiddis_on_off(ucharo)
{
o=0x3e+o;//0011111DD=1开显示器把RAM数据呈现在显示器上,D=0关显示,但数据仍储存在RAM内。
wcode(o,1,1);
}
///////////clear清屏///////////////
voidclear()
{
uchari,loop;
for(i=0;i<8;i++)///循环页写0/////////
{
set_adr(i,0);
for(loop=0;loop<64;loop++)wdata(0x00,1,1);
}
}
/////////////////////////////////////////////////////////////////////////
//汉字字模表//
//汉字库:
宋体纵向取模下高位,数据排列:
从左到右从上到下//
/////////////////////////////////////////////////////////////////////////
ucharcodexian[32]=//"现"
{
0x04,0x84,0x84,0xFC,0x86,0x84,0x00,0xFE,
0x02,0x82,0x7A,0x02,0xFF,0x02,0x00,0x00,
0x10,0x30,0x10,0x1F,0x88,0x88,0x40,0x23,
0x18,0x07,0x78,0x80,0x83,0x80,0xE0,0x00,
};
ucharcodezai[32]=//"在"
{
0x08,0x08,0x08,0x08,0xC8,0x38,0x0F,0x08,
0x08,0xE8,0x08,0x88,0x08,0x0C,0x08,0x00,
0x08,0x04,0x02,0xFF,0x00,0x40,0x41,0x41,
0x41,0x7F,0x41,0x41,0x41,0x60,0x40,0x00,
};
ucharcodewen[32]=//"温"
{
0x10,0x22,0x64,0x0C,0x80,0x00,0xFE,0x92,
0x92,0x92,0x92,0x92,0xFF,0x02,0x00,0x00,
0x04,0x04,0xFE,0x01,0x40,0x7E,0x42,0x42,
0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,
};
ucharcodedu[32]=//"度"
{
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0xA5,
0xA6,0xA4,0xFC,0x24,0x34,0x26,0x04,0x00,
0x40,0x20,0x9F,0x80,0x42,0x42,0x26,0x2A,
0x12,0x2A,0x26,0x42,0x40,0xC0,0x40,0x00
};
ucharcodemaohao[16]=//-:
-
{0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00,
};
ucharcodewu[16]=//-5-
{0x7C,0x7C,0x44,0x44,0xC4,0xC4,0x84,0x00,
0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,
};
ucharcodeer[16]=//-2-
{0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00,
0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00,
};
ucharcodesan[16]=//-3-
{0x08,0x0C,0x44,0x44,0x44,0xFC,0xB8,0x00,
0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,
};
ucharcodeli[32]=//"理"
{
0x44,0x44,0xFC,0x46,0x44,0x00,0xFE,0x92,
0x92,0xFE,0x92,0x92,0xFF,0x02,0x00,0x00,
0x10,0x30,0x1F,0x08,0x48,0x48,0x44,0x44,
0x44,0x7F,0x44,0x46,0x44,0x60,0x40,0x00,
};
ucharcodegong[32]=//"工",
{
0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,
0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,
0x20,0x20,0x20,0x20,0x20,0x30,0x20,0x00,
};
ucharcodexue[32]=//"学",
{
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,
0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00,
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,
0x06,0x05,0x04,0x04,0x04,0x06,0x04,0x00,
};
ucharcodeyuan[32]=//院
{
0x00,0xFE,0x22,0x5A,0x96,0x0C,0x24,0x24,
0x25,0x26,0x24,0x34,0xA4,0x14,0x0C,0x00,
0x00,0xFF,0x04,0x08,0x87,0x81,0x41,0x31,
0x0F,0x01,0x3F,0x41,0x41,0x41,0x70,0x00,
};
ucharcodedian[32]=//"电",
{
0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,
0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00,
0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,
0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00,
};
ucharcodezi[32]=//"子",
{
0x80,0x80,0x82,0x82,0x82,0x82,0x82,0xE2,
0xA2,0x92,0x8A,0x86,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
ucharcodechuang[32]=//"创",
{
0x80,0x40,0xF0,0x4C,0x43,0x44,0xC8,0x10,
0x30,0x00,0xF8,0x00,0x00,0xFF,0x00,0x00,
0x00,0x00,0x3F,0x40,0x42,0x44,0x43,0x70,
0x00,0x00,0x07,0x40,0x80,0x7F,0x00,0x00,
};
ucharcodexin[32]=//"新",
{
0x40,0x44,0x54,0x65,0xC6,0x64,0xD6,0x44,
0x40,0xFC,0x44,0x42,0xC3,0x62,0x40,0x00,
0x20,0x11,0x49,0x81,0x7F,0x01,0x05,0x29,
0x18,0x07,0x00,0x00,0xFF,0x00,0x00,0x00,
};
ucharcodeshi[32]=//"实",
{
0x10,0x0C,0x04,0x44,0x8C,0x94,0x35,0x06,
0xF4,0x04,0x04,0x04,0x04,0x14,0x0C,0x00,
0x02,0x82,0x82,0x42,0x42,0x23,0x12,0x0E,
0x03,0x0A,0x12,0x22,0x42,0xC3,0x02,0x00,
};
ucharcodeyan[32]=//"验",
{
0x02,0xFA,0x02,0x02,0xFF,0x42,0x20,0x50,
0x4C,0x43,0x4C,0x50,0x20,0x60,0x20,0x00,
0x10,0x31,0x11,0x49,0x89,0x7F,0x42,0x5C,
0x40,0x4F,0x60,0x58,0x47,0x60,0x40,0x00,
};
ucharcodeban[32]=//"班",
{
0x84,0x84,0xFC,0x84,0x06,0xF4,0x00,0xFF,
0x00,0x84,0x84,0xFC,0x84,0x86,0x04,0x00,
0x20,0x60,0x3F,0x10,0x92,0x41,0x38,0x07,
0x40,0x40,0x40,0x7F,0x40,0x60,0x40,0x00
};
ucharcodexie[32]=//"谢"
{
0x40,0x42,0xCC,0x00,0xFC,0x56,0x55,0x54,
0xFE,0x24,0x20,0x20,0xFF,0x20,0x20,0x00,
0x00,0x00,0x3F,0x52,0x2B,0x12,0x4A,0x86,
0x7F,0x01,0x46,0x80,0x7F,0x00,0x00,0x00,
};
ucharcodeguo[32]=//"国"
{
0x00,0xFE,0x02,0x0A,0x8A,0x8A,0x8A,0xFA,
0x8A,0xCA,0x8E,0x0A,0x02,0xFF,0x02,0x00,
0x00,0xFF,0x40,0x50,0x50,0x50,0x50,0x5F,
0x50,0x52,0x54,0x50,0x40,0xFF,0x00,0x00,
};
ucharcodehua[32]=//"华"
{
0x00,0x40,0x20,0x10,0xFC,0x03,0x40,0x20,
0x10,0xFF,0x08,0x04,0x06,0xC0,0x00,0x00,
0x04,0x04,0x04,0x04,0x05,0x04,0x04,0xFF,
0x04,0x04,0x05,0x05,0x05,0x05,0x04,0x00,
};
//////////////main////////////////
voidmain()
{
ucharloop;
reset();//复位
dis_on_off
(1);///开关开,把RAM数据呈现在显示器上
set_startline(10);//从第0行开始显示
clear();//清屏
while
(1)
{
//以下为字符显示程序,主要程序思路为分左右屏写,同一页同一行内按左到右踔厉风顺序写
//同一字符分上下16半个字写代码
set_adr(0,32);
for(loop=0;loop<16;loop++)wdata(xian[loop],1,0);
for(loop=0;loop<16;loop++)wdata(zai[loop],1,0);
set_adr(1,32);
for(loop=16;loop<32;loop++)wdata(xian[loop],1,0);
for(loop=16;loop<32;loop++)wdata(zai[loop],1,0);
set_adr(0,0);
for(loop=0;loop<16;loop++)wdata(wen[loop],0,1);
for(loop=0;loop<16;loop++)wdata(du[loop],0,1);
set_adr(1,0);
for(loop=16;loop<32;loop++)wdata(wen[loop],0,1);
for(loop=16;loop<32;loop++)wdata(du[loop],0,1);
///////////////////////////////////////////////////第一行显示现在温度
/*set_adr(0,32);
for(loop=0;loop<8;loop++)wdata(maohao[loop],0,1);
set_adr(1,32);
for(loop=8;loop<16;loop++)wdata(maohao[loop],0,1);
set_adr(2,45);
for(loop=0;loop<8;loop++)wdata(wu[loop],1,0);
for(loop=0;loop<8;loop++)wdata(er[loop],1,0);
set_adr(3,45);
for(loop=8;loop<16;loop++)wdata(wu[loop],1,0);
for(loop=8;loop<16;loop++)wdata(er[loop],1,0);
set_adr(2,0);
for(loop=0;loop<8;loop++)wdata(san[loop],0,1);
set_adr(3,0);
for(loop=8;loop<16;loop++)wdata(san[loop],0,1);*/
set_adr(2,32);
for(loop=0;loop<16;loop++)wdata(li[loop],1,0);
for(loop=0;loop<16;loop++)wdata(gong[loop],1,0);
set_adr(3,32);
for(loop=16;loop<32;loop++)wdata(li[loop],1,0);
for(loop=16;loop<32;loop++)wdata(gong[loop],1,0);
set_adr(2,0);
for(loop=0;loop<16;loop++)wdata(xue[loop],0,1);
for(loop=0;loop<16;loop++)wdata(yuan[loop],0,1);
set_adr(3,0);
for(loop=16;loop<32;loop++)wdata(xue[loop],0,1);
for(loop=16;loop<32;loop++)wdata(yuan[loop],0,1);
///////////////////////////////////////////////////第一行显示理工学院
set_adr(0,16);
for(loop=0;loop<16;loop++)wdata(chuang[loop],1,0);
set_adr(4,16);
for(loop=0;loop<16;loop++)wdata(xin[loop],1,0);
set_adr(0,32);
for(loop=0;loop<16;loop++)wdata(shi[loop],0,1);
set_adr(1,16);
for(loop=16;loop<32;loop++)wdata(chuang[loop],1,0);
set_adr(5,16);
for(loop=16;loop<32;loop++)wdata(xin[loop],1,0);
set_adr(1,32);
for(loop=16;loop<32;loop++)wdata(shi[loop],0,1);
//set_adr(4,0);
//for(loop=8;loop<16;loop++)wdata(shi[loop],0,1);
set_adr(2,32);
for(loop=0;loop<16;loop++)wdata(yan[loop],0,1);
set_adr(4,32);
for(loop=0;loop<16;loop++)wdata(ban[loop],0,1);
//set_adr(5,0);
//for(loop=24;loop<32;loop++)wdata(shi[loop],0,1);
set_adr(3,32);
for(loop=16;loop<32;loop++)wdata(yan[loop],0,1);
set_adr(5,32);
for(loop=16;loop<32;loop++)wdata(ban[loop],0,1);
///////////////////////////////////////////////////第三行显示创新实验班
set_adr(4,32);
for(loop=0;loop<16;loop++)wdata(xie[loop],1,0);
for(loop=0;loop<16;loop++)wdata(guo[loop],1,0);
set_adr(5,32);
for(loop=16;loop<32;loop++)wdata(xie[loop],1,0);
for(loop=16;loop<32;loop++)wdata(guo[loop],1,0);
set_adr(4,0);
for(loop=0;loop<16;loop++)wdata(hua[loop],0,1);
set_adr(5,0);
for(loop=16;loop<32;loop++)wdata(hua[loop],0,1);
////////////////////////////////////////////////////第四行显示谢国华
}
}