51/AVR单片机技术驿站!  <在线翻译>     便利工具    特色网址   无弹窗、无插件的绿色站点...  英才招聘   学历查询  喜欢>>收藏我站 

当前位置:首页 > 单片机源码 > 详细内容
12864液晶显示程序(C)
发布时间:2009/6/2  阅读次数:976  字体大小: 【】 【】【

  

#include <reg51.h>
#include <intrins.h>

sbit RS = P2^5;
sbit RW = P2^6;
sbit E = P2^7;

sbit RES = P3^5;
#define Lcd_Bus P0 //MCU P1<------> 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[]={
/*-- 调入了一幅图像:D:\3033B\3033.bmp --*/
/*-- 宽度x高度=128x64 --*/
/*--总共52行数据,每行16个数据--*/


0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0C,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x00,0x00,0x00,0x00,0x00,0x07,0xF1,0x00,0x03,0x01,0x00,0xF0,0x00,0x00,0x00,
0x18,0x00,0x00,0x00,0x00,0x00,0x04,0x01,0x00,0x03,0x81,0x08,0x98,0x00,0x00,0x00,
0x10,0x1F,0x07,0x06,0x00,0x00,0x08,0x01,0x00,0x04,0x81,0x11,0x88,0x00,0x00,0x00,
0x10,0x21,0x0D,0x83,0xE3,0xC0,0x0F,0x02,0x00,0x04,0xC1,0x31,0x30,0x00,0x00,0x00,
0x10,0x21,0x18,0x83,0x06,0x40,0x09,0x82,0x00,0x0F,0xC1,0x21,0xE0,0x00,0x00,0x00,
0x10,0x2E,0x11,0x86,0x06,0x40,0x00,0x86,0x00,0x08,0x43,0xC3,0xE0,0x00,0x00,0x00,
0x30,0x30,0x11,0x86,0x04,0x40,0x41,0x84,0x10,0x18,0x63,0x82,0x18,0x00,0x00,0x00,
0x20,0x1E,0x1F,0x84,0x04,0x60,0x7E,0x04,0x08,0x10,0x23,0x04,0x0E,0x00,0x00,0x00,
0x3F,0x83,0x00,0xE0,0x00,0x00,0x00,0x00,0x04,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x38,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x6C,0x3C,0x00,0x20,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x42,0x22,0x03,0xFD,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x40,0x62,0x00,0x22,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x46,0x42,0x00,0x22,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x44,0x42,0x00,0x23,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0x26,0x00,0x2D,0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x3C,0x00,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x06,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x30,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x03,0x18,0x08,0x0C,0x30,0xF1,0x08,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x08,0x08,0x0C,0x31,0x91,0x08,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x08,0x08,0x1A,0x71,0x01,0x08,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x08,0x13,0xD1,0x01,0x08,0x00,
0x00,0x00,0x08,0x11,0x0A,0x00,0x20,0x20,0x04,0x04,0x18,0x11,0x91,0x01,0x08,0x00,
0x00,0x00,0x04,0x11,0x12,0x31,0x22,0x20,0x04,0x04,0x10,0x11,0x13,0x01,0x08,0x00,
0x00,0x00,0x02,0x1B,0x92,0x31,0x26,0x20,0x04,0x04,0x10,0x10,0x12,0x01,0x08,0x00,
0x3F,0xFF,0xFF,0x0A,0x91,0x73,0x25,0x60,0x04,0x44,0x10,0x10,0x12,0x01,0x08,0x00,
0x00,0x00,0x02,0x0A,0xB1,0x4A,0x35,0x40,0x04,0x34,0x30,0x10,0x13,0x01,0x08,0x00,
0x00,0x00,0x04,0x0E,0x61,0xCA,0x19,0x40,0x04,0x1C,0x20,0x10,0x11,0x19,0x98,0x00,
0x00,0x00,0x08,0x04,0x60,0xCC,0x19,0xCC,0x06,0x0E,0x20,0x10,0x11,0xF0,0xFC,0xC0,
0x00,0x00,0x00,0x04,0x60,0x8C,0x18,0x8C,0x03,0xF3,0xBF,0x80,0x00,0x00,0x00,0xC0,
0x00,0x00,0x00,0x00,0x40,0x80,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,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,0x83,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x06,0xC3,0xFC,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x08,0x22,0x44,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x22,0x42,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x26,0x42,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x24,0x42,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x64,0x42,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0xC4,0x44,0x42,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x03,0x84,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

