今天终于完成了12864带字库液晶模块的图象和中英文字母显示,图象显示显示了自己的一副照片,呵呵,还认得出是自己,开心啊。。。硬件连接方式是:并口直接访问。
这是汉字显示程序:
#include<reg51.h>
#include<absacc.h>
#define uchar unsigned char
#define datawr 0x1200 //写数据通道
#define comwr 0x1000 //写控制命令通道
#define datare 0x1300 //读数据通道
#define comre 0x1100 //读忙通道
uchar code disp_data[]={" 浙江大学 " //第一行,第一页
"04级通信工程一班" //第三行
" 宁波理工学院 " //第二行
" 竞赛小组 " //第四行
"128X64液晶显示器" //第一行,第二页
" 测试程序 " //第三行
" 07年07月25日 " //第二行
" Tornado "}; //第四行
void set12864();
void write_command(uchar command);
void write_page(uchar data_add);
void read_page(uchar data_add);
void delays(uchar cont);
void main()
{
while(1)
{
set12864(); //初始化12864
write_page(0); //写入一页数据
read_page(0x30); //读出一页数据到内部RAM
delays(2); //延时2s
write_page(64); //写入下一页数据
delays(2); //延时2s
}
}
//初始化12864子程序
void set12864()
{
write_command(0x30); //功能设定控制字
write_command(0x0c); //显示开关控制字
write_command(0x01); //清除屏幕控制字
write_command(0x06); //进入设定点控制字
}
//写控制命令子程序
void write_command(uchar command)
{
bit flag="1"; //12864空闲标志位
while(flag) //检查12864是否空闲
flag="XBYTE"[comre]&0x80;
XBYTE[comwr]=command; //空闲传送控制字
}
//写一页子程序
void write_page(uchar data_add)
{
bit flag="1"; //12864空闲标志位
uchar num="64"; //64个循环,连续写入32个汉字或是64个西文字符
write_command(0x80);
for(;num>0;num--)
{
while(flag) //检查12864是否空闲
flag="XBYTE"[comre]&0x80;
XBYTE[datawr]=disp_data[data_add++]; //空闲传送数据
}
}
//读一页子程序
void read_page(uchar data_add)
{
bit flag="1"; //12864空闲标志位
uchar num="64"; //64个循环,连续写入32个汉字或是64个西文字符
write_command(0x80);
for(;num>0;num--)
{
while(flag) //检查12864是否空闲
flag="XBYTE"[comre]&0x80;
DBYTE[data_add++]=XBYTE[datare]; //空闲传送数据
}
}
//延时cont秒子程序
void delays(uchar count)
{
unsigned char h,i,j,k;
do
{
for(h=5;h>0;h--)
for(i=4;i>0;i--)
for(j=116;j>0;j--)
for(k=214;k>0;k--);
}while(--count);
}
这是图象显示程序:
#include<reg51.h>
#include<absacc.h>
#define uchar unsigned char
#define uint unsigned int
#define datawr 0x1200 //写数据通道
#define comwr 0x1000 //写控制命令通道
#define datare 0x1300 //读数据通道
#define comre 0x1100 //读忙通道
uchar code disp_data[] = // 数据表
{
0x00,0x01,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,
0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,
0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,
0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,
0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,
0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x80,0x00,0x00,0x00,
0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF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0x00,0x38,0x0F,0xFF,0xFE,
0xFF,0xFF,0xD0,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x03,0xFF,0xF8,
0xFF,0xFC,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xC0,
0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0xFF,0xF8,
0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x1F,0xFE,
0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x78,0x02,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x03,0xF0,0x78,0x00,0x00,0x00,0x00,0x00,0x02,0xFF,
0xFE,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,
0xF0,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,
0xE0,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x27,
0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,
0x80,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
};
void set12864();
void setxy(uchar x,uchar y);
void write_command(uchar command);
void write_16byte(uint data_add);
void delays(uchar count);
void main()
{
uchar x,y,i;
while(1)
{
y="0x80"; //设置液晶上半部分坐标
x="0x80";
delays(2); //延时2s
set12864(); //初始化12864
delays(2);
for(i=0;i<32;i++) //写入液晶上半图象部分
{ //写入坐标
setxy(x,y);
write_16byte(i*16); //连续写入16字节数据
y++; //y轴地址加1
}
y="0x80"; //设置液晶下半部分坐标
x="0x88";
for(i=0;i<32;i++) //写入液晶下半图象部分
{
setxy(x,y); //写入坐标
write_16byte((32+i)*16);//连续写入16字节数据
y++; //y轴地址加1
}
write_command(0x34); //写入扩充指令命令
write_command(0x36); //显示图象
}
}
//初始化12864子程序
void set12864()
{
write_command(0x30); //功能设定控制字
write_command(0x0c); //显示开关控制字
write_command(0x01); //清除屏幕控制字
write_command(0x06); //进入设定点控制字
}
//设置绘图坐标
void setxy(uchar x,uchar y)
{
write_command(0x34); //写入扩充指令命令
write_command(y); //写入y轴坐标
write_command(x); //写入x轴坐标
write_command(0x30); //写入基本指令命令
}
//写控制命令子程序
void write_command(uchar command)
{
bit flag="1"; //12864空闲标志位
while(flag) //检查12864是否空闲
flag="XBYTE"[comre]&0x80;
XBYTE[comwr]=command; //空闲传送控制字
}
void write_16byte(uint data_add)
{
bit flag="1"; //12864空闲标志位
uchar num="16"; //16个循环,连续写入16个字节
for(;num>0;num--)
{
while(flag) //检查12864是否空闲
flag="XBYTE"[comre]&0x80;
XBYTE[datawr]=disp_data[data_add++]; //空闲传送数据
}
}
//延时count秒子程序
void delays(uchar count)
{
unsigned char h,i,j,k;
do
{
for(h=5;h>0;h--)
for(i=4;i>0;i--)
for(j=116;j>0;j--)
for(k=214;k>0;k--);
}while(--count);
}
用户227870 2011-7-27 09:48
用户227870 2011-7-27 09:39
用户227870 2011-7-27 09:35
用户1657917 2008-4-13 13:45
用户1657917 2008-4-6 11:47
用户9671 2008-3-7 21:08
用户1657917 2007-8-13 19:03
用户1657917 2007-8-11 14:35
这几个是12864的控制命令,就是控制RS、R/W的。最高的半字节因为我的电路P2.4连接一个控制信号是高电平才有效,所以为1。接下来的半字节是P2.1接RS,P2.0接R/W,所以就有0、1、2、3了作用就是注释说的。低字节是P0口接12864的数据口,是用来读写数据的,所以为0、1都无所谓。
简单说就是设置好RS、R/W,其他位都为X就可以了。
用户18333 2007-8-10 14:55
#define datawr 0x1200 //写数据通道
#define comwr 0x1000 //写控制命令通道
#define datare 0x1300 //读数据通道
#define comre 0x1100 //读忙通道
这几句话,究竟怎么分配的啊可以把12864的20个脚和51单片机的I/O说清楚吗
用户1657917 2007-7-26 11:35