單片機的動手實踐篇--51單片機玩轉(zhuǎn)12864
12864液晶的驅(qū)動和1602的類似,只不過是多了幾個擴展的功能,不如畫圖功能:
本文引用地址:http://www.ex-cimer.com/article/201701/342707.htm這里講一下:不要簡單的認(rèn)為12864是y軸64,x為128,那是點陣的分布,不是讀寫的分布,如正圖表示,y軸的32行,從0到31,x軸的16 從0到15,0到7為上半個屏幕,8到15在下半個屏幕,所以繪圖的時候,有兩個部分要進行書寫
在12864上載入任意一幅圖:
示例代碼:
#include
#define uint unsigned int
#define uchar unsigned char
sbit lcdrs = P2^4;//數(shù)據(jù)還是指令的選擇端口
sbit lcdwr = P2^5;//讀寫操作端口
sbit lcden = P2^6;//使能端延時端口
sbit PSB = P2^1;//串行數(shù)據(jù)還是并行數(shù)據(jù)的選擇段
//圖片的編碼,這幅圖片的編碼是一個哆啦a夢
unsigned char code pic1[] = { /* 0X10,0X01,0X00,0X80,0X00,0X40, */
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0XFF,0XFF,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X3F,0XC0,0X0F,0XC0,0X0F,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X07,0XFF,0X00,0X07,0X80,0X03,0XFE,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X3F,0XFE,0XF7,0XFF,0XFF,0XFF,0XFF,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0XFF,0XFE,0X00,0X01,0X80,0X01,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X03,0XFF,0XFE,0X00,0X03,0XFF,0X01,0X0F,0XFE,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X0F,0XFF,0X83,0X00,0X07,0XFB,0X86,0X00,0XFF,0X80,0X00,0X00,0X00,0X00,
0X00,0X00,0X1F,0XFE,0X00,0XE0,0X0F,0XFF,0XFC,0X00,0X1F,0XC0,0X00,0X00,0X00,0X00,
0X00,0X00,0X7F,0XF8,0X00,0X3F,0XE3,0XFF,0X00,0X00,0X07,0XF0,0X00,0X00,0X00,0X00,
0X00,0X00,0XFF,0XE0,0X00,0X00,0X00,0X38,0X00,0X00,0X01,0XF8,0X00,0X00,0X00,0X00,
0X00,0X01,0XFF,0XC7,0X7F,0XF0,0X00,0X0C,0X00,0X1F,0XFF,0XFC,0X00,0X00,0X00,0X00,
0X00,0X01,0XFF,0X00,0X00,0X00,0X00,0X04,0X00,0X00,0X00,0X7E,0X00,0X00,0X00,0X00,
0X00,0X03,0XFF,0X00,0X00,0X00,0X00,0X06,0X00,0X03,0XC0,0X3E,0X00,0X00,0X00,0X00,
0X00,0X03,0XFE,0X0F,0XFF,0XF0,0X00,0X02,0X00,0X0C,0X3F,0X9E,0X00,0X00,0X00,0X00,
0X00,0X07,0XFC,0X00,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X1F,0X00,0X00,0X00,0X00,
0X00,0X07,0XFC,0X00,0X1F,0XC0,0X00,0X02,0X00,0X00,0X00,0X0F,0X00,0X00,0X00,0X00,
0X00,0X07,0XF8,0X03,0XE0,0X00,0X00,0X02,0X00,0X07,0XFE,0X0F,0X00,0X00,0X00,0X00,
0X00,0X07,0XF8,0X1E,0X00,0X00,0X00,0X02,0X00,0X00,0X01,0XC6,0X00,0X00,0X00,0X00,
0X00,0X07,0XF8,0X30,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,
0X00,0X03,0XFC,0X00,0X00,0X00,0X00,0X02,0X00,0X03,0XFE,0X0E,0X00,0X00,0X00,0X00,
0X00,0X01,0XFC,0X00,0X00,0X00,0X00,0X7F,0XC0,0X00,0X03,0X0C,0X00,0X00,0X00,0X00,
0X00,0X01,0XFE,0X00,0X00,0X00,0X3F,0X80,0X3E,0X00,0X01,0X18,0X00,0X00,0X00,0X00,
0X00,0X00,0XFE,0X00,0X00,0X0F,0XC0,0X00,0X01,0XF0,0X06,0X30,0X00,0X00,0X00,0X00,
0X00,0X00,0X7F,0X00,0X01,0XE0,0X00,0X00,0X00,0X1F,0XF8,0X60,0X00,0X00,0X00,0X00,
0X00,0X00,0X3F,0X80,0X04,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0X00,0X00,0X00,0X00,
0X00,0X00,0X0F,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0X80,0X00,0X00,0X00,0X00,
0X00,0X00,0X03,0XF0,0X00,0X00,0X00,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0XFC,0X00,0X00,0X00,0X00,0X00,0X01,0XFC,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X01,0XFF,0XF8,0X00,0X03,0XFF,0XE0,0X1F,0XFF,0XC0,0X00,0X00,0X00,0X00,
0X00,0X00,0X07,0XFF,0XE0,0X00,0X03,0XFF,0XC0,0X07,0XFF,0XE0,0X00,0X00,0X00,0X00,
0X00,0X00,0X0F,0XFF,0XC0,0X00,0X00,0XFF,0X80,0X03,0XFF,0XF0,0X00,0X00,0X00,0X00,
0X00,0X00,0X1F,0XFF,0X80,0X00,0X00,0X00,0X00,0X01,0XFF,0XF8,0X00,0X00,0X00,0X00,
0X00,0X00,0X3F,0XFF,0X80,0X00,0X00,0X00,0X00,0X01,0XFF,0XF8,0X00,0X00,0X00,0X00,
0X00,0X00,0X7F,0XFF,0X80,0X00,0X00,0X00,0X00,0X01,0XFF,0XFC,0X00,0X00,0X00,0X00,
0X00,0X03,0X80,0X3F,0X80,0X0F,0XFF,0XFF,0XFC,0X01,0XFE,0X3E,0X00,0X00,0X00,0X00,
0X00,0X06,0X00,0X0F,0XC0,0X70,0X00,0X00,0X03,0XC1,0XF8,0X07,0X00,0X00,0X00,0X00,
0X00,0X06,0X00,0X07,0XE0,0X30,0X00,0X00,0X00,0X43,0XF8,0X03,0X00,0X00,0X00,0X00,
0X00,0X07,0X00,0X07,0XF0,0X38,0X00,0X00,0X00,0XCF,0XFC,0X03,0X00,0X00,0X00,0X00,
0X00,0X03,0XC0,0X1F,0XFC,0X0F,0X00,0X00,0X03,0X1F,0XFC,0X0E,0X00,0X00,0X00,0X00,
0X00,0X00,0X7F,0XFF,0XFF,0X81,0XF0,0X00,0XFC,0XFF,0XFE,0XF8,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X1F,0XFF,0XFE,0X1F,0XFF,0X1F,0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X1F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X1F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X1F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X0F,0XFF,0X07,0XF0,0XFF,0XF0,0X7F,0X8F,0X80,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X7F,0XFF,0X83,0XE0,0XFF,0XF8,0X0F,0XBF,0XF8,0X00,0X00,0X00,0X00,
0X00,0X00,0X01,0XDF,0XF8,0X7D,0XFF,0X7F,0X0F,0XFF,0XC7,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X07,0XFF,0XF7,0X00,0X41,0XEF,0XF8,0X02,0X0F,0X78,0X00,0X00,0X00,0X00,
0X00,0X00,0X0F,0XFF,0XCC,0X00,0X40,0X7F,0XE0,0X02,0X01,0XBF,0XE0,0X00,0X00,0X00,
0X00,0X00,0X0F,0XFE,0X07,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XE0,0X00,0X00,
0X00,0X00,0X01,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0X7E,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};
void delay1ms(uint x)//延時函數(shù)
{
uint i,j;
for(i= x;i>0;i--)
for(j=110;j>0;j--);
}
void write_cmd(uchar cmd)//寫指令函數(shù)
{
lcdrs = 0;
lcdwr = 0;
P0 = cmd;
lcden = 1;
delay1ms(5);//
lcden = 0;
}
void write_date(uchar date)//寫數(shù)據(jù)函數(shù)
{
lcdrs = 1;
lcdwr = 0;
P0 = date;
lcden = 1;
delay1ms(5);//
lcden = 0;
}
void init_12864()
{
PSB = 1;//確定是并行傳送
write_cmd(0x30);//基本指令操作
write_cmd(0x0c);//開顯示,關(guān)掉光標(biāo)
write_cmd(0x01);//清楚lcd的內(nèi)容
}
void lcd_putpic(unsigned char code *img)//載入圖畫的函數(shù)
{
uint i,j;
//顯示上半個屏幕的內(nèi)容
for(i = 0;i<32;i++)
{
write_cmd(0x80+i);//垂直的地址
write_cmd(0x80);//水平的地址
for(j=0;j<16;j++)
{
write_date(*img);
img++;
}
}
//顯示下半個屏幕的內(nèi)容
for(i = 0;i<32;i++)
{
write_cmd(0x80+i);//垂直的內(nèi)容
write_cmd(0x88);//水平的地址第三行的內(nèi)容
for(j=0;j<16;j++)
{
write_date(*img);
img++;
}
}
}
void setpic()//圖像顯示模式設(shè)置函數(shù)
{
write_cmd(0x36);//選擇8bit的數(shù)據(jù)流,圖像顯示模式
delay1ms(5);
}
main()
{
init_12864();//初始化液晶
setpic();//初始化液晶圖片顯示
lcd_putpic(pic1);//載入一幅圖片
delay1ms(5);
while(1);
}
以后載入圖片只需要將圖片用取模的軟件,注意圖片的大小必須是128x64的尺寸,否則會出現(xiàn)亂碼,這是個比較容易犯的錯誤,希望大家注意
評論