#include <reg52.h>
#include <intrins.h>
/*定义管脚*/
sbit RS = P1^0;
sbit RW = P1^1;
sbit E = P1^2;
sbit RES = P1^3;
sbit PSB = P1^5;
#define Lcd_Bus P0 //MCU P2<------> LCM
#define FIRST_ADDR 0 //定义字符/汉字显示起始位置
unsigned char code zk[]={
0x08,0x20,0x1c,0x10,0x1c,0x1c,0xff,0x9e,0x7f,0x1e,0x1c,0x1f,0x3e,0x1f,0x3e,0x1f,
0x77,0x1f,0x41,0x3f,0x00,0x7e,0x00,0xfe,0x83,0xfc,0x7f,0xf8,0x3f,0xf0,0x0f,0xc0,
};
unsigned char code BMP1[]={
/*-- 一幅图像 KISS- 正向取模,字节正序*/
/*-- 宽度x高度=128x64 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFF,0x9F,0x00,0x00,0x0F,0x0E,0x00,0x00,0x00,0x00,0x19,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xBF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFD,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xF3,0xE0,0x00,0x00,0x1F,0xFD,0x80,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFA,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xF0,0x00,0x00,0x00,0x03,0xF8,0x01,0xFF,0xFF,0xE0,0x00,0x07,0xFF,0xFF,
0x00,0x00,0x00,0x0F,0xFF,0xFC,0x00,0xF0,0x3F,0xFF,0xFF,0xFE,0x00,0x30,0x00,0x00,
0x00,0x00,0x00,0x7F,0xFF,0xFF,0x80,0x41,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,
0xFF,0xFF,0x01,0xFF,0xFF,0xFF,0xF0,0x02,0x7F,0xFF,0xFF,0xFF,0xE0,0x03,0xFF,0xFF,
0x00,0x00,0x03,0xFF,0xFF,0xFF,0xF8,0x04,0x3F,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,
0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFC,0x08,0x73,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,
0xFF,0xE4,0x3F,0x7F,0xFF,0xFF,0xFF,0x30,0x2F,0xFF,0xFF,0xFF,0xFE,0x00,0x7F,0xFF,
0x00,0x00,0xFE,0x9F,0xFF,0xFF,0xFF,0xB0,0x1D,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,
0x00,0x00,0xFF,0x7F,0xFF,0xFF,0xFF,0xC2,0x23,0x3F,0xFF,0xFE,0x1F,0x80,0x00,0x00,
/*****************************************************************************/
0xFF,0xE1,0xFF,0xFF,0xFF,0xFF,0xFC,0xC5,0x92,0xFF,0xB7,0xB8,0xC9,0x80,0x7F,0xFF,
0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFC,0x4F,0xEF,0x3F,0xC8,0x1A,0x20,0xC0,0x00,0x00,
0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xF8,0x7F,0xFF,0xFF,0x75,0x86,0xF6,0xC0,0x00,0x00,
0xFF,0x03,0xEF,0x9F,0xFB,0xFF,0xF8,0x7F,0xFF,0xFF,0xFB,0xDF,0xFE,0xC0,0x7F,0xFF,
0x00,0x07,0xDE,0x7F,0xC7,0xFF,0xF0,0x7E,0x7F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,
0x00,0x07,0x1C,0xF7,0x9F,0xDF,0xF0,0x7E,0x7F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,
0xFC,0x07,0x00,0x8C,0x1F,0xBF,0xE7,0x3C,0x3F,0xFF,0xFF,0xFF,0xFF,0xC0,0x7F,0xFF,
0x00,0x07,0x00,0x08,0x1C,0x3F,0x88,0x3C,0x7F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,
0x00,0x06,0x0C,0x08,0x98,0x7F,0x80,0x0D,0x9F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,
0xFC,0x06,0x1C,0xE3,0x99,0xFF,0x00,0x0C,0x0F,0xFF,0xFF,0xFF,0xFF,0xC0,0x5F,0xFF,
0x00,0x06,0xF1,0xE3,0x83,0xFE,0x00,0x08,0x03,0xDF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,
0x00,0x06,0xF1,0xF7,0xC7,0xFE,0x00,0x08,0x01,0xCF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,
0xFC,0x06,0xF3,0xF7,0xC7,0xFC,0x03,0x08,0x00,0x01,0xFF,0xFF,0xFF,0xC0,0xBF,0xFF,
0x00,0x07,0xF3,0xFF,0xE7,0xF0,0x03,0x09,0x80,0x00,0xFF,0xFF,0xFF,0xC0,0x00,0x00,
0x00,0x07,0xFF,0xFF,0xFF,0xE0,0x03,0x09,0x80,0x00,0x3F,0xFF,0xFF,0x80,0x00,0x00,
0xFC,0x07,0xFF,0xFF,0xFF,0xC0,0x03,0x09,0x80,0x00,0x0F,0xFF,0xFF,0x83,0xFF,0xFF,
/*****************************************************************************/
0x00,0x07,0xFF,0xE0,0xFE,0x00,0x03,0x09,0x80,0x00,0x07,0xFF,0xFF,0x80,0x00,0x00,
0x00,0x07,0xFF,0x80,0x7C,0x00,0x07,0xB1,0x80,0x00,0x07,0x83,0xFF,0x00,0x00,0x00,
0xFF,0x07,0xFF,0x0C,0x00,0x00,0x7F,0xB3,0xC0,0x00,0x06,0x01,0xFE,0x03,0xFF,0xFF,
0x00,0x07,0xFF,0x03,0x00,0x00,0x1F,0x43,0xFC,0x00,0x06,0x38,0xFE,0x00,0x00,0x00,
0x00,0x07,0xFF,0x03,0x00,0x00,0x00,0x81,0xF0,0x00,0x04,0x40,0xF8,0x00,0x00,0x00,
0xFC,0x87,0xFF,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x04,0x40,0xF0,0x07,0xFF,0xFF,
0x00,0x07,0xFF,0x80,0x00,0x2C,0x00,0x80,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,
0x00,0x07,0xFF,0x80,0x00,0x52,0x00,0x40,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,
0xFF,0x83,0xFF,0xF0,0x80,0x2C,0x00,0x40,0x00,0x00,0x00,0x01,0xC0,0x7F,0xFF,0xFF,
0x00,0x03,0xFF,0xFF,0x80,0x00,0x00,0x30,0x00,0x00,0x01,0x86,0x00,0x00,0x00,0x00,
0x00,0x03,0xFF,0xFF,0x80,0x00,0x00,0x38,0x00,0x00,0x01,0xF8,0x00,0x00,0x00,0x00,
0xFF,0xA3,0xFF,0xFF,0x80,0x00,0x00,0x44,0x00,0x00,0x01,0xFF,0x00,0x7F,0xFF,0xFF,
0x00,0x03,0xFF,0xFF,0x80,0x00,0x03,0x82,0x00,0x00,0x01,0xC0,0xC0,0x00,0x00,0x00,
0x00,0x03,0xFF,0xFF,0x80,0x00,0x1C,0x01,0xC0,0x00,0x00,0x78,0xC0,0x00,0x00,0x00,
0xFF,0x81,0xFF,0xFF,0xC0,0x3F,0xE0,0x00,0x3C,0x00,0x07,0x80,0x20,0x7F,0xFF,0xFF,
0x00,0x01,0xFF,0xFF,0xE0,0x40,0x00,0x00,0x03,0xFE,0x78,0x00,0x20,0x00,0x00,0x00,
/*****************************************************************************/
0x00,0x01,0xFF,0xFF,0xF8,0x40,0x00,0x00,0x00,0x21,0x80,0x00,0x10,0x00,0x00,0x00,
0xFF,0xC1,0xFF,0xFF,0xFC,0x40,0x00,0x00,0x00,0x2E,0x00,0x00,0x10,0x4F,0xFF,0xFF,
0x00,0x01,0xFF,0xFF,0xFE,0x20,0x00,0x00,0x00,0x30,0x00,0x00,0x30,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xA0,0x00,0x00,0x00,0xC0,0x00,0x01,0xF8,0x00,0x00,0x00,
0xFF,0xE0,0xFF,0xFF,0xFB,0xE0,0x00,0x00,0x00,0xC0,0x00,0x03,0xFE,0x07,0xFF,0xFF,
0x00,0x00,0xFF,0xFF,0xFD,0xE0,0x00,0x00,0x00,0xC0,0x00,0x1F,0xFF,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0xFE,0x70,0x00,0x00,0x01,0xE0,0x00,0x3F,0xFF,0x80,0x00,0x00,
0xFF,0xC0,0xFF,0xFF,0xFF,0xB0,0x00,0x00,0x01,0xE0,0x00,0x7F,0xFF,0xC0,0x3F,0xFF,
0x00,0x00,0xFF,0xFF,0xFF,0xDC,0x00,0x00,0x03,0xF7,0x81,0xFF,0xFF,0xF0,0x00,0x00,
0x00,0x01,0xFF,0x80,0x7F,0xDC,0x00,0x00,0x0F,0xFF,0xC3,0xFF,0xFF,0xF8,0x00,0x00,
0xFF,0x01,0xFF,0x00,0x1F,0xEE,0x00,0x00,0x13,0xFF,0xF7,0xFF,0xFF,0xFC,0x07,0xFF,
0x00,0x01,0xFE,0x00,0x07,0xEF,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0x01,0xFC,0x00,0x03,0xF3,0x00,0x00,0x13,0xFF,0xBF,0xFF,0xFF,0xFF,0x80,0x00,
0xFF,0x01,0xFC,0x00,0x01,0xF3,0x80,0x00,0x1F,0xFF,0xBF,0xFF,0xFF,0xFF,0x83,0xFF,
0x00,0x01,0xF0,0x00,0x01,0xFD,0x80,0x00,0x0F,0xFF,0x7F,0xFF,0xFF,0xFF,0xC0,0x00,
0x00,0x03,0xF0,0x00,0x00,0x72,0xE0,0x00,0x03,0xFE,0xFF,0xFF,0xFF,0xFF,0xC0,0x00
};
unsigned char code BMP[]={
//一幅图像 - 正向取模,字节正序
/*-- 宽度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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x40,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x40,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x40,0x38,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x60,0x00,0x06,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x01,0x80,0x00,0x38,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x03,0xC0,0x00,0x03,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1C,0x38,0x00,0x1C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x04,0x00,0xE0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x02,0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,0x01,0x00,0x00,0x80,0x00,0x00,0x00,
/*****************************************************************************/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x01,0x00,0x00,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE1,0x00,0x00,0x80,0x00,0x00,0x00,
0x00,0x00,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x40,0x00,0x00,0x00,
0x00,0x00,0x18,0xC0,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x40,0x00,0x00,0x00,
0x00,0x00,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x41,0xC0,0x00,0x00,
0x00,0x00,0x30,0x60,0x3F,0xC0,0x00,0x00,0x00,0x02,0x00,0x00,0x40,0x3E,0x00,0x00,
0x00,0x00,0x20,0x23,0xC0,0x60,0x00,0x00,0x00,0x61,0x00,0x00,0x80,0x01,0xC0,0x00,
0x00,0x00,0x40,0x3C,0x00,0x18,0x00,0xC0,0x07,0xC1,0x00,0x00,0x80,0x00,0x00,0x00,
0x00,0x00,0x40,0x18,0x00,0x04,0x01,0xA0,0x1C,0x01,0x00,0x00,0x80,0x00,0x00,0x00,
0x00,0x00,0x40,0x08,0x00,0x06,0x02,0x1C,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0x08,0x00,0x01,0x8C,0x03,0x80,0x00,0x40,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0x0C,0x00,0x00,0x58,0x00,0x60,0x06,0x20,0x04,0x20,0x00,0x00,0x00,
0x00,0x01,0x00,0x04,0x00,0x00,0x20,0x00,0x10,0x1C,0x1C,0x38,0x18,0x00,0x00,0x00,
0x00,0x01,0x00,0x06,0x00,0x00,0x30,0x00,0x08,0x30,0x03,0xC0,0x07,0x00,0x00,0x00,
0x00,0x01,0x00,0x02,0x00,0x00,0x18,0x00,0x04,0x60,0x00,0x00,0x01,0x80,0x00,0x00,
0x00,0x02,0x00,0x00,0x00,0x00,0x0C,0x00,0x03,0x00,0x00,0x00,0x00,0x40,0x00,0x00,
/*****************************************************************************/
0x00,0x02,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x80,0x02,0x08,0x00,0x30,0x00,0x00,
0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x02,0x08,0x00,0x18,0x00,0x00,
0x00,0x0C,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x20,0x02,0x04,0x00,0x00,0x00,0x00,
0x00,0x0C,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x18,0x02,0x04,0x00,0x00,0x00,0x00,
0x00,0x18,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x07,0xF2,0x02,0x00,0x00,0x00,0x00,
0x00,0x30,0x00,0x00,0x0F,0xFC,0x00,0x00,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,
0x00,0x60,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x00,0x40,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x01,0x80,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x80,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,0x0F,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x8C,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x30,0xCC,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,
/*
"太", "阳", "出", "来", "喜", "洋", "洋", "喽",*/
0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x22,0x10,0x22,0x10,0x00,0x48,
0x01,0x00,0x7D,0xFC,0x01,0x00,0x01,0x00,0x7F,0xFC,0x11,0x10,0x11,0x10,0x02,0x4C,
0x01,0x00,0x45,0x04,0x21,0x04,0x3F,0xFC,0x01,0x00,0x11,0x20,0x11,0x20,0xF1,0x50,
0x01,0x00,0x49,0x04,0x21,0x04,0x01,0x00,0x3F,0xF8,0x07,0xFC,0x07,0xFC,0x97,0xFE,
0x7F,0xFE,0x49,0x04,0x21,0x04,0x09,0x30,0x00,0x00,0x80,0x40,0x80,0x40,0x90,0xE0,
0x01,0x00,0x51,0x04,0x21,0x04,0x05,0x20,0x1F,0xF0,0x50,0x40,0x50,0x40,0x91,0x50,
0x01,0x00,0x49,0xFC,0x3F,0xFC,0x03,0x40,0x10,0x10,0x57,0xFC,0x57,0xFC,0x92,0x4E,
0x01,0x00,0x45,0x04,0x21,0x04,0x7F,0xFE,0x1F,0xF0,0x10,0x40,0x10,0x40,0x9D,0x44,
0x02,0x80,0x45,0x04,0x01,0x00,0x01,0x80,0x04,0x40,0x20,0x40,0x20,0x40,0x91,0x00,
0x02,0x40,0x45,0x04,0x21,0x04,0x03,0x40,0xFF,0xFE,0x2F,0xFE,0x2F,0xFE,0xF7,0xFC,
0x04,0x20,0x69,0x04,0x21,0x04,0x05,0x20,0x00,0x00,0xE0,0x40,0xE0,0x40,0x92,0x10,
0x05,0x10,0x51,0x04,0x21,0x04,0x09,0x18,0x1F,0xF0,0x20,0x40,0x20,0x40,0x83,0x20,
0x08,0x98,0x41,0xFC,0x21,0x04,0x31,0x0E,0x10,0x10,0x20,0x40,0x20,0x40,0x00,0xE0,
0x10,0xCC,0x41,0x04,0x3F,0xFC,0xC1,0x04,0x10,0x10,0x20,0x40,0x20,0x40,0x01,0x18,
0x20,0x86,0x40,0x00,0x01,0x00,0x01,0x00,0x1F,0xF0,0x20,0x40,0x20,0x40,0x02,0x0C,
0x40,0x04,0x40,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x20,0x40,0x20,0x40,0x04,0x08
};
/*------------------检查忙位-----------------------------*/
void chk_busy()
{ RS=0;
RW=1;
E=1;
Lcd_Bus=0xff;
while((Lcd_Bus&0x80)==0x80);
E=0;
}
/*------------------延时子程序-----------------------------*/
void delay(unsigned int t)
{ unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++);
}
/*------------------写命令到LCD------------------------------*/
void write_com(unsigned char cmdcode)
{
chk_busy();
RS=0;
RW=0;
E=1;
Lcd_Bus=cmdcode;
delay(5);////////////////////在数据写入的时候加入适当的延时
E=0;
delay(5);
}
/*-------------------写数据到LCD----------------------------*/
void write_data(unsigned char Dispdata)
{
chk_busy();
RS=1;
RW=0;
E=1;
Lcd_Bus=Dispdata;
delay(5);///////////////////在数据写入的时候加入适当的延时
E=0;
delay(5);
}
/*------------------初始化LCD屏--------------------------*/
void lcdreset()
{ delay(2000);
write_com(0x30);
delay(10); //选择基本指令集
write_com(0x30); //选择8bit数据流
delay(5);
write_com(0x0c); //开显示(无游标、不反白)
delay(10);
write_com(0x01); //清除显示,并且设定地址指针为00H
delay(500);
write_com(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位
delay(0);
}
/*------------------自定义一个字符代码(一个星星和月亮)--------------------------*/
void CGRAM()
{ int i;
write_com(0x30);
write_com(0x40);
for(i=0;i<16;i++)
{write_data(zk[i*2]);
write_data(zk[i*2+1]);
}
}
/*------------------显示字符串--------------------------*/
void hzkdis(unsigned char code *s)
{ while(*s>0)
{ write_data(*s);
s++;
delay(50);
}
}
/*------------------首屏显示--------------------------*/
void ceshi()
{write_com(0x01);//清除显示,并且设定地址指针为00H
delay(5);
write_com(0x80);//第一行(如果是地址是:80H,即LCD的第一行的第一个位置显示)
hzkdis("ourhc@163.com");
write_com(0x90);//第二行(如果是地址是:90H,即LCD的第二行的第一个位置显示)
hzkdis("汇诚科技电子");
write_com(0x88);//第三行(如果是地址是:88H,即LCD的第二行的第一个位置显示)
hzkdis("QQ:115451619");
write_com(0x98);//第四行(如果是地址是:98H,即LCD的第二行的第一个位置显示)
hzkdis("液晶显示测试程序");
}
/*------------------显示图片------------------------*/
void Disp_Img(unsigned char code *img)
{ unsigned int j=0;
unsigned char x,y,i;
for(i=0;i<9;i+=8)
for(y=0;y<32;y++)/*原来 为 y<26 ,上下两个半屏不能正常对接显示,导致显示的图片中间有空隙*/
for(x=0;x<8;x++)
{ write_com(0x36);//功能设置---8BIT控制界面,扩充指令集
write_com(y+0x80); //行地址
write_com(x+0x80+i); //列地址
write_com(0x30);
write_data(img[j++]);
write_data(img[j++]);
}
}
/*------------------清整个GDRAM空间----------------------------*/
void clrgdram()
{ unsigned char x,y;
for(y=0;y<64;y++)
for(x=0;x<16;x++)
{ write_com(0x34);
write_com(y+0x80); //行地址
write_com(x+0x80); //列地址
write_com(0x30);
write_data(0x00);
write_data(0x00);
}
}
/*------------------整屏写入数据:全亮,或者竖条-----------------------------*/
void lcdfill(unsigned char disdata)
{ unsigned char x,y;
for(y=0;y<32;y++)
for(x=0;x<16;x++)
{ write_com(0x36);
write_com(y+0x80); //行地址
write_com(x+0x80); //列地址
write_com(0x30);
write_data(disdata);
write_data(disdata);
}
write_com(0x34);
write_com(0x36);
}
/*------------------显示横-----------------------------*/
void Disp_H_Line()
{ unsigned char x,y;
unsigned char k=0x00;
for(y=0;y<32;y++)
{ k=~k;
for(x=0;x<16;x++)
{ write_com(0x36);
write_com(y+0x80); //行地址
write_com(x+0x80); //列地址
write_com(0x30);
write_data(k);
write_data(k);
};
}
write_com(0x34);
write_com(0x36);
}
/*------------------显示边框-------------------------------*/
void Frame()
{unsigned char x,y;
lcdfill(0x00);
for(x=0;x<9;x+=8)
for(y=0;y<32;y++)
{ write_com(0x36);
write_com(y+0x80); //行地址
write_com(x+0x80); //列地址
write_com(0x30);
write_data(0x80);
write_data(0x00);
write_com(0x36);
write_com(y+0x80); //行地址
write_com(x+0x87); //列地址
write_com(0x30);
write_data(0x00);
write_data(0x01);
}
for(y=0;y<2;y++)
for(x=0;x<8;x++)
{write_com(0x36);
write_com(y*31+0x80); //行地址
write_com(x+0x80+8*y); //列地址
write_com(0x30);
write_data(0xff);
write_data(0xff);
}
write_com(0x34);
write_com(0x36);
}
/*------------------在第7列的位置加入两条竖线--------------------------*/
void shuxian()
{ unsigned char x,y;
for(x=0;x<9;x+=8)
for(y=0;y<32;y++)
{ write_com(0x36);
write_com(y+0x80); //行地址
write_com(x+0x86); //列地址
write_com(0x30);
write_data(0x00);
write_data(0x14);
};
}
/*------------------清屏命令--------------------------*/
void clrscreen()
{
write_com(0x01);
delay(10);
}
/*------------------唐诗《静夜思》--------------------------*/
void gushi_display()
{ write_com(0x30);
clrscreen();
write_com(0x80+FIRST_ADDR);
hzkdis("白日依山尽,");
write_com(0x90+FIRST_ADDR);
hzkdis("黄河入海流。");
write_com(0x88+FIRST_ADDR);
hzkdis("欲穷千里目,");
write_com(0x98+FIRST_ADDR);
hzkdis("更上一层楼。");
write_com(0xb3+FIRST_ADDR);
hzkdis("登鹳雀楼");
write_com(0xaa+FIRST_ADDR);
hzkdis("( 唐 )王之焕");
}
main()
{ unsigned char i;
while(1)
{
PSB=0;
delay(300);
PSB=1;
RW=0;
lcdreset(); //初始化LCD屏
CGRAM();
ceshi(); //显示测试字样
delay(2000);
clrgdram();
clrscreen(); //清屏
Disp_Img(BMP); //调入一幅图画
delay(30000);
Disp_Img(BMP1); //调入一幅图画
delay(20000);
lcdfill(0xff); //显示全开
delay(2000);
Disp_H_Line(); //显示横条
delay(2000);
lcdfill(0xaa); //显示竖条
delay(2000);
Frame(); //显示边框
delay(2000);
gushi_display(); //显示唐诗
clrgdram();
write_com(0x87); //调用自定义的CGRAM的代码
write_data(0x00);
write_data(0x00);
delay(400);
shuxian(); //加入两条竖线
delay(8000);
write_com(0x30);
delay(2000);
gushi_display();
delay(6000);
for(i=0;i<8;i++) //字符循环左移
{write_com(0x18);
delay(2000);}
gushi_display();
delay(6000);
write_com(0x36);
write_com(0x04); //第一行反白显示
delay(6000);
write_com(0x04); //第一行恢复正常
delay(6000);
write_com(0x05); //第二行反白显示
delay(6000);
write_com(0x05); //第二行恢复正常
delay(6000);
write_com(0x03); //垂直滚动屏幕的内容
write_com(0x60);
delay(6000);
}
}
|