显示屏12864:图像+汉字+闪烁

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit PSB=P2^3;
sbit RW=P2^1;
sbit RS=P2^2;
sbit EN=P2^0;
//sbit beef=P2^5;
uchar code table[]="我喜欢艾达王";
uchar lcd_x,lcd_y;
uchar code image[]=
{/*
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0xFC,0x00,0x00,0x7F,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0xFE,0x00,0x00,0x7F,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0xFF,0x00,0x00,0x00,0xFE,0x00,0x00,0x7F,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x01,0x00,
0x00,0x00,0xFF,0x07,0x00,0xC0,0xFF,0x00,0x00,0xFE,0x03,0x00,0xC0,0xFF,0x01,0x00,
0x00,0x00,0xFF,0x3F,0x00,0xFC,0xFF,0x00,0x00,0xFE,0x3F,0x00,0xFC,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0x01,0xFF,0x3F,0x00,0x00,0xFC,0xFF,0x00,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x01,0x0

0,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0x7F,0xF8,0xFF,0x3F,
0x00,0x00,0x00,0x00,0xFC,0xFF,0x3F,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x00,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFC,0x00,0x00,0xFC,0xFF,0xFB,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0x07,0xE0,0xFF,0xFF,0xFD,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0xFD,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xE3,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0xFF,0xFF,0xDF,0xFF,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0xFE,0xFF,0xC1,0xFF,0xFF,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0x00,0x00,0x00,0xE0,0xFB,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0x00,0x00,0x00,0xE0,0xFD,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0x00,0x00,0x00,0xC0,0xFD,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0xFC,0x01,0x00,0xFE,0x01,0x00,
0x00,0x00,0x7F,0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0xF8,0x01,0x00,0xFC,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,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/*"C:\Users\xu changlong\Desktop\111_副本.bmp",0*/
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x0

0,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x
00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x

00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
};
void delay1(void) //误差 0us
{
unsigned char a,b,c;
for(c=167;c>0;c--)
for(b=171;b>0;b--)
for(a=16;a>0;a--);
}

void delay(uint x)
{
x=x*12;
while(x--)
{
_nop_();
_nop_();
_nop_();

}
}
void write_lcd_cmd(uchar cmd)//写命令
{
RS=0;
RW=0;
EN=1;
P1=cmd;
// delay(1);
EN=0;
delay(1);
}
void write_lcd_date(uchar date)//写数据
{
RS=1;
RW=0;
EN=1;
P1=date;
// delay(1);
EN=0;
delay(1);
}

void display_pos(uchar x,uchar y)//设置显示地址
{
uchar pos;
switch(x)
{
case 0: pos=0x80; break;
case 1: pos=0x90; break;
case 2: pos=0x88; break;
case 3: pos=0x98; break;
default: pos=0x80;
}
pos=pos+y;
write_lcd_cmd(pos);
}
/*====================================================
函数功能:清除GCROM的内容,如果不清除会出现花屏现象
清除方法:向GCROM中写入0x00来清除内容

========================================================*/
void clear_gcrom()
{
uchar i,j,k;
lcd_x=0x80;
lcd_y=0x80;
write_lcd_cmd(0x34);
for(i=0;i<2;i++)
{
for(j=0;j<32;j++)
{
write_lcd_cmd(lcd_y+j);
write_lcd_cmd(lcd_x);
for(k=0;k<16;k++)
{
write_lcd_date(0x00);
}
}
lcd_x=0x88;
}
write_lcd_cmd(0x36);
write_lcd_cmd(0x30);
}
/*================================================================
函数功能:向12864中写入一幅图片
函数参数:lcd_x为水平显示位置,lcd_y为垂直显示位置,
函数将12864屏分成上下两屏写入,上半屏LCD_x=0x80,下半屏lcd_x=0x88
=================================================================*/
void write_image(uchar *p)
{
uchar i = 0,j,k,num;
lcd_x=0x80;
lcd_y=0x80;
write_lcd_cmd(0x34);
for(i = 0;i<2;i++) //分为上下两屏
{
if(i==0) j = 0,num = 32;
if(i==1) j = 0,num = 16;
for(;j<num;j++)
{
write_lcd_cmd(lcd_y+j);
write_lcd_cmd(lcd_x);
for(k=0;k<16;k++) //写入显示数据
{
write_lcd_date(*p++);
}
}
lcd_x=0x88;
}
write_lcd_cmd(0x36);
write_lcd_cmd(0x30);
}

void init()//初始化函数
{
// beef=0;
RW=0;
write_lcd_cmd(0x30);//基本指令动作
write_lcd_cmd(0x0c);
write_lcd_cmd(0x06);
write_lcd_cmd(0x01);//清除显示
delay(5);
}
void main()
{
uint i,j;

init();
// write_lcd_cmd(0x1c

);
clear_gcrom();

write_image(image);



while(1)
{
display_pos(3,2);
for(i=0;i<6;i++)
w
rite_lcd_date(table[i]);

for(j = 0;j<3;j++)
{
delay1();
display_pos(3,5);
for(i=6+2*j;i<8+2*j;i++)
write_lcd_date(table[i]);
}
}
}



















相关文档
最新文档