/*********************************包含头文件********************************/ #include <reg51.h>
/********************************命令字定义*********************************/ #define Disp_On 0x3f #define Disp_Off 0x3e #define Col_Add 0x40 #define Page_Add 0xb8 #define Start_Line 0xc0
/*********************************端口定义**********************************/ sbit Mcs=P2^3; //左半屏使能,当MCS=1,左半屏显示 sbit Scs=P2^4; //右半屏使能,当SCS=1,右半屏显示 sbit Enable=P2^2; //使能 sbit Di=P2^0; //数据/命令选择(RS) sbit RW=P2^1; //读/写信号 sbit Rst=P2^5; //复位脚 sbit Light=P2^6; //背光脚
/**********************************字模表***********************************/ /*****************************www.hificat.com*******************************/ char code h[]={ /*-- 文字: h --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20, }; char code w[]={ /*-- 文字: w --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00, }; char code i[]={ /*-- 文字: i --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, }; char code f[]={ /*-- 文字: f --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, }; char code c[]={ /*-- 文字: c --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00, }; char code a[]={ /*-- 文字: a --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20, }; char code t[]={ /*-- 文字: t --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00, }; char code o[]={ /*-- 文字: o --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00, }; char code m[]={ /*-- 文字: m --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F, }; char code dian[]={ /*-- 文字: . --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00, }; /*************************************欢迎使用***********************************/ char code huan[]={ /*-- 文字: 欢 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 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, }; char code yun2[]={ /*-- 文字: 迎 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 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, }; char code shi[]={ /*-- 文字: 使 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 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, }; char code yong[]={ /*-- 文字: 用 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 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, };
/***********************************单片机开发板*********************************/ char code dan[]={ /*-- 文字: 单 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x00,0xF8,0x28,0x29,0x2E,0x2A,0xF8,0x28,0x2C,0x2B,0x2A,0xF8,0x00,0x00,0x00, 0x08,0x08,0x0B,0x09,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x09,0x0B,0x08,0x08,0x00, }; char code pian[]={ //*-- 文字: 片 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x00,0x00,0xFE,0x10,0x10,0x10,0x10,0x10,0x1F,0x10,0x10,0x10,0x18,0x10,0x00, 0x80,0x40,0x30,0x0F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,0x00,0x00,0x00,0x00, }; char code ji[]={ /*-- 文字: 机 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x08,0x08,0xC8,0xFF,0x48,0x88,0x08,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00, 0x04,0x03,0x00,0xFF,0x00,0x41,0x30,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x78,0x00, }; char code kai[]={ /*-- 文字: 开 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x40,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x00, 0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00, }; char code fa[]={ /*-- 文字: 发 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x10,0x3E,0x10,0x10,0xF0,0x9F,0x90,0x90,0x92,0x94,0x1C,0x10,0x10,0x10,0x00, 0x40,0x20,0x10,0x88,0x87,0x41,0x46,0x28,0x10,0x28,0x27,0x40,0xC0,0x40,0x00,0x00, }; char code ban[]={ /*-- 文字: 板 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x10,0x10,0xD0,0xFF,0x50,0x90,0x00,0xFE,0x62,0xA2,0x22,0x21,0xA1,0x61,0x00,0x00, 0x04,0x03,0x00,0x7F,0x00,0x11,0x0E,0x41,0x20,0x11,0x0A,0x0E,0x31,0x60,0x20,0x00, };
char code dang[]={ /*-- 文字: 当 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x00,0x40,0x42,0x5C,0x48,0x40,0x40,0x7F,0x40,0x50,0x4E,0x44,0xC0,0x00,0x00, 0x00,0x00,0x20,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x7F,0x00,0x00, };
char code qian[]={ /*-- 文字: 前 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x08,0x08,0xE8,0xA8,0xA9,0xAE,0xEA,0x08,0x08,0xC8,0x0C,0x0B,0xEA,0x08,0x08,0x00, 0x00,0x00,0x7F,0x04,0x24,0x44,0x3F,0x00,0x00,0x1F,0x40,0x80,0x7F,0x00,0x00,0x00, };
char code zhuang[]={ /*-- 文字: 状 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x08,0x30,0x00,0xFF,0x20,0x20,0x20,0x20,0xFF,0x20,0xE1,0x26,0x2C,0x20,0x20,0x00, 0x04,0x02,0x01,0xFF,0x40,0x20,0x18,0x07,0x00,0x00,0x03,0x0C,0x30,0x60,0x20,0x00, };
char code tai1[]={ /*-- 文字: 态 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x04,0x04,0x04,0x84,0x44,0x34,0x4F,0x94,0x24,0x44,0x84,0x84,0x04,0x00,0x00, 0x00,0x60,0x39,0x01,0x00,0x3C,0x40,0x42,0x4C,0x40,0x40,0x70,0x04,0x09,0x31,0x00, };
char code yun[]={ /*-- 文字: 运 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x40,0x41,0xCE,0x04,0x00,0x20,0x22,0xA2,0x62,0x22,0xA2,0x22,0x22,0x22,0x20,0x00, 0x40,0x20,0x1F,0x20,0x28,0x4C,0x4A,0x49,0x48,0x4C,0x44,0x45,0x5E,0x4C,0x40,0x00, };
char code xing[]={ /*-- 文字: 行 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x10,0x08,0x84,0xC6,0x73,0x22,0x40,0x44,0x44,0x44,0xC4,0x44,0x44,0x44,0x40,0x00, 0x02,0x01,0x00,0xFF,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00, };
char code zhong[]={ /*-- 文字: 中 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00, 0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00, };
char code maohao[]={ /*-- 文字: : --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, };
/**************************************************************************** 函数功能:延时程序 入口参数:t 出口参数: ****************************************************************************/ void delay(unsigned int t) { unsigned int i,j; for(i=0;i<t;i++) for(j=0;j<10;j++); }
/***************************************************************************** 函数功能:写命令到LCD程序 入口参数:cmdcode 出口参数: *****************************************************************************/ void write_com(unsigned char cmdcode) { Di=0; RW=0; P0=cmdcode; delay(2); Enable=1; delay(2); Enable=0; }
/***************************************************************************** 函数功能:写数据到LCD程序 入口参数:Dispdata 出口参数: *****************************************************************************/ void write_data(unsigned char Dispdata) { Di=1; RW=0; P0=Dispdata; delay(2); Enable=1; delay(2); Enable=0; }
/***************************************************************************** 函数功能:清除LCD内存程序 入口参数:pag,col,hzk 出口参数: *****************************************************************************/ void Clr_Scr() { unsigned char j,k; Mcs=1;Scs=1; write_com(Page_Add+0); write_com(Col_Add+0); for(k=0;k<8;k++) { write_com(Page_Add+k); for(j=0;j<64;j++)write_data(0x00); } Mcs=0;Scs=0; }
/***************************************************************************** 函数功能:指定位置显示数字16*16程序 入口参数:pag,col,hzk 出口参数: *****************************************************************************/ void hz_disp16(unsigned char pag,unsigned char col, unsigned char code *hzk) { unsigned char j=0,i=0; for(j=0;j<2;j++) { write_com(Page_Add+pag+j); write_com(Col_Add+col); for(i=0;i<16;i++) write_data(hzk[16*j+i]); } }
/***************************************************************************** 函数功能:指定位置显示数字8*16程序 入口参数:pag,col,hzk 出口参数: *****************************************************************************/ void hz_disp8(unsigned char pag,unsigned char col, unsigned char code *hzk) { unsigned char j=0,i=0; for(j=0;j<2;j++) { write_com(Page_Add+pag+j); write_com(Col_Add+col); for(i=0;i<8;i++) write_data(hzk[8*j+i]); } } /***************************************************************************** 函数功能:LCD初始化程序 入口参数: 出口参数: *****************************************************************************/ void init_lcd() { delay(100); Mcs=1; Scs=1; delay(100); write_com(Disp_Off); write_com(Page_Add+0); write_com(Start_Line+0); write_com(Col_Add+0); write_com(Disp_On); }
/***************************************************************************** 函数功能:主程序 入口参数: 出口参数: *****************************************************************************/ void main(void) { Light=0; //开LCD背光 init_lcd(); Clr_Scr(); Mcs=1;Scs=0; //左、右都显示 while(1) { Mcs=1;Scs=0; //左显示 delay(2); //欢迎 hz_disp16(0,32,huan); hz_disp16(0,48,yun2); //单片机 hz_disp16(2,16,dan); hz_disp16(2,32,pian); hz_disp16(2,48,ji); //当前状态 hz_disp16(4,0,dang); hz_disp16(4,16,qian); hz_disp16(4,32,zhuang); hz_disp16(4,48,tai1); //网址:www.hifi hz_disp8(6,0,w); hz_disp8(6,8,w); hz_disp8(6,16,w); hz_disp8(6,24,dian); hz_disp8(6,32,h); hz_disp8(6,40,i); hz_disp8(6,48,f); hz_disp8(6,56,i);
Mcs=0;Scs=1; //右显示 //使用 hz_disp16(0,0,shi); hz_disp16(0,16,yong); //开发板 hz_disp16(2,0,kai); hz_disp16(2,16,fa); hz_disp16(2,32,ban); //:运行中 hz_disp8(4,0,maohao); hz_disp16(4,8,yun); hz_disp16(4,24,xing); hz_disp16(4,40,zhong); //网址:cat.com hz_disp8(6,0,c); hz_disp8(6,8,a); hz_disp8(6,16,t); hz_disp8(6,24,dian); hz_disp8(6,32,c); hz_disp8(6,40,o); hz_disp8(6,48,m); delay(2); } }
|