您的位置 首页 5G

AMPIRE12864液晶C言语代码

#includeiom16v.h>#includemacros.h>#defineucharunsignedchar#defineuintunsignedint#defineRS_H()P

#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},/*”爱”,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位数据接口,1行显现。5*7点阵,挑选根本指令集
delay(5);
Write_cmd(0x0f); //开显现(光标显现。闪耀)
delay(5);

Write_cmd(0x01); //铲除显现,而且设定地址指针为00H
delay(5);
Write_cmd(0x06); //指定在材料的读取及写入时,设定游标的移动方向及指定显现的移位
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); //从左半屏开端 若列数超越128 改右
if(col>=64)
{
SelectScreen(2);
col-=0x40;
}
SetLine(page); //按要求写入页地址
SetColum(col); //按要求从相应列开端写数据
for(j=0;j<16;j++) //写入一个汉字的上半部分,共16字节
{
Write_data(temp[j]);
delay(1);
}
SetLine(page+1); //从下一页开端显现汉字的下半部分要求从相应的列开端写数据
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); //从左半屏开端 若列数超越128 改右

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

SetLine(page); //按要求写入页地址
SetColum(col); //按要求从相应列开端写数据
for(j=0;j<8;j++) //写入一个汉字的上半部分,共16字节
{
Write_data(temp[j]);
delay(1);
}
SetLine(page+1); //从下一页开端显现汉字的下半部分要求从相应的列开端写数据
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单片机

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/5g/268281.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部