//EDM12864B DRIVE//
/**************************************
PAGEADD为页地址起使
TIERADD为行地址起使
DIS_STARTADD为开始命令
CTABLE为汉字字库数组
ETABLE为英文字库数组
***************************************/
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define High 1
#define Low 0
#define _nop {}
#define PAGEADD 0xb8
#define TIERADD 0x40
#define DIS_STARADD 0xc0
uint key_value;
sbit DI=P1^4;
sbit E=P1^2;
sbit CS1=P1^1;
sbit CS2=P1^0;
sbit RW=P1^3;
sbit cs=P1^7;
sbit sclk=P1^6;
sbit dout=P1^5;
sbit I2C_SCL = P3^7;
sbit I2C_SDA = P3^6;
//uchar ntable[]={61,49,57,60,19,49,62,49,60,63,55,2,0,0,6,22,56,
//63,68,61,49,57,60,17,51,63,61};//email:analog2006@hotmail.com
uchar data voltage_display[8];
/*****************************
字符表
显示"Welcome Use"
******************************/
uchar code table1[]={
0x00,0x3e,0x51,0x49,0x45,0x3e,0x00,0x00,//0(0)
0x00,0x00,0x42,0x7f,0x40,0x00,0x00,0x00,//1
0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00,//2
0x00,0x21,0x41,0x45,0x4b,0x31,0x00,0x00,//3
0x00,0x18,0x14,0x12,0x7f,0x10,0x00,0x00,//4
0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00,//5
0x00,0x3c,0x4a,0x49,0x49,0x30,0x00,0x00,//6
0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00,//7
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,//8
0x00,0x06,0x49,0x49,0x29,0x1e,0x00,0x00,//9
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// (10)
0x00,0x00,0x00,0x47,0x00,0x00,0x00,0x00,//!
0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00,//%
0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00,//&
0x00,0x14,0x08,0x3e,0x08,0x14,0x00,0x00,//*
0x00,0x08,0x08,0x3e,0x08,0x08,0x00,0x00,//+
0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00,//-
0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,//.
0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00,///
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,//:(19)
0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00,//=
0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00,//?
0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00,//@(22)
0x00,0x7e,0x11,0x11,0x11,0x7f,0x00,0x00,//A
0x00,0x41,0x7f,0x49,0x49,0x36,0x00,0x00,//B
0x00,0x3e,0x41,0x41,0x41,0x22,0x00,0x00,//C
0x00,0x41,0x7f,0x41,0x41,0x3e,0x00,0x00,//D
0x00,0x7f,0x49,0x49,0x49,0x49,0x00,0x00,//E
0x00,0x7f,0x09,0x09,0x09,0x01,0x00,0x00,//F
0x00,0x3e,0x41,0x41,0x49,0x7a,0x00,0x00,//G(29)
0x00,0x7f,0x08,0x08,0x08,0x7f,0x00,0x00,//H
0x00,0x00,0x41,0x7f,0x41,0x00,0x00,0x00,//I
0x20,0x40,0x41,0x3f,0x01,0x01,0x00,0x00,//J
0x00,0x7f,0x08,0x14,0x22,0x41,0x00,0x00,//K
0x00,0x7f,0x40,0x40,0x40,0x40,0x00,0x00,//L
0x00,0x7f,0x02,0x0c,0x02,0x7f,0x00,0x00,//M
0x00,0x7f,0x06,0x08,0x30,0x7f,0x00,0x00,//N
0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00,//O
0x00,0x7f,0x09,0x09,0x09,0x06,0x00,0x00,//P
0x00,0x3e,0x41,0x51,0x21,0x5e,0x00,0x00,//Q(39)
0x00,0x7f,0x09,0x19,0x29,0x46,0x00,0x00,//R
0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,//S
0x00,0x01,0x01,0x7f,0x01,0x01,0x00,0x00,//T
0x00,0x3f,0x40,0x40,0x40,0x3f,0x00,0x00,//U
0x00,0x1f,0x20,0x41,0x20,0x1f,0x00,0x00,//V
0x00,0x7f,0x20,0x80,0x20,0x7f,0x00,0x00,//W
0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00,//X
0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00,//Y
0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00,//Z
0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00,//a(49)
0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00,//b
0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00,//c
0x00,0x38,0x44,0x44,0x48,0x7f,0x00,0x00,//d
0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00,//e
0x00,0x00,0x08,0x7e,0x09,0x02,0x00,0x00,//f
0x00,0x0c,0x52,0x52,0x4c,0x3e,0x00,0x00,//g
0x00,0x7f,0x08,0x04,0x04,0x78,0x00,0x00,//h
0x00,0x00,0x44,0x7d,0x40,0x00,0x00,0x00,//i
0x00,0x20,0x40,0x44,0x3d,0x00,0x00,0x00,//j
0x00,0x00,0x7f,0x10,0x28,0x44,0x00,0x00,//k(59)
0x00,0x00,0x41,0x7f,0x40,0x00,0x00,0x00,//l
0x00,0x7c,0x04,0x78,0x04,0x78,0x00,0x00,//m
0x00,0x7c,0x08,0x04,0x04,0x78,0x00,0x00,//n
0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,//o
0x00,0x7e,0x0c,0x12,0x12,0x0c,0x00,0x00,//p
0x00,0x0c,0x12,0x12,0x0c,0x7e,0x00,0x00,//q
0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00,//r
0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00,//s
0x00,0x04,0x3f,0x44,0x40,0x20,0x00,0x00,//t
0x00,0x3c,0x40,0x40,0x3c,0x40,0x00,0x00,//u(69)
0x00,0x1c,0x20,0x40,0x20,0x1c,0x00,0x00,//v
0x00,0x3c,0x40,0x30,0x40,0x3c,0x00,0x00,//w
0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,//x
0x00,0x1c,0xa0,0xa0,0x90,0x7c,0x00,0x00,//y
0x00,0x44,0x64,0x54,0x4c,0x44,0x00,0x00,//z(74)
};
/****************************
中文字符表
显示"欢迎使用液晶模块"
*****************************/
uchar code table2[]={
0x14,0x24,0x44,0x84,0x64,0x1c,0x20,0x18,
0x0f,0xe8,0x08,0x08,0x28,0x18,0x08,0x00,
0x20,0x10,0x4c,0x43,0x43,0x2c,0x20,0x10,
0x0c,0x03,0x06,0x18,0x30,0x60,0x20,0x00,//欢(0)
0x40,0x41,0xce,0x04,0x00,0xfc,0x04,0x02,
0x02,0xfc,0x04,0x04,0x04,0xfc,0x00,0x00,
0x40,0x20,0x1f,0x20,0x40,0x47,0x42,0x41,
0x40,0x5f,0x40,0x42,0x44,0x43,0x40,0x00,//迎(1)
0x40,0x20,0xf0,0x1c,0x07,0xf2,0x94,0x94,
0x94,0xff,0x94,0x94,0x94,0xf4,0x04,0x00,
0x00,0x00,0x7f,0x00,0x40,0x41,0x22,0x14,
0x0c,0x13,0x10,0x30,0x20,0x61,0x20,0x00,//使(2)
0x00,0x00,0x00,0xfe,0x22,0x22,0x22,0x22,
0xfe,0x22,0x22,0x22,0x22,0xfe,0x00,0x00,
0x80,0x40,0x30,0x0f,0x02,0x02,0x02,0x02,
0xff,0x02,0x02,0x42,0x82,0x7f,0x00,0x00,//用(3)
0x10,0x61,0x06,0xe0,0x18,0x84,0xe4,0x1c,
0x84,0x65,0xbe,0x24,0xa4,0x64,0x04,0x00,
0x04,0x04,0xff,0x00,0x01,0x00,0xff,0x41,
0x21,0x12,0x0c,0x1b,0x61,0xc0,0x40,0x00,//液(4)
0x00,0x00,0x00,0x00,0x7e,0x2a,0x2a,0x2a,
0x2a,0x2a,0x2a,0x7e,0x00,0x00,0x00,0x00,
0x00,0x7f,0x25,0x25,0x25,0x25,0x7f,0x00,
0x00,0x7f,0x25,0x25,0x25,0x25,0x7f,0x00,//晶(5)
0x10,0xd0,0xff,0x50,0x90,0x04,0xf4,0x54,
0x5f,0x54,0x54,0x5f,0xf4,0x04,0x00,0x00,
0x03,0x00,0xff,0x00,0x00,0x84,0x85,0x45,
0x35,0x0f,0x15,0x25,0x65,0xc4,0x44,0x00,//模(6)
0x10,0x10,0xff,0x10,0x10,0x00,0x08,0x08,
0xff,0x08,0x08,0x08,0xf8,0x00,0x00,0x00,
0x08,0x18,0x0f,0x04,0x85,0x41,0x31,0x0d,
0x03,0x05,0x09,0x11,0x31,0x61,0x21,0x00,//块(7)
0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,
0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,
0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,
0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,//电(8)
0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0x42,
0xFA,0x42,0x42,0x42,0x62,0x42,0x02,0x00,
0x20,0x18,0x27,0x20,0x20,0x20,0x20,0x20,
0x3F,0x20,0x21,0x2E,0x24,0x20,0x20,0x00,//压(9)
0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,
0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,
0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,
0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,//温(10)
0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,
0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,
0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,
0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,//度(11)
0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,
0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,
0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,
0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00,//测(12)
0x40,0x40,0x40,0xDF,0x55,0x55,0x55,0xD5,
0x55,0x55,0x55,0xDF,0x40,0x40,0x40,0x00,
0x40,0x40,0x40,0x57,0x55,0x55,0x55,0x7F,
0x55,0x55,0x55,0x57,0x50,0x40,0x40,0x00,//量(13)
};
/********************************
显示用的延时函数
延时长度有参数 n 决定
*********************************/
Delay_nms(uchar n)
{ uchar a;
for(;n>0;n--)
{
for(a=0;a<100;a++)
{
_nop;
_nop;
_nop;
_nop;
};
};
}
/*****************************************
DEM12864B状态检测,从EDM12864B读出数
据检测标志位BF
******************************************/
void LCD_Busy()
{
uchar busy;
E=Low;
DI=Low;
RW=High;
while(1)
{
E=High;
_nop;
_nop;
busy=P2;//读状态标志寄存器
_nop;
E=Low;
if((busy&0x90)==0)//检测BF和RES位,两者都为零时表示可进行写入
break;
};
}
/*********************************
写指令
**********************************/
void WRCommand_L(uchar command)
{
CS1=High;
CS2=Low;
LCD_Busy();
DI=Low;
_nop;
RW=Low;
_nop;
E=High;
_nop;
P2=command;
_nop;
E=Low;
_nop;
}
void WRCommand_R(uchar command)
{
CS1=Low;
CS2=High;
LCD_Busy();
DI=Low;