12864中文字库C语言

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。


#include
#include

#define LcmXPixel 128 //横像素
#define LcmYPixel 64 //纵像素

//#define BUS_MODE //总线模式
#define IO_MODE //IO模式

//总线模式程序接口
#ifdef BUS_MODE
char xdata LcmWCmdPort _at_ 0x0000; //写命令
char xdata LcmWDatPort _at_ 0x0100; //写数据
char xdata LcmRStaPort _at_ 0x0200; //读状态
char xdata LcmRDatPort _at_ 0x0300; //读数据
#endif

void int_zhongduan();
void delay(unsigned int t);
//IO模式程序接口
#ifdef IO_MODE
sbit RSP = P2^0; //RSP表示RS Port,P=Port,下同
sbit RWP = P2^1;
sbit EP = P2^2; //E信号在本程序中是通过单片机的WR和RD与非出来的,是为了不改动总线模式的连线方式
sbit RES =P2^3;
#define LcmDataBus P0 //用户可以不用这样操作,直接用一个IO口来操作,替换本程序中_E1_()和_E0_()两个函数
#endif

sbit Key=P3^2;
sbit P33=P3^3;
sbit p0_dr=P3^4; //坚鸿测试架增加指令,控制P0口的输入输出。(用户不用理会这里)
unsigned char code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
};
unsigned char code str1[]="黄河远上白云间,一片孤城万仞山。羌笛何须怨杨柳,春风不度玉门关。";
unsigned char code str2[]="简体字 or "; //简体字or
unsigned char code str3[]={0xC1,0x63,0xC5,0xE9,0xA6,0x72,0};//繁體字
unsigned char code bmp1[];

//IO模式下,在不改变总线模式连线方式情况下,E只能通过操作WR与RD来实现
#ifdef IO_MODE
void _E1_(void)
{
EP=1;
}

void _E0_(void)
{
EP=0;
}
#endif

void CheckBusy( void )
{
#ifdef BUS_MODE
while(LcmRStaPort&0x80);
#endif

#ifdef IO_MODE
p0_dr=1;//坚鸿测试架增加指令,控制P0口输入输出
RSP = 0;
RWP = 1;
LcmDataBus = 0xFF; //输出0xff以便读取正确
// EP = 1;
_E1_(); //相当于EP=1
_nop_();
while(LcmDataBus & 0x80); //Status Read Bit7 = BUSY
// EP = 0;
_E0_(); //相当于EP=0
_nop_();
p0_dr=0;//坚鸿测试架增加指令,控制P0口输入输出
#endif
}

void WriteCommand( unsigned char Cbyte )
{
CheckBusy();
#ifdef BUS_MODE
LcmWCmdPort = Cbyte;
#endif

#ifdef IO_MODE
RSP = 0;
RWP = 0;
LcmDataBus = Cbyte;
// EP = 1;
_E1_(); //相当于EP=1
_nop_();
// EP = 0;
_E0_(); //相当于EP=0
_nop_();
#endif
}

void WriteData( unsigned char Dbyte )
{
CheckBusy();
#ifdef BUS_MODE
LcmWDatPort = Dbyte;
#endif

#ifdef IO_MODE
RSP = 1;
RWP = 0;
LcmDataBus = Dbyte;
// EP = 1;
_E1_(); //相当于EP=1
_nop_();
// EP = 0;
_E0_(); //相当于EP=0
_nop_();
#endif
}

unsigned char ReadData( void )
{
unsigned char RData;
CheckBusy();
#ifdef BUS_MODE
RData = LcmRDatPort;
#endif

#ifdef IO_MODE
p0_dr=1;//坚鸿测试架增加指令,控制P0口输入

输出
RSP = 1;
RWP = 1;
LcmDataBus = 0xFF; //输出0xff以便读取正确
// EP = 1;
_E1_(); //相当于EP=1
_nop_();
RData = LcmDataBus;
// EP = 0;
_E0_(); //相当于EP=0
_nop_();
p0_dr=0;//坚鸿测试架增加指令,控制P0口输入输出
#endif
return RData;
}

