本帖最后由 dc42733255 于 2020-10-31 15:58 编辑
初学者,用LCD12864可以显示字库与点,就是不能显示图片,请大家指点指点,程序如下:
#include "./lcd.h"
#define uchar unsigned char
#define uint unsigned int
#define led_data_bus P0 //data bus is P0 PORT
/********P0.0-P0.7is DATA/ORDER NOTE LOW ACTIVE*******,P1.1 is RST,***P1.2 is RS,***P1.3 is RW,***P1.4 is REN*/
sbit RST=P1^1;
sbit RS=P1^2;
sbit RW=P1^3;
sbit E=P1^4;
sbit PSB=P3^2;
void delay_lcd(uint w)
{
uint j;
for(j=0;j<w;j++)
;
}
/******busy check******/
void chk_busy()
{
led_data_bus=0xff;
RS=0;
RW=1;
E=1;
delay_lcd(50);
while(led_data_bus & 0x80);
E=0;
}
/******busy check******/
/*****write com******/
void write_com(unsigned char cmdcode)
{
chk_busy(); //忙检查
RS=0;
RW=0; //RS=0,RW=0;表示MCU写指令到暂存器IR
E=1;
led_data_bus=cmdcode; //Lcd_Bus=P0;
E=0; //E由高到低变化配合W进行写指令或写数据
}
/*****write com******/
/*****write data******/
void write_data(unsigned char Dispdata)
{
chk_busy(); //忙检查
RS=1;
RW=0; //RS=1;RW=0;表示MCU写数据到暂存器IR
E=1;
led_data_bus=Dispdata; //Lcd_Bus=P0;
E=0; //E由高到低变化配合W进行写指令或写数据
}
/*****write data******/
/*****READ data******/
uchar read_data(void)
{
uchar ram_data;
chk_busy(); //忙检查
RS=1;
RW=1; //RS=1;RW=0;表示MCU写数据到暂存器IR
E=0;
led_data_bus=0xff;
delay_lcd(50);
E=1;
delay_lcd(50);
ram_data=led_data_bus; //Lcd_Bus=P0;
E=0; //E由高到低变化配合W进行写指令或写数据
return ram_data;
}
/*****READ data******/
/*****initail LCD******/
void lcm_init()
{ RST=0;
delay_lcd(50);
RST=1;
delay_lcd(50);
PSB=0;
delay_lcd(50);
PSB=1;
delay_lcd(100);
write_com(0x30); //选择8bit数据流 0X30=0011,0000
delay_lcd(100);
write_com(0x01); //开显示(无游标,不反白)
delay_lcd(100);
write_com(0x06); //清除显示,并且设定地址指针为00H
delay_lcd(100);
write_com(0x0c);
}
/*****initail LCD******/
//============================================================//写数据或指令(被调用层)
void lcm_w_test(bit i,unsigned char word)
{
if(i == 0) //根据i的状态区分指令或数据
{
write_com(word);//写数据或指令(0,指令)
}
else
{
write_data(word);//写指令或数据(1,数据)
}
}
//-----------------------------------------------------------//清屏函数
void lcm_clr(void)
{
write_com(0x30);
delay_lcd(50);
write_com(0x08);
delay_lcd(50);
write_com(0x0c);
delay_lcd(50);
write_com(0x01);
delay_lcd(50);
write_com(0x06);
}
//===========================================================//向LCM发送一个字符串,长度64字符之内(被调用层),
void lcd_str(uchar *s)
{
while(*s!='\0')
{
lcm_w_test(1,*s);
s++;
}
}
void lcd_putstring(uchar x,uchar y,uchar *s)
{
switch(y)
{
case 1: write_com(0x80+x); break;
case 2: write_com(0x90+x); break;
case 3: write_com(0x88+x); break;
case 4: write_com(0x98+x); break;
default:break;
}
while(*s>0)
{
write_data(*s);
s++;
delay_lcd(100);
}
}
void led_picture(uchar *p)
{
uchar i,j,addr_x,addr_y_sbp,addr_y_xbp;
addr_x=0x80;
addr_y_sbp=0x80;//上半屏
addr_y_xbp=0x88;//下半屏
write_com(0x34);
for(i=0;i<32;i++)
{
for(j=0;j<8;j++)
{
write_com(addr_y_sbp+i);
write_com(addr_x);
write_data(*p);
p++;
write_data(*p);
p++;
}
}
for(i=0;i<32;i++)
{
for(j=0;j<8;j++)
{
write_com(addr_y_xbp+i);
write_com(addr_x);
write_data(*p);
p++;
write_data(*p);
p++;
}
}
write_com(0x36);
}
主函数:
#include<REG52.H>
#include "./lcd.h"
#define uchar unsigned char
#define uint unsigned int
uchar a[]={"书山有路勤为径"};
uchar b[]={"学海无涯苦作舟"};
uchar c[]={" 实践出真理 "};
uchar d[]={" 地顿悟 "};
uchar pitc[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
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,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1C,0x00,0x80,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x24,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,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,0x80,0x01,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 main(void)
{
uchar i,j;
P0=0x00;
P1=0x00;
lcm_init();
led_picture(pitc);
while(1);
}
|