unsigned char code BMP[]={

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x20,0x00,0x00,0x00,0x00,
0x1F,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x84,0x42,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x84,0x00,0x00,0x00,0x00,
0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0xE0,0x04,0x00,0x08,0x80,0x60,0x00,0x00,
0x00,0x1F,0xFF,0xC0,0x00,0x00,0x00,0x01,0x10,0x02,0x1F,0xC1,0x01,0xD0,0x00,0x38,
0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x00,0x10,0x00,0x70,0x72,0x01,0x0C,0x00,0x68,
0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x06,0x13,0x08,0x40,0x08,0x03,0x06,0x00,0xCC,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x09,0x84,0x80,0x0C,0x1E,0x03,0x89,0x86,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0xC1,0x80,0x04,0x68,0x00,0xFF,0x02,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x41,0x00,0x00,0xC0,0x00,0x60,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x61,0x00,0x00,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x31,0x00,0x00,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x0C,0x00,0x00,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x01,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x06,0x00,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x00,0x00,0x00,0xC0,0x00,0x03,0x00,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xE8,0x00,0x00,0x01,0x80,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x1A,0x08,0x00,0x00,0x03,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x00,0x00,0x02,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x18,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0xC0,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x00,0x02,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xF4,0x00,0x02,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x79,0xF8,0x10,0x20,0x00,
0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x09,0x08,0x10,0x20,0x00,
0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x09,0x08,0x10,0x20,0x00,
0x06,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x79,0xF8,0x10,0x20,0x00,
0x04,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0xFD,0xFE,0x00,
0x04,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x43,0xFC,0x10,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x03,0xFF,0xF0,0x42,0x44,0x10,0x60,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x7A,0x44,0x38,0x70,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x0B,0xFC,0x74,0xB0,0x00,
0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x54,0xA8,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x08,0x48,0x91,0x28,0x00,
0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x44,0x12,0x26,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x7E,0x14,0x24,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2B,0xC4,0x10,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 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("----强林单片机");

write_com(0x90);//第二行(如果是地址是:90H,即LCD的第二行的第一个位置显示)
hzkdis("--技术项目交易网");

write_com(0x88);//第三行(如果是地址是:88H,即LCD的第二行的第一个位置显示)
hzkdis("LCD12864点阵液晶");

write_com(0x9A);//第四行(如果是地址是:98H,即LCD的第二行的第一个位置显示)
hzkdis("测试程序");


}
/*------------------显示图片------------------------2005.11.14.21:20修改---benladn911---*/
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;
//RES=0;
//delay(100);
// RES=1;
     while(1)
     {
         RW=0;
           lcdreset();                                       //初始化LCD屏
           CGRAM();                                              
           ceshi();                                           //显示测试字样
         delay(1000);


      
           clrgdram();
         clrscreen();                                   //清屏
//         Disp_Img(BMP);                             //调入一幅图画
//           delay(10000);

         Disp_Img(BMP1);                             //调入一幅图画
           delay(10000);
     // while(1);                      
           //while(1);
          
                                        
         lcdfill(0xff);                             //显示全开
           delay(20000);                      
      
         Disp_H_Line();                               //显示横条
             delay(20000);
          
          
             lcdfill(0xaa);                             //显示竖条
           delay(20000);
        
           Frame();                                         //显示边框
           delay(20000);
          
         gushi_display();                         //显示唐诗
           clrgdram();
                    
         write_com(0x87);                   //调用自定义的CGRAM的代码
         write_data(0x00);
         write_data(0x00);
         delay(400);
          
           shuxian();                           //加入两条竖线
           delay(8000);
           write_com(0x30);
             delay(1000);
                        
           gushi_display();
           delay(6000);
           for(i=0;i<8;i++)               //字符循环左移
         {write_com(0x18);
               delay(20000);}
                  
             gushi_display();
           delay(6000);    
         write_com(0x36);              
           write_com(0x04);                   //第一行反白显示
           delay(20000);
           write_com(0x04);                   //第一行恢复正常
           delay(20000);
             write_com(0x05);                   //第二行反白显示
           delay(20000);
           write_com(0x05);                   //第二行恢复正常
           delay(20000);
                  
           write_com(0x03);                 //垂直滚动屏幕的内容
           write_com(0x60);
           delay(20000);
          
     }
}

  

我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!

网站导航 管理登陆 ┊ 免责声明 问题反馈  友链说明
本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正!
不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作!

    我要报警 Alexa
 mcusy_cn#126.com (请把#改成@) 交流:522422171
本站学习交流群:138..158(高级群1-)、77930286(高级群2)、61804809(群3)
Copyright© MCUSY All Rights Reserved
本站网警备案号: WZ36040002485
  ICP备案证书号:粤ICP备09034963号