void DelayMS(unsigned int MS)
{
unsigned char us,usn;
while(MS!=0)
{
usn = 2; //for 12M
while(usn!=0)
{
us=0xf6;
while (us!=0){us--;};
usn--;
}
MS--;
}
}

void DelayKey(unsigned int Second , unsigned int MS100)
{
unsigned int i;
for(i=0;i{
if(Key==0)
{
DelayMS(20);
while(Key==0) {DelayMS(20);}
break;
}
else DelayMS(10);
}
}

void LcmInit( void )
{
RES=0;
DelayMS(10);
RES=1;
DelayMS(30);
WriteCommand(0x30); //8BitMCU,基本指令集合
WriteCommand(0x03); //AC归0,不改变DDRAM内容
WriteCommand(0x0C); //显示ON,游标OFF,游标位反白OFF
WriteCommand(0x01); //清屏,AC归0
WriteCommand(0x06); //写入时,游标右移动
}

void LcmClearTXT( unsigned char FillByte )
{
unsigned char i;
WriteCommand(0x30); //8BitMCU,基本指令集合
WriteCommand(0x80); //AC归起始位
for(i=0;i<64;i++)
WriteData(FillByte);
}

void LcmClearBMP( unsigned char FillByte )
{
unsigned char i,j;
WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
for(i=0;i<32;i++) //12864实际为256x32
{
WriteCommand(0x80|i);
WriteCommand(0x80);
for(j=0;j<32;j++)
WriteData(FillByte);
}
}


void PutStr(unsigned char row,unsigned char col,unsigned char *puts)
{
WriteCommand(0x30); //8BitMCU,基本指令集合
WriteCommand(AC_TABLE[8*row+col]); //起始位置
while(*puts != '\0')
{
if(col==8)
{
col=0;
row++;
}
if(row==4) row=0; //一屏显示完,回到屏左上角
WriteCommand(AC_TABLE[8*row+col]);
WriteData(*puts);
puts++;
WriteData(*puts);
puts++;
col++;
}
}

//文本区读取测试
//可以将显示的文本内容读取出来
void TXTReadDemo( void )
{
unsigned char i;
unsigned char x,y;
PutStr(0,0,str2);
PutStr(0,5,str3);
for(i=0;i<8;i++)
{
WriteCommand(0x80|i);
x = ReadData(); //假读一次
x = ReadData();
y = ReadData();
WriteCommand(0x90|i); //将读取的内容写到第三行
WriteData(x);
WriteData(y);
WriteCommand(0x88|i); //将读取的内容写到第二行
WriteData(x);
WriteData(y);
WriteCommand(0x98|i); //将读取的内容写到第四行
WriteData(x);
WriteData(y);
}
}

void PutBMP(unsigned char *puts)
{
unsigned int x=0;
unsigned char i,j;
WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
for(i=0;i<32;i++)
{
WriteCommand(0x80|i); //行位置
WriteCommand(0x80); //列位置
for(j=

0;j<32;j++)
{
WriteData(puts[x]);
x++;
}
}
}

//反向当前显示的图形内容,只能用于图形区
void RevBMP( void )
{
unsigned char x,y;
unsigned char i,j;
WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
for(i=0;i<32;i++)
{
for(j=0;j<16;j++)
{
WriteCommand(0x80|i); //行位置
WriteCommand(0x80|j); //列位置
x = ReadData(); //假读一次
x = ReadData();
y = ReadData();
WriteCommand(0x80|i); //重新设置回地址
WriteCommand(0x80|j);
WriteData(~x); //注意:绘图模式下显示数据必须一次写2byte
WriteData(~y);
}
}
}

void PutDots(unsigned char DotByte,unsigned char n)
{
unsigned char i,j,k;
WriteCommand(0x34); //8Bit扩充指令集,即使是36H也要写两次
WriteCommand(0x36); //绘图ON,基本指令集里面36H不能开绘图
for(i=0;i<(32/n);i++)
{
for(k=0;k{
WriteCommand(0x80|(i*n+k)); //行位置
WriteCommand(0x80); //列位置
for(j=0;j<32;j++)
{
WriteData(DotByte);
}
}
DotByte=~DotByte;
}
}

void main( void )
{
DelayMS(100); //等待复位
p0_dr=0;//坚鸿测试架增加指令,控制P0口输入输出
int_zhongduan();
LcmInit();
LcmClearTXT(0x20);
LcmClearBMP(0x00);
while(1)
{
LcmClearTXT(0x20);
PutBMP(bmp1);
DelayKey(1,5);

RevBMP();
DelayKey(1,5);

LcmClearBMP(0xFF);
DelayKey(1,5);

LcmClearBMP(0x00);
PutStr(0,0,str1);
DelayKey(1,5);

LcmClearTXT(0x20);
TXTReadDemo();
DelayKey(1,5);

LcmClearTXT(0x20);
PutDots(0x55,1);
DelayKey(1,5);

PutDots(0xAA,1);
DelayKey(1,5);

PutDots(0x33,2);
DelayKey(1,5);

PutDots(0xCC,2);
DelayKey(1,5);

PutDots(0x0F,4);
DelayKey(1,5);

PutDots(0xF0,4);
DelayKey(1,5);
}
}

unsigned char code bmp1[]={
//25632_2.bmp
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x80,0x00,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x3F,0xC0,0x00,0x07,0x07,0x00,0x04,0x01,0x00,0x00,0x38,0x60,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x78,0xE0,0x00,0x3F,0x83,0x80,0x06,0x03,0x80,0x00,0x1C,0x70,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x02,0x38,0x70,0x00,0xFF,0x07,0x80,0x06,0x39,0x80,0x00,0x1F,0x70,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x02,0x1C,0x30,0x00,0x7C,0x0E,0x00,0x06,0x19,0xC0,0x00,0x1F,0x80,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x02,0x1C,0x30,0x00,0x3E,0x1C,0x00,0x06,0x1F,0xC0,0x00,0x7F,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x

00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x03,0x3E,0x30,0x00,0x62,0x1A,0x00,0x0F,0x79,0x00,0x03,0xFE,0x00,0x00,0x01,
0x80,0x00,0x00,0x60,0x0F,0x00,0x3F,0x00,0x00,0x00,0x3C,0x00,0xC0,0x00,0x00,0x01,
0x80,0x07,0x76,0x18,0x00,0xC3,0xC1,0x00,0x1F,0xFB,0x00,0x03,0xFE,0x00,0x00,0x01,
0x80,0x00,0x01,0xE0,0x3F,0xC0,0xF1,0xC0,0x00,0x00,0xF0,0x01,0xC0,0x00,0x00,0x01,
0x80,0x07,0x6E,0x18,0x00,0xCF,0xC1,0x80,0x7E,0x3F,0x80,0x01,0xE2,0x00,0x00,0x01,
0x80,0x00,0x07,0xE0,0x7F,0xE0,0xE0,0xE0,0x00,0x03,0xC0,0x03,0xC0,0x00,0x00,0x01,
0x80,0x07,0x7F,0x98,0x00,0xFE,0x83,0x81,0xFC,0x1E,0xC0,0x00,0x83,0x00,0x00,0x01,
0x80,0x00,0x0F,0xE0,0x63,0xE1,0xE0,0xE0,0x00,0x07,0x00,0x03,0xC0,0x00,0x00,0x01,
0x80,0x06,0xFF,0xD8,0x01,0xFA,0x87,0x00,0xFD,0xF8,0xC0,0x01,0x73,0x00,0x00,0x01,
0x80,0x00,0x01,0xE0,0xC1,0xE1,0xE0,0xE0,0x00,0x0F,0x00,0x07,0xC0,0x00,0x00,0x01,
0x80,0x0F,0xD9,0xD8,0x03,0xE3,0x0E,0x80,0xFE,0x7E,0xC0,0x03,0xF9,0x80,0x00,0x01,
0x80,0x00,0x01,0xE0,0x01,0xE1,0xF0,0xE0,0x00,0x1E,0x00,0x0B,0xC0,0x00,0x00,0x01,
0x80,0x0D,0xB8,0x18,0x1F,0xC3,0x08,0xC0,0x0E,0x6D,0x80,0x03,0xF1,0x80,0x00,0x01,
0x80,0x00,0x01,0xE0,0x01,0xE0,0xFD,0xC7,0xEF,0x9E,0x00,0x13,0xC0,0x00,0x00,0x01,
0x80,0x0D,0xFE,0x18,0x0F,0xC2,0x10,0xE0,0x1C,0x3F,0x00,0x03,0xE0,0xC0,0x00,0x01,
0x80,0x00,0x01,0xE0,0x01,0xC0,0xFF,0x83,0xC6,0x1F,0xE0,0x13,0xC0,0x00,0x00,0x01,
0x80,0x0D,0xCE,0x18,0x06,0xC2,0x01,0xC0,0x38,0x3E,0x00,0x00,0xE8,0xC0,0x00,0x01,
0x80,0x00,0x01,0xE0,0x01,0x80,0x3F,0x81,0xE4,0x3C,0x78,0x23,0xC0,0x00,0x00,0x01,
0x80,0x0C,0x4C,0x18,0x00,0xC2,0x03,0x80,0x78,0x1F,0xF0,0x00,0xFC,0x60,0x00,0x01,
0x80,0x00,0x01,0xE0,0x03,0x80,0x3F,0xC1,0xE8,0x3C,0x78,0x43,0xC0,0x00,0x00,0x01,
0x80,0x0C,0x5E,0x18,0x00,0xC2,0x07,0x00,0x68,0x3F,0xF8,0x03,0xFC,0x22,0x00,0x01,
0x80,0x00,0x01,0xE0,0x03,0x00,0x6F,0xC0,0xF0,0x3C,0x3C,0x83,0xC0,0x00,0x00,0x01,
0x80,0x06,0x3F,0x38,0x01,0x82,0x0E,0x00,0x09,0xF8,0x00,0x03,0xC0,0x32,0x00,0x01,
0x80,0x00,0x01,0xE0,0x06,0x00,0xC3,0xE0,0x78,0x3C,0x3C,0xFF,0xF0,0x00,0x00,0x01,
0x80,0x07,0x10,0x38,0x00,0x82,0x1C,0x00,0x0B,0x99,0xC0,0x03,0x00,0x1A,0x00,0x01,
0x80,0x00,0x01,0xE0,0x0C,0x11,0xC3,0xE0,0x78,0x3C,0x3C,0xFF,0xF0,0x00,0x00,0x01,
0x80,0x03,0xFF,0xF0,0x00,0x02,0x38,0x00,0x08,0x30,0xE0,0x02,0x00,0x1E,0x00,0x01,
0x80,0x00,0x01,0xE0,0x08,0x11,0xC1,0xE0,0x7C,0x3C,0x3C,0xFF,0xF0,0x00,0x00,0x01,
0x80,0x01,0xEF,0xF0,0x00,0x00,0xE0,0x00,0x08,0xE0,0x60,0x00,0x00,0x0E,0x00,0x01,
0x80,0x00,0x01,0xE0,0x1F,0xF1,0xC1,0xE0,0xBC,0x1C,0x3C,0x03,0xC0,0x00,0x00,0x01,
0x80,0x00,0x03,0xE0,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x07,0x00,0x01,
0x80,0x00,0x01,0xE0,0x3F,0xE1,0xC1,0xC0,0x9E,0x1E,0x38,0x03,0xC0,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
0x80,0x00,0x01,0xF0,0x7F,0xE0,0xE3,0x83,0x1F,0x0E,0x70,0x03,0xC0,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x0F,0xFC,0xFF,0xE0,0x3F,0x07,0xDF,0x83,0xE0,0x03,0xC0,0x00,0x00,0x01,
0x80,0x00,0x0

0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x01,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};


void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;ifor(j=0;j<10;j++)
;
}

void Interrupt1 (void) interrupt 2
{
unsigned char p3_temp;
P33=1;
delay(10);

delay(10);

while(P33==0)
{
P33=1;
delay(10);

delay(10);

}



delay(10);

delay(10);

while(P33==1)
{
P33=1;
delay(10);

delay(10);

}


delay(10);

delay(10);

while(P33==0)
{
P33=1;

delay(10);

delay(10);



}
}


void int_zhongduan()
{


//外部中断1初始化
IT1 = 0;
EX1 = 1;
EA = 1;//打开中断
}


























相关文档
最新文档