各位大虾,偶单片机菜鸟,学习液晶屏驱动程序,用protues 仿真HDG12864L-4显示不了,附上图片及程序请大虾指教
/*******************************************************************
* 文件名:DISPLAY_LCD12864_image_p.c
* 说 明:用HDG12864L-4仿真显示图片
*******************************************************************/
#include <reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD_DAT P2 //定义LCD数据端口
sbit A0=P0^0; //数据/命令控制端口 1数据 0命令
sbit E=P0^2; //时钟使能端口 1使能
sbit RW=P0^1; //读写操作 1读 0写
/* 宋体12(小四); 此字体对应的点阵为:宽x高=16x16 */
code uchar IMAGE_STYLE[]={/*-- 调入了一幅图像:这是您新建的图像 --*/
/*-- 宽度x高度=128x64 --*/
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,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0x90,0xD0,0x78,0xF8,0xF8,0xF8,0xF0,0xF0,0xF0,0xE0,0xE0,
0xE0,0xA0,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,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x06,0x0F,0x0F,0x07,0x0F,0x0F,0x0F,0xCF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xDD,0x9F,0x0E,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,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,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,0x00,0x00,0xE0,0xF0,0x78,0xF8,0xF0,0xE0,0xC0,0xC0,0x80,
0xC0,0xE0,0xE0,0xF0,0xFC,0xFE,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFD,0x3B,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x80,
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,
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,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xF8,0xFF,0xFF,0xFC,0x9C,0x3C,0x3D,0x3F,0x7F,0xFD,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF9,0xE1,0xC3,0x87,
0x05,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFE,0xE3,0xF1,
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,
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,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x1F,0x1F,0x78,0xF0,0x00,0x00,0x00,0x01,
0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFE,0xFE,0xFC,0xF8,0xF0,0xE0,0x80,0x80,0x80,0xC0,0xE0,0xFF,0xDF,0x7F,0x1F,
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,
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,
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,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x1F,0x7F,0xFF,0xFF,0xEF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,0x1F,0x07,0xBF,0xFF,0x3F,0x1F,0x05,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,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,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,0x00,0x01,0x03,
0x07,0x07,0x07,0x07,0x06,0x06,0x06,0x06,0x0E,0x0E,0x0E,0x1F,0x1F,0x07,0x9F,0xFF,
0xFF,0x7B,0x61,0x00,0x00,0x00,0x00,0x00,0x01,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,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x18,0x1C,0x1E,0x07,0x03,0x01,
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,
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
};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=0;y<80;y++) ;
}
/******************************************************
* 函 数:从并行口输入要显示的数据
* 参 数:dat 要显示的数据
* 返回值:无
*******************************************************/
void write_data(uchar dat)
{
A0=1;
RW=0;
_nop_();
_nop_();
LCD_DAT=dat; //输入要显示的数据
E=1;
_nop_();
_nop_();
E=0;
}
/******************************************************
* 函 数:从并行口输入命令
* 参 数:command 要输出的命令
* 返回值:无
*******************************************************/
void write_cmd(uchar command)
{
A0=0;
RW=0;
LCD_DAT=command; //输入要显示的数据
_nop_();
_nop_();
E=1;
_nop_();
_nop_();
E=0;
}
/******************************************************
* 函 数:清屏
* 参 数:空
* 返回值:无
*******************************************************/
void clear_screen(void)
{
uchar i,j;
for(i=0;i<8;i++)
{
write_cmd(0xB0|i); //写入页地址
write_cmd(0x00); //写入列低位起始地址
write_cmd(0x10); //写入列高位起始地址
for(j=0;j<128;j++)//128列清零
{
write_data(0x00);
}
}
}
/******************************************************
* 函 数:设定页地址
* 参 数:page 页地址,有效范围0~7
* 返回值:无
*******************************************************/
void set_page(uchar page)
{
uchar tmp = 0;
tmp = page&0x07; //确定输入值为0-7
tmp = tmp|0xB0; //获得页地址
write_cmd(tmp); //写入页地址
}
/******************************************************
* 函 数:设定列地址
* 参 数:column 列地址,有效范围0~127
* 返回值:无
*******************************************************/
void set_column(uchar column)
{
uchar col_h, col_l;
column = column&0x7f; //确定输入数值在0-127
col_h = column&0xf0; //取列地址高四位
col_h = col_h>>4;
col_l = column&0x0f; //取列地址低四位
col_h = col_h|0x10;
col_l = col_l|0x00;
write_cmd(col_h); //写入地址低四位
write_cmd(col_l); //写入地址低四位
}
/******************************************************
* 函 数:设定行地址
* 参 数:row 行地址
* 返回值:无
*******************************************************/
void set_row(uchar row)
{
write_cmd(row|0x40);
}
/******************************************************
* 函 数:开关显示设置
* 参 数:state 1:开显示 0:关显示
* 返回值:无
*******************************************************/
void LCD_open(uchar state)
{
state = state|0xAE; //开:0xAF; 关:0xAE
write_cmd(state); //写入状态
}
/******************************************************
* 函 数:液晶初始化
* 参 数:空
* 返回值:无
*******************************************************/
void LCD_init(void)
{
write_cmd(0xE2); //复位
write_cmd(0xAf); //液晶显示开
write_cmd(0xA2); //lcd bias set
write_cmd(0xA1); //反向显示(即从左到右显示)字的方向:0xA0/0xA1
write_cmd(0xc0); //字体上下颠倒显示 0xc0正向显示,0x80 颠倒显示 无此命令默认正向显示
write_cmd(0xA4); //所有的屏幕点开关,A4正常显示 A5所有点开 无此命令默认正常显示
set_page(0);
set_row(0);
set_column(0);
}
/*****************************************************
* 函数:显示一个16X16的汉字
* 参数:page:显示的页(0~7)
* column:显示的列(0~127)
* *pt:显示字的首地址
* 返回值:无
*****************************************************/
void show_pic128(uchar page, uchar column)
{
uchar i;
set_page(page); //设置页地址
set_column(column); //设置起始列
for(i=0; i<128; i++) //128列*8行图像
{
write_data(IMAGE_STYLE[page*128+i]); //写数据
}
}
/******************************************************
* 函 数:显示汉字
* 参 数:空
* 返回值:无
*******************************************************/
void display_image(void)
{
uchar page = 0;
uchar column = 0;
for(page=0; page<8; page++)
{
show_pic128(page, 0);
}
}
/******************************************************
* 函 数:端口初始化函数
* 参 数:空
* 返回值:无
*******************************************************/
/*
void port_init(void)
{
DDRA = 0xFF;
PORTA = 0x00;
DDRB = 0xFF;
PORTB = 0xFF;
DDRC = 0xFF;
PORTC = 0x00;
DDRD = 0xFF;
PORTD = 0xFF;
}
*/
/******************************************************
* 函 数:主函数,用HDG12864L-1的串行方式显示汉字
* 参 数:空
* 返回值:无
*******************************************************/
void main(void)
{
LCD_init ();
LCD_DAT=0X
clear_screen();
LCD_open(1);
display_image();
while(1)
{
write_cmd(0xA6); //字体颜色反显 0xA6/0xA7
delay(1000);
write_cmd(0xA7);
delay(1000);
}
}
|