本帖最后由 sTw_gongwen 于 2011-6-12 20:15 编辑
使用硬件:慧净的HJ-1C型的学习实验板;带字库的LCD12864液晶屏;STC89C52单片机;
查资料知道绘图显示步骤为:
1.关闭绘图显示功能;
2.写入水平位元组坐标(X);
3.写入垂直坐标(Y);
4.将D15-D8数据写入;
5.将D7-D0数据写入;
6.打开绘图显示功能;
代码如下:
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
/*TS12864A-3 端口定义*/
#define LCD_data P0 //数据口
sbit LCD_RS = P3^5; //寄存器选择输入
sbit LCD_RW = P3^6; //液晶读/写控制
sbit LCD_EN = P3^4; //液晶使能控制
sbit LCD_PSB = P3^7; //串/并方式控制
//***************************************************************************************
void delay(uint z) //延时z毫秒子函数
{
uint x;
uchar y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
//******************************************************************
uchar code picture1[]; //图片代码
bit lcd_busy(); //LCD测忙
void lcd_wcmd(uchar cmd); //向LCD12864写指令子函数
void lcd_wdata(uchar Xdata); //向LCD12864写数据子函数
void lcd12864_init(); //LCD12864初始化子函数
void lcd_weizhi(uchar X,uchar Y); //确定显示位置
void print(uchar X,uchar Y,uchar *str); //打印字符串子函数 举例:print(0x80,"gongwen");
void print2(uchar X,uchar Y,uchar t); //打印一个字符子函数 举例:print2(0x80,'0');
void displaypicture(uchar code *pic); //显示图片子函数
void pic_init();
//******************************************************************
void main()
{
lcd12864_init(); //显示汉字字母数字
print2(2,6,'6');
print(3,0,"ab12您好!");
delay(10000);
pic_init(); //显示图片
lcd_wcmd(0x01); //清屏指令
delay(5);
displaypicture(picture1);
delay(100);
while(1);
}
//******************************************************************
bit lcd_busy() //LCD测忙
{
bit result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
delay(1);
result = (bit)(P0&0x80);
LCD_EN = 0;
return(result);
}
//******************************************************************
void lcd_wcmd(uchar cmd) //向LCD12864写指令子函数
{
while(lcd_busy());
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
P0 = cmd;
delay(5);
LCD_EN = 1;
delay(5);
LCD_EN = 0;
}
//******************************************************************
void lcd_wdata(uchar Xdata) //向LCD12864写数据子函数
{
while(lcd_busy());
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
P0 = Xdata;
delay(5);
LCD_EN = 1;
delay(5);
LCD_EN = 0;
}
//******************************************************************
void lcd12864_init() //LCD12864初始化子函数
{
delay(50);
LCD_PSB = 1; //并口方式
lcd_wcmd(0x34); //扩充指令操作
delay(5);
lcd_wcmd(0x30); //基本指令操作
delay(5);
lcd_wcmd(0x0C); //显示开,关光标
delay(5);
lcd_wcmd(0x01); //清除LCD的显示内容
delay(5);
}
//******************************************************************
void lcd_weizhi(uchar X,uchar Y) //确定显示位置
{
uchar weizhi;
if (X==1)
{X=0x80;}
else if (X==2)
{X=0x90;}
else if (X==3)
{X=0x88;}
else if (X==4)
{X=0x98;}
weizhi = X+Y ;
lcd_wcmd(weizhi); //显示地址
}
//******************************************************************
void print(uchar X,uchar Y,uchar *str) //打印字符串子函数 举例:print(0x80,"gongwen");
{
lcd_weizhi(X,Y);
while(*str != '\0')
{
lcd_wdata(*str++);
}
*str = 0;
}
//******************************************************************
void print2(uchar X,uchar Y,uchar t) //打印一个字符子函数 举例:print2(0x80,'0');
{
lcd_weizhi(X,Y);
lcd_wdata(t); //写数据
}
//******************************************************************
void displaypicture(uchar code *pic) //显示图片子函数
{
char i,j;
lcd_wcmd(0x34); //关闭绘图显示
for(i=0;i<32;i++) //显示上半屏的内容
{
lcd_wcmd(0x80+i);
lcd_wcmd(0x80);
for(j=0;j<16;j++)
{
lcd_wdata(*pic);
pic++;
}
}
for(i=0;i<32;i++) //显示上半屏的内容
{
lcd_wcmd(0x80+i);
lcd_wcmd(0x88);
for(j=16;j<32;j++)
{
lcd_wdata(*pic);
pic++;
}
}
lcd_wcmd(0x36); //打开绘图显示
}
//******************************************************************
uchar code picture1[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,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,0x0F,0x0F,0x07,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1C,0x3C,0x3F,0x1F,0x1F,0x0F,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,0x06,0x0F,0x0F,0x0F,0x07,0x03,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x1E,0x1E,0x1F,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC3,0xCF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x3C,0x3C,
0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0xBC,0xFF,0xFF,0xFF,0xFF,0x3F,0x3D,0x3C,0x3C,0x7C,
0xFC,0xF8,0xF0,0xF0,0xF0,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,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,0xF8,0xFC,0xFE,0xFE,0xDF,0x0F,
0x07,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x07,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xE0,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,
0x3F,0xFF,0xFC,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x8F,0xFF,0xFF,0xFF,0xFF,0x07,0x07,0x03,
0x03,0x03,0x03,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x03,0x07,0x07,0x07,0x03,
0x00,0x00,0x00,0x00,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,0x83,0xE1,
0xF0,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x38,0x7C,0x7C,0xBC,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x78,0xF8,0xF8,0x78,0x78,0x78,0x78,
0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x7C,0x7E,0xFE,0xFC,
0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1B,0x3F,0x3F,0x3F,0x3D,0x3C,0xBC,0xBC,0xBC,0xBC,0xFC,0xFC,0xFC,
0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFD,0xFD,0xBC,0x3C,
0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
0x3C,0x3C,0x3E,0x3E,0x1E,0x1F,0x1F,0x1F,0x1F,0x0F,0x00,0x00,0xE0,0xF8,0xF8,0xFC,
0x7E,0x3E,0x1F,0x1F,0x0F,0x07,0x31,0x78,0x78,0x78,0x78,0x79,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x78,0x78,0x78,0x78,0x78,0x78,0x78,
0x78,0x78,0x78,0x7F,0x7F,0x7F,0x7F,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,
0x78,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xF0,0xF8,0xFE,0xFE,0x3F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0xFF,0xFF,0xFF,0xFF,0x00,
0x00,0x00,0x00,0x01,0x03,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x07,
0x07,0x07,0x3F,0x7F,0xFF,0xFE,0xF0,0xF0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0xC0,0xF8,0xFC,0xFC,0xF8,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xE0,0x98,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x1F,0xFF,0xFF,0xFF,0xFF,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81,0xC3,0xFF,0xFF,0xFF,0xFF,0x03,
0x03,0x03,0x07,0x0F,0x1F,0x1F,0x3F,0x3F,0x7F,0xFF,0xFF,0xF7,0xF7,0x8F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x8F,0xCF,0xEF,0xFF,0xFF,0xFF,0x7F,0x7F,0xFF,0xFF,0xFF,0xEF,0xDF,
0xDF,0x8F,0x8F,0x0F,0x0F,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x3F,0x7F,0x7F,0x3F,0x00,0x00,0xC0,0xE0,0xE0,0xC0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x1F,
0xFF,0xFF,0xFF,0xF8,0xC0,0x03,0x07,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,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,0xC0,0xFF,0xFF,0xFF,0xFF,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x80,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,0x01,0x0F,
0x1F,0x3F,0xFF,0xFC,0xF8,0xF0,0xC0,0x60,0xF0,0xF0,0xF0,0xF0,0xF8,0x78,0x78,0x78,};
//**************************************************************************************
void pic_init() //绘图模式初始化
{
delay(100);
LCD_PSB = 1; //并口方式
lcd_wcmd(0x36); //扩充指令操作
delay(5);
lcd_wcmd(0x36); //扩充指令操作
delay(5);
lcd_wcmd(0x3E);
delay(5);
lcd_wcmd(0x01); //清除LCD的显示内容
delay(5);
}
//******************************************************************************************
/*程序编译烧写后,文字部分能正常显示,但图片显示时只有一片乱点;
新人真心求教,望各位前辈能抽空给点解答,好人一生平安*/ |