/************************************************************** * +---------------------------------------------------+ * * | 液晶1602的汉字显示 | * * +---------------------------------------------------+ * * * * 此源码版权属 小牛 全权享有,如欲引用,敬请署名并告知 * * 严禁随意用于商业目的,违者必究,后果自负 * * Q Q:513696765 * * * * 运行环境:STC89C52单片机 12M晶振 * * 程序说明: * **************************************************************/ #include #include #define uchar unsigned char #define uint unsigned int sbit e=P2^7; sbit rs=P2^6; sbit rw=P2^5; sbit LCD7=P0^7; sbit LCD6=P0^6; sbit LCD5=P0^5; sbit LCD4=P0^4; uchar bdata lcdbuff; uint loop,x=30; sbit lcdbuff0=lcdbuff^0; sbit lcdbuff1=lcdbuff^1; sbit lcdbuff2=lcdbuff^2; sbit lcdbuff3=lcdbuff^3; sbit lcdbuff4=lcdbuff^4; sbit lcdbuff5=lcdbuff^5; sbit lcdbuff6=lcdbuff^6; sbit lcdbuff7=lcdbuff^7; /**************字模*****************/ unsigned char code tab[]={ /*-- 文字: 中 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x01,0x01,0x21,0x3F,0x21,0x21,0x21,0x21,0x21,0x3F,0x21,0x01,0x01,0x01,0x01,0x01, 0x00,0x00,0x08,0xFC,0x08,0x08,0x08,0x08,0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00, /*-- 文字: 国 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x7F,0x40,0x5F,0x41,0x41,0x41,0x4F,0x41,0x41,0x41,0x5F,0x40,0x40,0x7F,0x40, 0x00,0xFC,0x04,0xF4,0x04,0x04,0x04,0xE4,0x44,0x24,0x24,0xF4,0x04,0x04,0xFC,0x04, /*-- 文字: 电 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x01,0x01,0x01,0x3F,0x21,0x21,0x3F,0x21,0x21,0x21,0x3F,0x21,0x01,0x01,0x00,0x00, 0x00,0x00,0x00,0xF8,0x08,0x08,0xF8,0x08,0x08,0x08,0xF8,0x08,0x02,0x02,0xFE,0x00, /*-- 文字: 子 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x3F,0x00,0x00,0x00,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x01,0x01,0x05,0x02, 0x00,0xF0,0x20,0x40,0x80,0x00,0x00,0x04,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*-- 文字: 网 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0x7F,0x40,0x41,0x51,0x4A,0x44,0x44,0x4A,0x4A,0x51,0x61,0x40,0x40,0x40,0x00, 0x00,0xFC,0x04,0x04,0x14,0x9C,0x54,0x24,0x24,0x54,0x94,0x04,0x04,0x1C,0x08,0x00, }; /************函数声明***************/ void r_BF(); void w_cdata(void); void w_com(uchar com); void w_sting(uchar string); void init_lcd(); void cg_w(); void w_word(uchar word); void delay(uint xms); /************主函数*************/ void main() { init_lcd(); while(1) { w_com(0x01); //清屏 loop=0; cg_w(); w_com(0x80); w_word(0x00); w_word(0x00+2); w_word(0x00+4); w_com(0x80+0x40); w_word(0x00+1); w_word(0x00+3); w_word(0x00+5); delay(x); //************************************** w_com(0x01); //清屏 loop=32; cg_w(); w_com(0x80+0x03); w_word(0x00); w_word(0x00+2); w_word(0x00+4); w_com(0x80+0x43); w_word(0x00+1); w_word(0x00+3); w_word(0x00+5); delay(x); //***************************************** w_com(0x01); //清屏 loop=64; cg_w(); w_com(0x80+0x06); w_word(0x00); w_word(0x00+2); w_word(0x00+4); w_com(0x80+0x46); w_word(0x00+1); w_word(0x00+3); w_word(0x00+5); delay(x); //****************************************** w_com(0x01); //清屏 loop=96; cg_w(); w_com(0x80+0x09); w_word(0x00); w_word(0x00+2); w_word(0x00+4); w_com(0x80+0x49); w_word(0x00+1); w_word(0x00+3); w_word(0x00+5); delay(x); //******************************************* w_com(0x01); //清屏 loop=128; cg_w(); w_com(0x80+0x0c); w_word(0x00); w_word(0x00+2); w_word(0x00+4); w_com(0x80+0x4c); w_word(0x00+1); w_word(0x00+3); w_word(0x00+5); delay(x); } } //********************************** void delay(uint xms) { uint i,j; for(i=0;i>3; w_sting(temp); } else if((i>=16)&&(i<32)) { temp=(tab[i+loop-16]<<3)|(tab[i+loop]>>6); w_sting(temp); } else if((i>=32)&&(i<48)) { temp=(tab[i+loop-16])>>1; w_sting(temp); } else w_sting(tab[i+loop]); } } /***************显示写入******************/ /************函数说明********************* **把自己想要写入LCD屏幕的字符写入LCD显示** ******************************************/ void w_word(uchar word) { r_BF(); lcdbuff=word; rs=1; rw=0; w_cdata(); }