#include <reg52.h>
#include <math.h>
#define lcd_data P1
sbit cs1=P2^3
sbit cs2=P2^4
sbit di=P2^0
sbit rw=P2^1
sbit e=P2^2
void delay(int t)
{
int i,j,k
for(i=0i<ti++)
{ for(j=0j<255j++)
k++}
}
void write_com_l(unsigned int command)
{
cs1=1
rw=0
di=0
lcd_data=command
e=1
e=0
cs1=0
}
void write_data_l(unsigned int data0)
{
cs1=1
rw=0
di=1
lcd_data=data0
e=1
e=0
cs1=0
}
void write_com_r(unsigned int command)
{
cs2=1
rw=0
di=0
lcd_data=command
e=1
e=0
cs2=0
}
void write_data_r(unsigned int data0)
{
cs2=1
rw=0
di=1
lcd_data=data0
e=1
e=0
cs2=0
}
void disp0()
{
unsigned int i,j
for (i=0i<8i++)
{write_com_l(0xb8+i)
write_com_r(0xb8+i)
write_com_l(0x40)
write_com_r(0x40)
for (j=0j<64j++)
{write_data_l(0xaa)
write_data_r(0xaa)
}
}
}
void disp1()
{
unsigned int i,j
for (i=0i<8i++)
{write_com_l(0xb8+i)
write_com_r(0xb8+i)
write_com_l(0x40)
write_com_r(0x40)
for (j=0j<64j++)
{write_data_l(0x55)
write_data_r(0x55)
}
}
}
void disp2()
{
unsigned int i,j
for (i=0i<8i++)
{write_com_l(0xb8+i)
write_com_r(0xb8+i)
write_com_l(0x40)
write_com_r(0x40)
for (j=0j<64j++)
{write_data_l(0x0f)
write_data_r(0x0f)
}
}
}
void disp3()
{
unsigned int i,j
for (i=0i<8i++)
{write_com_l(0xb8+i)
write_com_r(0xb8+i)
write_com_l(0x40)
write_com_r(0x40)
for (j=0j<64j++)
{write_data_l(0xf0)
write_data_r(0xf0)
}
}
}
void init_lcd() //初始化LCD清屏
{
write_com_l(0x3e)
write_com_r(0x3e)
write_com_l(0x3f)
write_com_r(0x3f)
write_com_l(0xc0)
write_com_r(0xc0)
write_com_l(0xb8)
write_com_r(0xb8)
write_com_l(0x40)
write_com_r(0x40)
for(1)
{
disp0()
delay(0x0ff)
disp1()
delay(0x0ff)
disp2()
delay(0x0ff)
disp3()
delay(0x0ff)
}
}
void main()
{
IE=0x81
init_lcd()
}
void innt0 () interrupt 0
{
do {}while(1)
}
#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>0num--)
{
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>0num--)
{
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=5h>0h--)
for(i=4i>0i--)
for(j=116j>0j--)
for(k=214k>0k--)
}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,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0xFF,0xFF,0x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,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=0i<32i++) //写入液晶上半图象部分
{ //写入坐标
setxy(x,y)
write_16byte(i*16)//连续写入16字节数据
y++ //y轴地址加1
}
y="0x80"//设置液晶下半部分坐标
x="0x88"
for(i=0i<32i++) //写入液晶下半图象部分
{
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>0num--)
{
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=5h>0h--)
for(i=4i>0i--)
for(j=116j>0j--)
for(k=214k>0k--)
}while(--count)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)