新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > AMPIRE12864液晶C語(yǔ)言代碼

AMPIRE12864液晶C語(yǔ)言代碼

作者: 時(shí)間:2016-11-17 來(lái)源:網(wǎng)絡(luò) 收藏

本文引用地址:http://butianyuan.cn/article/201611/315462.htm

#include
#include

#define uchar unsigned char
#define uint unsigned int

#define RS_H() PORTD|=BIT(4);
#define RS_L() PORTD&=~BIT(4);
#define RW_H() PORTD|=BIT(5);
#define RW_L() PORTD&=~BIT(5);
#define E_H() PORTD|=BIT(6);
#define E_L() PORTD&=~BIT(6);

#define CS1_L() PORTA&=~BIT(6);//左屏
#define CS1_H() PORTA|=BIT(6);
#define CS2_L() PORTA&=~BIT(7);//右屏
#define CS2_H() PORTA|=BIT(7);
uchar ni[32]={0x40,0xF0,0x2C,0x43,0x20,0x98,0x0F,0x0A,0xE8,0x08,0x88,0x28,0x1C,0x08,0x00,0x00,0x00,0x7F,0x00,0x10,0x0C,0x03,0x21,0x40,0x3F,0x00,0x00,0x03,0x1C,0x08,0x00,0x00};
uchar ba[]={0x38,0x44,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar HZ[8][32] = {

{0x40,0xB2,0x96,0x9A,0x92,0xF6,0x9A,0x93,0x91,0x99,0x97,0x91,0x90,0x30,0x00,0x00,0x20,0xA0,0x90,0x4C,0x47,0x2A,0x2A,0x12,0x1A,0x26,0x22,0x40,0xC0,0x40,0x00,0x00},/*"愛(ài)",0*/

{0x20,0x20,0x22,0x22,0xFE,0x21,0x21,0x20,0x20,0xFF,0x20,0x22,0xAC,0x20,0x20,0x00,0x04,0x04,0x42,0x82,0x7F,0x01,0x01,0x10,0x10,0x08,0x07,0x1A,0x21,0x40,0xF0,0x00},/*"我",1*/

{0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00},/*"中",2*/

{0x20,0x10,0x08,0xFC,0x03,0x02,0x10,0x10,0x7F,0x88,0x88,0x84,0x86,0xE4,0x00,0x00,0x00,0x04,0x04,0x05,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00},/*"華",3*/

{0x20,0x20,0x22,0x22,0xFE,0x21,0x21,0x20,0x20,0xFF,0x20,0x22,0xAC,0x20,0x20,0x00,0x04,0x04,0x42,0x82,0x7F,0x01,0x01,0x10,0x10,0x08,0x07,0x1A,0x21,0x40,0xF0,0x00},/*"我",4*/

{0x00,0xF8,0x8C,0x8B,0x88,0xF8,0x40,0x30,0x8F,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x00,0x7F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x03,0x26,0x40,0x20,0x1F,0x00,0x00},/*"的",5*/

{0x00,0x18,0x04,0x14,0x94,0x94,0xD5,0xB6,0x14,0x14,0x94,0x04,0x14,0x0C,0x04,0x00,0x00,0x29,0x29,0x15,0x14,0x4A,0x89,0x44,0x3F,0x06,0x09,0x09,0x10,0x30,0x10,0x00}/*"家",6*/
};
//////////////////////////////
uchar ZM[][16]={
{0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},/*"h",0*/

{0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00},/*"t",1*/

{0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00},/*"t",2*/

{0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00},/*"p",3*/

{0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},/*":",4*/

{0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",5*/

{0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",6*/

{0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},/*"h",7*/

{0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"i",8*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},/*".",9*/

{0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"b",10*/

{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20},/*"a",11*/

{0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"i",12*/

{0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20},/*"d",13*/

{0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20},/*"u",14*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},/*".",15*/

{0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00},/*"c",16*/

{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},/*"o",17*/

{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F},/*"m",18*/

{0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",19*/

{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",20*/

{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",21*/

{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",22*/

{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",23*/

{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",24*/

{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",25*/

{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",26*/

{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},/*"7",27*/

{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",28*/

{0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",29*/

{0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"b",30*/

{0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"l",31*/

{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},/*"o",32*/

{0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00}/*"g",33*/

};
void delay(uint ms)
{
uint i,j;
for(i=0;ifor(j=0;j<1141;j++);
}


void Write_cmd(uchar cmd)
{
RS_L();
RW_L();
E_H();
PORTB=cmd;
delay(2);
E_L();;

}
void Write_data(uchar data)
{
RS_H();
RW_L();
E_H();
PORTB=data;
delay(2);
E_L();

}

void WriteStr(uchar *s)
{
while(*s)
{ Write_data(*s++);
delay(5);

}
}
init_12864()
{
DDRB=0XFF;
DDRD|=BIT(4)|BIT(5)|BIT(6);//RS RW E
DDRA|=BIT(6)|BIT(7);//CS1 CS2
delay(5);
Write_cmd(0x30); //8位數(shù)據(jù)接口,1行顯示。5*7點(diǎn)陣,選擇基本指令集
delay(5);
Write_cmd(0x0f); //開(kāi)顯示(光標(biāo)顯示。閃爍)
delay(5);

Write_cmd(0x01); //清除顯示,并且設(shè)定地址指針為00H
delay(5);
Write_cmd(0x06); //指定在資料的讀取及寫(xiě)入時(shí),設(shè)定游標(biāo)的移動(dòng)方向及指定顯示的移位
delay(5);
}

void SetLine(uchar line) //line -> 0 : 7
{
line = line & 0x07;
line = line | 0xb8; //1011 1xxx
Write_cmd(line);
}


void SetColum(uchar colum) //colum -> 0 :63
{
colum = colum & 0x3f;
colum = colum | 0x40; //01xx xxxx
Write_cmd(colum);
}

void SelectScreen(uchar screen)//0全屏,1左平,2右屏
{
switch(screen)
{
case 0:
CS1_L();CS2_L();
break;
case 1:
CS1_L();CS2_H();
break;
case 2:
CS1_H();CS2_L();
break;
}
}

//PAGE -> 0 : 7
//colum -> 0 :63
void display_HZ( uchar page,uchar col,uchar *temp) //顯示漢字子程序
{
uchar j;
SelectScreen(1); //從左半屏開(kāi)始 若列數(shù)超過(guò)128 改右
if(col>=64)
{
SelectScreen(2);
col-=0x40;
}
SetLine(page); //按要求寫(xiě)入頁(yè)地址
SetColum(col); //按要求從相應(yīng)列開(kāi)始寫(xiě)數(shù)據(jù)
for(j=0;j<16;j++) //寫(xiě)入一個(gè)漢字的上半部分,共16字節(jié)
{
Write_data(temp[j]);
delay(1);
}
SetLine(page+1); //從下一頁(yè)開(kāi)始顯示漢字的下半部分要求從相應(yīng)的列開(kāi)始寫(xiě)數(shù)據(jù)
SetColum(col);
for(j=16;j<32;j++)
{
Write_data(temp[j]);
delay(1);
}
}
void display_ZM( uchar page,uchar col,uchar *temp) //顯示字母子程序
{
uchar j;
SelectScreen(1); //從左半屏開(kāi)始 若列數(shù)超過(guò)128 改右

if(col>=64)
{
SelectScreen(2);
col-=64;
}

SetLine(page); //按要求寫(xiě)入頁(yè)地址
SetColum(col); //按要求從相應(yīng)列開(kāi)始寫(xiě)數(shù)據(jù)
for(j=0;j<8;j++) //寫(xiě)入一個(gè)漢字的上半部分,共16字節(jié)
{
Write_data(temp[j]);
delay(1);
}
SetLine(page+1); //從下一頁(yè)開(kāi)始顯示漢字的下半部分要求從相應(yīng)的列開(kāi)始寫(xiě)數(shù)據(jù)
SetColum(col);
for(j=8;j<16;j++)
{
Write_data(temp[j]);
delay(1);
}
}
void main()
{
uchar i,j;
init_12864();
for(i=0;i<8;i++)
display_HZ(0,16*i,HZ[i]);

for(i=0;i<34;i++)
{
if(i>=32)
{
display_ZM(6,8*i-256,ZM[i]);
continue;
}
if(i>=16)
{
display_ZM(4,8*i-128,ZM[i]);
continue;
}
display_ZM(2,8*i,ZM[i]);

}

字模軟件

avr單片機(jī)



關(guān)鍵詞: AMPIRE12864液晶AV

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