小弟刚开始学习240128,在网上找到一个通用程序,但是有些不明白的地方,
void CGRAM(void)
{
unsigned int m=0;
double_byte_parameter(0x07,0x00,0x22); //设定最高的1K 为CGRAM
double_byte_parameter(0x00,0x3c,0x24); //
no_parameter(0xb0);
for(m=0;m<992;m++)
{
check_sta3();
wdata(CGTAB[m]);
}
check_sta3();
wcom(0xb2);
}
上面是一个子程序,其中{double_byte_parameter(0x07,0x00,0x22); //设定最高的1K 为CGRAM}什么意思啊 ?CGRAM不是很明白,这是设置它的大小吗?
15、驱动程序
/******************************************************************/
//6963c 通用程序
//8X8 象素
//RAM 空间:32K,地址:0-7FFF;
//取模方式:横向取模
//对不同得屏,修改下面的参数
//unsigned int size_lie=128 ; //LCD 象素点的列数目,例如240128 的屏是240
//unsigned int size_hang=64 ; //LCD 象素点的行数目,例如240128 的屏是128
//然后将unsigned char code sch[]={}里的数据改为新的图片数据,默认的是12864 的
/******************************************************************/
#include <reg52.h>
#include <intrins.h>
/******************************************************************/
sbit ce=P1^0; /* chip enable */
sbit d_i=P1^3; /* command or data select,H:command L:data*/
sbit r_d=P1^4; /* rd EQU P1.4 */
sbit w_r=P1^5; /* wr EQU P1.5 */
sbit rst=P1^6; /* RESET EQU P1.5 */
sbit sta0_bit=P2^0;
sbit sta1_bit=P2^1;
sbit sta3_bit=P2^3;
unsigned char *p;
unsigned char *q;
unsigned char *r;
unsigned char *s;
//以下的变量比较多,建议用结构体
unsigned int size_lie=128 ; //LCD 象素点的列数目,例如240128 的屏是240
unsigned int size_hang=64 ; //LCD 象素点的行数目,例如240128 的屏是128
unsigned int textsize; //LCD text 区域空间,
unsigned int graphicsize;//LCD graphic 区域空间
unsigned char textsize_h; //textsize 的高字节
unsigned char textsize_l; //低字节
unsigned char graphicsize_h;//graphic 的高字节
unsigned char graphicsize_l;//graphic 的低字节
unsigned int text_startaddr;//TEXT 区域的起始地址
unsigned char text_startaddr_h;//高字节,
unsigned char text_startaddr_l;//低字节
unsigned int graphic_startaddr;//graphic 区域的首地址
unsigned char graphic_startaddr_h;
unsigned char graphic_startaddr_l;
unsigned char *p;//指针变量
unsigned char *q;
unsigned char *r;
unsigned char *s;
unsigned char bdata flag;
#define nop() _nop_();
unsigned char code h8O[3]={0x18,0x28,0x79};
unsigned char code graphich8o[24]={
0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e,0x00,//字符的编码
0x11,0x11,0x11,0x1f,0x11,0x11,0x11,0x00,//字符的编码
0x0a,0x00,0x0e,0x11,0x11,0x11,0x0e,0x00//字符的编码
};
unsigned char code sch[1920]={};
unsigned char code tableindex[48]={//汉字的索引,此方法比较繁琐
0,0,0,0,0,0,0,1,2,0,0,0,//第一组,24 个 送别
0,3,4,5,6,7,0,8,6,9,10,11,//下马饮君酒 问君何所之
0,6,12,13,14,15,0,16,17,18,19,20,//君言不得志 归卧南山陲
0,21,22,23,24,25,0,26,27,28,29,30};//但去莫复闻 白云无尽时
//每个字符代码所占的空间=8 字节
//===============数组:"液晶"16*16===============
unsigned char code CGTAB[992]={// 共30 个汉字,每个32 字节,共占960 个字节,字体: 宋体
大小: -12
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,
/*送*/0x42,0x21,0x21,0x07,0x00,0x00,0xEF,0x20,0x21,0x21,0x22,0x24,0x20,0x50,0x8F,0x00,
0x20,0x20,0x40,0xF8,0x80,0x80,0xFC,0x80,0x40,0x20,0x10,0x10,0x00,0x00,0xFE,0x00,
/*别*/0x00,0x3F,0x21,0x21,0x21,0x3F,0x29,0x08,0x7F,0x09,0x11,0x11,0x21,0x27,0x42,0x80,
0x04,0x04,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x04,0x04,0x04,0x1C,0x08,
/*下*/0x00,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
0x04,0xFE,0x00,0x00,0x00,0xC0,0x60,0x30,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*马*/0x00,0x3F,0x00,0x08,0x08,0x08,0x08,0x0F,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,
0x00,0xE0,0x20,0x20,0x20,0x20,0x20,0xFC,0x04,0x04,0xF4,0x04,0x04,0x34,0x08,0x00,
/*饮*/0x20,0x20,0x20,0x3D,0x45,0x4A,0x94,0x10,0x10,0x10,0x10,0x11,0x15,0x1A,0x14,0x00,
0x80,0x80,0x80,0xFE,0x04,0x48,0x40,0x40,0x40,0xA0,0xA0,0x10,0x08,0x0E,0x04,0x00,
/*君*/0x00,0x3F,0x02,0x02,0xFF,0x04,0x04,0x3F,0x04,0x08,0x1F,0x18,0x28,0x48,0x8F,0x08,
0x00,0xF8,0x08,0x08,0xFE,0x08,0x08,0xF8,0x08,0x00,0xF8,0x08,0x08,0x08,0xF8,0x08,
/*酒*/0x40,0x2F,0x21,0x01,0x97,0x55,0x15,0x25,0x25,0x26,0xC4,0x47,0x44,0x47,0x44,0x00,
0x00,0xFE,0x20,0x20,0xFC,0x24,0x24,0x24,0x24,0x3C,0x04,0xFC,0x04,0xFC,0x04,0x00,
/*问*/0x10,0x0B,0x08,0x20,0x20,0x27,0x24,0x24,0x24,0x27,0x20,0x20,0x20,0x20,0x20,0x20,
0x00,0xFC,0x04,0x04,0x04,0xE4,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x04,0x14,0x08,
/*何*/0x08,0x0C,0x1B,0x10,0x30,0x27,0x64,0xA4,0x24,0x27,0x24,0x20,0x20,0x20,0x20,0x00,
0x00,0x00,0xFE,0x08,0x08,0xC8,0x48,0x48,0x48,0xC8,0x48,0x08,0x08,0x28,0x10,0x00,
/*所*/0x0E,0x70,0x40,0x40,0x7C,0x44,0x44,0x44,0x7C,0x40,0x41,0x41,0x42,0x42,0x84,0x08,
0x1E,0xE0,0x80,0x80,0x80,0xFE,0x88,0x88,0x88,0x88,0x08,0x08,0x08,0x08,0x08,0x08,
/*之*/0x02,0x01,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x18,0x28,0xE7,0x40,0x00,
0x00,0x00,0x88,0xFC,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,
/*言*/0x02,0x01,0x7F,0x00,0x00,0x1F,0x00,0x1F,0x00,0x00,0x1F,0x10,0x10,0x10,0x1F,0x10,
0x00,0x00,0xFE,0x00,0x00,0xF0,0x00,0xF0,0x00,0x00,0xF0,0x10,0x10,0x10,0xF0,0x10,
/*不*/0x00,0x7F,0x01,0x01,0x01,0x01,0x03,0x05,0x09,0x11,0x21,0x41,0x01,0x01,0x01,0x00,
0x04,0xFE,0x80,0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,
/*得*/0x13,0x1A,0x23,0x4A,0x8B,0x10,0x13,0x30,0x50,0x97,0x10,0x11,0x11,0x11,0x10,0x10,
0xF8,0x08,0xF8,0x08,0xF8,0x00,0xFE,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0x50,0x20,
/*意*/0x01,0x3F,0x08,0x04,0xFF,0x00,0x1F,0x12,0x11,0x1F,0x00,0x29,0x28,0x68,0x07,0x00,
0x00,0xFC,0x20,0x40,0xFE,0x00,0xF0,0x10,0x10,0xF0,0x00,0x08,0x84,0x14,0xF0,0x00,
/*归*/0x08,0x08,0x0B,0x48,0x48,0x48,0x48,0x49,0x48,0x48,0x48,0x08,0x10,0x13,0x20,0x40,
0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,
/*卧*/0x00,0x7F,0x48,0x48,0x48,0x7F,0x41,0x41,0x7F,0x48,0x48,0x48,0x48,0x7F,0x00,0x00,
0x40,0x40,0x40,0x40,0x40,0x60,0x50,0x4C,0x46,0x42,0x40,0x40,0x40,0x40,0x40,0x00,
/*南*/0x01,0x01,0xFF,0x01,0x02,0x3F,0x24,0x22,0x2F,0x21,0x3F,0x21,0x21,0x21,0x21,0x00,
0x00,0x04,0xFE,0x00,0x00,0xFC,0x24,0x44,0xF4,0x04,0xFC,0x04,0x04,0x14,0x08,0x00,
/*山*/0x01,0x01,0x01,0x01,0x01,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x7F,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x04,0x00,
/*陲*/0x78,0x4B,0x50,0x57,0x61,0x51,0x49,0x4F,0x49,0x69,0x51,0x47,0x40,0x40,0x43,0x40,
0x3C,0xC0,0x40,0xFE,0x50,0x50,0x50,0xFE,0x50,0x50,0x50,0xFE,0x40,0x40,0xFC,0x00,
/*但*/0x10,0x1B,0x12,0x22,0x22,0x73,0xA2,0x22,0x22,0x23,0x22,0x22,0x20,0x2F,0x20,0x00,
0x00,0xF8,0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0xF8,0x08,0x00,0x00,0xFE,0x00,0x00,
/*去*/0x01,0x01,0x01,0x3F,0x01,0x01,0x01,0x01,0x7F,0x02,0x06,0x08,0x10,0x3F,0x10,0x00,
0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x20,0x10,0xF8,0x10,0x00,
/*莫*/0x04,0x04,0x7F,0x04,0x1F,0x10,0x1F,0x10,0x1F,0x01,0xFF,0x02,0x04,0x08,0x10,0x60,
0x20,0x20,0xFE,0x20,0xF0,0x10,0xF0,0x10,0xF0,0x00,0xFE,0x80,0x40,0x20,0x1C,0x08,
/*复*/0x08,0x0F,0x10,0x2F,0x48,0x0F,0x08,0x0F,0x04,0x07,0x0C,0x12,0x21,0x06,0x18,0x60,
0x00,0xFC,0x00,0xF8,0x08,0xF8,0x08,0xF8,0x00,0xF8,0x10,0x60,0x80,0x60,0x1E,0x04,
/*闻*/0x10,0x0B,0x40,0x40,0x5F,0x44,0x47,0x44,0x47,0x44,0x44,0x5F,0x40,0x40,0x40,0x40,
0x00,0xFC,0x04,0x04,0xF4,0x44,0xC4,0x44,0xC4,0x44,0xF4,0x44,0x44,0x44,0x54,0x08,
/*白*/0x02,0x02,0x04,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x00,
0x00,0x00,0x00,0xF8,0x08,0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x08,0xF8,0x08,0x00,
/*云*/0x00,0x00,0x3F,0x00,0x00,0x00,0xFF,0x03,0x07,0x06,0x0C,0x18,0x31,0x7F,0x20,0x00,
0x00,0x30,0xF8,0x00,0x00,0x0C,0xFE,0x00,0x00,0x40,0x20,0x10,0xF8,0x0C,0x08,0x00,
/*无*/0x00,0x3F,0x01,0x01,0x01,0x01,0x7F,0x01,0x02,0x02,0x04,0x08,0x10,0x20,0xC0,0x00,
0x00,0xFC,0x00,0x00,0x00,0x00,0xFE,0x80,0x80,0x80,0x80,0x80,0x82,0x82,0x7E,0x00,
/*尽*/0x00,0x1F,0x10,0x10,0x1F,0x10,0x10,0x10,0x26,0x21,0x40,0x84,0x03,0x01,0x00,0x00,
0x00,0xF8,0x08,0x08,0xF8,0x80,0x80,0x40,0x20,0x98,0x8E,0x04,0x00,0x80,0x80,0x00,
/*时*/0x00,0x00,0x7C,0x44,0x47,0x44,0x7C,0x45,0x44,0x44,0x7C,0x00,0x00,0x00,0x00,0x00,
0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x90,0x90,0x10,0x10,0x10,0x10,0x50,0x20,
};
/*************************************************/
//Write Data
/*************************************************/
void wdata(unsigned char com) //PR14
{
ce=0;//片选
d_i=0;//数据
r_d=1;
w_r=0;//写数据
nop();
P2=com;//送出数据
nop();
w_r=1;
}
/*************************************************/
//写命令
/*************************************************/
void wcom(unsigned char dat) //wdata
{
ce=0;
d_i=1;//命令
r_d=1;
w_r=0;//写
nop();
P2=dat;
nop();
w_r=1;
}
/*************************************************/
//查状态0 和1 位
/*************************************************/
void check_sta01(void)
{
unsigned char temp;
w_r=1;
d_i=1;
ce=0;
while(1)
{
P2=0XFF;
r_d=0;
nop();
temp=P2;
nop();
r_d=1;
if((temp&0x03)==0x03)//STA0 AND STA1
return;
}
}
/*************************************************/
// check_sta3
/*************************************************/
void check_sta3(void)
{
unsigned char temp;
w_r=1;
d_i=1;//命令
ce=0;
while(1)
{
P2=0XFF;
r_d=0;
temp=P2;
nop();
r_d=1;
if((temp&0x08)==0x08)
return;
}
}
/*************************************************/
//双字节命令
/*************************************************/
void double_byte_parameter(unsigned char coma,unsigned char comb,unsigned char data_b)
{
check_sta01();
wdata(coma);
check_sta01();
wdata(comb);
check_sta01();
wcom(data_b);
}
/*************************************************/
//无参数命令
/*************************************************/
void no_parameter(unsigned char com)
{
check_sta01();
wcom(com);
}
/*************************************************/
//清屏或全显
//state=0,TEXT 区,vlaue=0,清屏,value=0xff,全显
/*************************************************/
void all_display(unsigned char state,unsigned char vlue)
{
unsigned int i;
if(state==0)
{
double_byte_parameter(text_startaddr_l,text_startaddr_h,0x24);
no_parameter(0xb0);
for(i=textsize;i>0;i--)
{
check_sta3();
wdata(vlue);
}
check_sta3();
wcom(0xb2);
}
else
{
double_byte_parameter(graphic_startaddr_l,graphic_startaddr_h,0x24);
no_parameter(0xb0);
for(i=graphicsize;i>0;i--)
{
check_sta3();
wdata(vlue);
}
check_sta3();
wcom(0xb2);
}
}
/*************************************************/
//TEXT 模式下,写8X8 字符
//hang:1-size_hang/8
//lie:1-size_lie/8
/*************************************************/
void display_ascii(unsigned char *addr,unsigned char hang,unsigned char lie)
{
unsigned int temp;//
unsigned char low;
unsigned char high;
temp=(size_lie/8)*(hang-1)+(lie-1);
//TEXT 模式下,TEXT 区域被分为size_hang/8 行、size_lie/8 列个8X8 点阵
//行地址为0-(size_hang/8-1),列地址 0 - (size_lie/8-1)
//注意,本程序的hang 和 lie 都是从1 开始的
low=temp&0x00ff;
high=(temp>>8)&0x00ff;
double_byte_parameter(low,high,0x24);
no_parameter(0xb0);//
check_sta3();
wdata(*addr);//addr:CGRAM OR CGROM 中字符的地址
深圳市显晶科技有限公司
SHENZHEN HAN-GTECHNOLOGY CO.,LTD
check_sta3();
wcom(0xb2);//
}
/*************************************************/
//显示一副图片
//graphic 模式下,共size_hang 行,size_lie/8 列
/*************************************************/
void display_map(unsigned char *p)
{
unsigned char m,n;
double_byte_parameter(graphic_startaddr_l,graphic_startaddr_h,0x24);
no_parameter(0xb0);
for(m=size_hang;m>0;m--)//共size_hang 行
{
for(n=(size_lie/8);n>0;n--)//size_lie/8 列
{
check_sta3();
wdata(*p++);
}
}
check_sta3();
wcom(0xb2);
}
void display8hotext(void)//TEXT 模式下写调用CGROM 中字符
{
unsigned int hang;//
unsigned int lie;//
for(hang=1;hang<=((size_hang*3/8)/8);hang++)//3/8 屏字符8
{
for(lie=1;lie<=(size_lie/8);lie++)
display_ascii( &h8O,hang, lie );
}
for(hang=(((size_hang*3/8)/8)+1);hang<=(((size_hang*3/8)/8)+2);hang++)//2/8 屏H
{
for(lie=1;lie<=(size_lie/8);lie++)
display_ascii( &h8O+1,hang, lie );
}
for(hang=(((size_hang*3/8)/8)+3);hang<=(((size_hang*3/8)/8)+5);hang++)//3/8 屏 O
{
for(lie=1;lie<=(size_lie/8);lie++)
display_ascii( &h8O+2,hang, lie );
}
深圳市显晶科技有限公司
SHENZHEN HAN-GTECHNOLOGY CO.,LTD
}
//显示汉字
//hang 1-size_hang/16, lie 1-size_lie/16
//addr CGRAM 中字符的地址
//四个8X8 字符组成一个16X16 的汉字字符
void displayHZ_at_xyaddr(unsigned char addr,unsigned char hang,unsigned char lie)
{
unsigned int temp;
unsigned char low;
unsigned char high;
temp=(size_lie/8)*2*(hang-1)+2*(lie-1);
//TEXT 模式下,TEXT 区域被分为size_hang/8 行、size_lie/8 列个8X8 点阵
//行地址为0-(size_hang/8-1),列地址 0 - (size_lie/8-1)
//注意,本程序的hang 和 lie 都是从1 开始的,并且是16X16 的
low=temp&0x00ff;
high=(temp>>8)&0x00ff;
double_byte_parameter(low,high,0x24);
no_parameter(0xb0);
check_sta3();
wdata(addr);//左上
check_sta3();
wdata(addr+2);//右上
check_sta3();
wcom(0xb2);
temp=(size_lie/8)*2*(hang-1)+(size_lie/8)+2*(lie-1);// 下半部分比上半部分的地址多
(size_lie/8)
low=temp&0x00ff;
high=(temp>>8)&0x00ff;
double_byte_parameter(low,high,0x24);
no_parameter(0xb0);
check_sta3();
wdata(addr+1);
check_sta3();
wdata(addr+3);
check_sta3();
wcom(0xb2);
}
/*************************************************/
void displayHZ()
{
unsigned char j;
for(j=1;j<=6;j++)
{
displayHZ_at_xyaddr(0X80+tableindex[j-1+24]*4,2,j);
displayHZ_at_xyaddr(0X80+tableindex[j-1+24+6]*4,3,j);
}
}
//graphic 格式下显示8HO 字符
void display_8HO(unsigned char *q)//显示字符,三种字符的数量按照3:2:3 的比例显示,
{
unsigned int count_byte,count_row,count_page,page;
for(count_row=7;count_row>3;count_row--)//共七种字符形式
{
double_byte_parameter(graphic_startaddr_l,graphic_startaddr_h,0x24);// 从
GRAPHIC 的首地址开始写
no_parameter(0xb0);//自动写
for(page=1;page<=((size_hang*3/8)/8);page++)// 3/8 屏
{
s=q;
for(count_byte=8;count_byte>0;count_byte--)//共8 行,组成一个8 X 8 字符
{
for(count_page=(size_lie/8);count_page>0;count_page--)//写一行,共(size_lie/8)
列
{
check_sta3();
wdata(*s);
}
s++;
}
}
for(page=1;page<=((size_hang*2/8)/8);page++)// 2/8
{
s=q;
s=s+8;
for(count_byte=8;count_byte>0;count_byte--)//每页8 行,8 X 8 点阵
{
for(count_page=(size_lie/8);count_page>0;count_page--)//30X8 列
{
check_sta3();
wdata(*s);
}
s++;
}
}
for(page=1;page<=((size_hang*3/8)/8);page++)// 3/8
{
s=q;
s=s+16;
for(count_byte=8;count_byte>0;count_byte--)//每页8 行,8 X 8 点阵
{
for(count_page=(size_lie/8);count_page>0;count_page--)//30X8
列
{
check_sta3();
wdata(*s);
}
s++;
}
}
check_sta3();
wcom(0xb2);//退出自动写
}
}
void CGRAM(void)
{
unsigned int m=0;
double_byte_parameter(0x07,0x00,0x22); //设定最高的1K 为CGRAM
double_byte_parameter(0x00,0x3c,0x24); //
no_parameter(0xb0);
for(m=0;m<992;m++)
{
check_sta3();
wdata(CGTAB[m]);
}
check_sta3();
wcom(0xb2);
}
void delay1s(void)
{
unsigned int i;
unsigned int j;
for(i=0;i<1000;i++)
{
for(j=0;j<100;j++)
{j=j;}
}
}
/*************************************************/
void main(void)
{
rst=0;
nop();
nop();
nop();
rst=1;
textsize=graphicsize=size_lie/8*size_hang;//
textsize_l=textsize;//
textsize_h=textsize>>8;//
graphicsize_h=graphicsize>>8;
graphicsize_l=graphicsize;
text_startaddr=0x0000;
text_startaddr_h=text_startaddr>>8;//
text_startaddr_l=text_startaddr;
graphic_startaddr=text_startaddr+textsize;//
graphic_startaddr_h=graphic_startaddr>>8;//
graphic_startaddr_l=graphic_startaddr;
double_byte_parameter(text_startaddr_l,text_startaddr_h,0x40);//TEXT
double_byte_parameter((size_lie/8),0x00,0x41);
double_byte_parameter(graphic_startaddr_l,graphic_startaddr_h,0x42);
double_byte_parameter((size_lie/8),0x00,0x43);
no_parameter(0x80);//TEXT OR GRAPHIC
no_parameter(0xa3);//
CGRAM();
while(1)
{
all_display(1,0x00);
no_parameter(0x98);//TEXT OFF ,GRAPHIC ON
display_map(&sch);
delay1s();
display_8HO(&graphich8o);
delay1s();
no_parameter(0x94); //TEXT ON,GRAPHIC OFF
all_display(0,0x00);
displayHZ();
delay1s();
all_display(0,0x00);
display8hotext();
delay1s();
}
}
深圳市显晶科技有限公司 |