LCD12864(ST7920)线路图
- /*-----------------------------------------------
- 名称:LCD12864 字库液晶 芯片组st7920
- 公司:
- 网站:
- 编写:
- 日期:
- 修改: Erics C.L. YOU
- 内容: 修改了显示数组IC_DAT为1 3 2 4顺序的bug
- 版本:
- ------------------------------------------------*/
- #include <stdio.h>
- #include <math.h>
- #include <reg52.h>
- #include <string.h>
- /******************************************************************/
- /* 定义数组 */
- /******************************************************************/
- unsigned char code IC_DAT[];
- unsigned char code IC_DAT2[];
- unsigned char code Photo1[];
- /******************************************************************/
- /* 定义接口信息 */
- /******************************************************************/
- sbit RS =P2^4;
- sbit WRD=P2^5;
- sbit E= P2^6;
- sbit PSB=P2^1;
- sbit RES=P2^3;
- /******************************************************************/
- /* 函数声明 */
- /******************************************************************/
- void TransferData(char data1,bit DI);
- void display(void);
- void display_grapic(void);
- void delayms(unsigned int n);
- void DisplayLine(unsigned char line1,unsigned char line2);
- void DisplayGraphic(unsigned char code *adder);
- void delay(unsigned int m);
- void lcd_mesg(unsigned char code *adder1);
- //显示的是1行 31行 21行 41行
- unsigned char code IC_DAT[]={
- "去年今日此门中,"
- "人面桃花相映红。"
- "人面不知何处去,"
- "桃花依旧笑春风。"
- };
- unsigned char code IC_DAT2[]={
- "人生若只如初见,"
- "何事秋风悲画扇。"
- "等闲变却故人心,"
- "却道故人心易变。"
- };
- /////////////////////////////////////////////////////////////////////////
- // Bitmap点阵数据表 //
- // 图片: E:\..\小猪减肥.bmp,横向取模左高位,数据排列:从左到右从上到下 //
- // 图片尺寸: 128 * 64 //
- /////////////////////////////////////////////////////////////////////////
- unsigned char code Photo1[] = // 数据表
- {
- 0x02,0x08,0x00,0x08,0x00,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0xD0,0x06,0x04,0x08,0x03,0x02,0x00,0x38,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x41,0x00,0x09,0x43,0x00,0x04,0xA1,0x80,0x41,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x42,0x00,0x29,0x00,0x00,0x14,0x80,0x00,0x8E,0x00,0xE7,0x00,0x00,0x00,0x00,0x00,
- 0x32,0x88,0x29,0x30,0x04,0x14,0x98,0x00,0x70,0x00,0x1C,0x80,0x00,0x00,0x00,0x00,
- 0x0C,0x00,0x16,0x48,0x00,0x0B,0x24,0x00,0x20,0x00,0x08,0x60,0x00,0x00,0x00,0x00,
- 0x00,0x20,0x4D,0x80,0x00,0x26,0xC0,0x00,0x40,0x00,0x08,0x10,0x00,0x00,0x00,0x00,
- 0x40,0x20,0x00,0x10,0x00,0x00,0x08,0x00,0x4C,0x00,0x08,0x10,0x00,0x00,0x00,0x00,
- 0x04,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x00,0x08,0x20,0x00,0x00,0x00,0x00,
- 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x08,0x09,0xC0,0x00,0x00,0x00,0x00,
- 0x18,0x10,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x40,0x00,0x00,0x00,0x00,
- 0x25,0x3F,0xC3,0xFE,0x3F,0xE0,0x00,0x01,0x10,0x04,0x00,0x40,0x00,0x00,0x00,0x00,
- 0xA4,0x08,0x40,0x20,0x00,0x41,0x80,0x01,0x10,0x00,0x00,0x20,0x00,0x00,0x00,0x00,
- 0xA4,0xC8,0x47,0xFF,0x00,0x83,0xC0,0x01,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,
- 0x59,0x28,0x40,0x20,0x03,0x03,0xC0,0x02,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,
- 0x36,0x08,0x81,0xFC,0x02,0x03,0xC0,0x02,0xF0,0x40,0x10,0x20,0x00,0x00,0x00,0x00,
- 0x00,0x44,0x81,0x24,0x02,0x01,0x80,0x05,0x0C,0x04,0x10,0x20,0x00,0x00,0x00,0x00,
- 0x00,0x05,0x01,0xFC,0x02,0x01,0x80,0x05,0x42,0x00,0x14,0x40,0x00,0x00,0x00,0x00,
- 0x00,0x02,0x01,0x24,0x02,0x00,0x00,0x05,0x51,0x00,0x1C,0x40,0x00,0x00,0x00,0x00,
- 0x00,0x05,0x03,0xFE,0x02,0x01,0x80,0x04,0x91,0x03,0xC0,0x40,0x00,0x00,0x00,0x00,
- 0x00,0x18,0xC0,0x20,0x02,0x01,0x80,0x04,0x61,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
- 0x02,0x60,0x37,0xFF,0x0E,0x00,0x00,0x04,0x1E,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
- 0x40,0x7F,0xF4,0x0A,0x3B,0xF3,0xFE,0x01,0x01,0xF0,0x01,0x00,0x00,0x00,0x00,0x00,
- 0x38,0x05,0x02,0x0A,0x2A,0x90,0x04,0x00,0xC7,0xF8,0x02,0x00,0x00,0x00,0x00,0x00,
- 0x04,0x3F,0xE2,0xFF,0x2A,0x90,0x08,0x00,0x70,0xF8,0x04,0x00,0x00,0x00,0x00,0x00,
- 0x20,0x25,0x20,0x88,0x3A,0x90,0x30,0x00,0xC7,0x00,0x08,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x3F,0xE2,0xF9,0x2B,0xF0,0x20,0x01,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x04,0x02,0x89,0x2A,0x00,0x20,0x02,0x20,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
- 0x41,0x7F,0xF4,0xFA,0x3A,0x00,0x20,0x04,0x48,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
- 0x18,0x08,0x84,0xD4,0x2A,0x00,0x20,0x08,0x80,0x08,0x00,0x80,0x00,0x00,0x00,0x00,
- 0x20,0x1D,0x05,0x75,0x2A,0x10,0x20,0x09,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
- 0x40,0x03,0x85,0x4B,0x4A,0x10,0x20,0x12,0x30,0x00,0x80,0x40,0x00,0x00,0x00,0x00,
- 0x50,0x7C,0x62,0x11,0x5B,0xF0,0xE0,0x13,0x8F,0xC0,0x80,0x20,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x78,0x3F,0x00,0x20,0x00,0x00,0x00,0x00,
- 0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x03,0xC0,0x80,0x20,0x00,0x00,0x00,0x00,
- 0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x00,0x0F,0x80,0x20,0x00,0x00,0x00,0x00,
- 0x84,0x80,0x00,0x1C,0x08,0x0E,0x04,0x28,0x00,0x00,0x40,0x20,0x00,0x00,0x00,0x00,
- 0x04,0x1C,0x08,0x22,0x00,0x11,0x00,0x18,0x00,0x00,0x20,0x20,0x00,0x00,0x00,0x00,
- 0x02,0x22,0x00,0x21,0x00,0x10,0x80,0x08,0x00,0x00,0x20,0x20,0x00,0x00,0x00,0x00,
- 0xA1,0xA1,0x00,0x24,0xE0,0x12,0x70,0x10,0x00,0x00,0x30,0x20,0x00,0x00,0x00,0x00,
- 0x80,0x24,0xE0,0x18,0x10,0x0C,0x08,0x10,0x00,0x00,0x28,0x20,0x00,0x00,0x00,0x00,
- 0x98,0x18,0x10,0x00,0x80,0x00,0x40,0x10,0x08,0x00,0x25,0xE0,0x00,0x00,0x00,0x00,
- 0x24,0x00,0x81,0x00,0x00,0x80,0x00,0x1A,0x08,0x00,0x22,0x20,0x00,0x00,0x00,0x00,
- 0xC1,0x00,0x00,0x00,0x00,0x00,0x00,0x1D,0x46,0x00,0x22,0xA0,0x00,0x00,0x00,0x00,
- 0x08,0x00,0x00,0x01,0x04,0x00,0x82,0x0F,0x93,0x40,0x21,0x40,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 initinal(void) //LCD字库初始化程序
- {
- delay(40); //大于40MS的延时程序
- PSB=1; //设置为8BIT并口工作模式
- delay(1); //延时
- RES=0; //复位
- delay(1); //延时
- RES=1; //复位置高
- delay(10);
- TransferData(0x30,0); //Extended Function Set :8BIT设置,RE=0: basic instruction set, G=0 :graphic display OFF
- delay(100); //大于100uS的延时程序
- TransferData(0x30,0); //Function Set
- delay(37); ////大于37uS的延时程序
- TransferData(0x08,0); //Display on Control
- delay(100); //大于100uS的延时程序
- TransferData(0x10,0); //Cursor Display Control光标设置
- delay(100); //大于100uS的延时程序
- TransferData(0x0C,0); //Display Control,D=1,显示开
- delay(100); //大于100uS的延时程序
- TransferData(0x01,0); //Display Clear
- delay(10); //大于10mS的延时程序
- TransferData(0x06,0); //Enry Mode Set,光标从右向左加1位移动
- delay(100); //大于100uS的延时程序
- }
- /******************************************************************/
- /* 液晶初始化-图形 */
- /******************************************************************/
- void initina2(void) //LCD显示图片(扩展)初始化程序
- {
- delay(40); //大于40MS的延时程序
- PSB=1; //设置为8BIT并口工作模式
- delay(1); //延时
- RES=0; //复位
- delay(1); //延时
- RES=1; //复位置高
- delay(10);
- TransferData(0x36,0); //Extended Function Set RE=1: extended instruction
- delay(100); //大于100uS的延时程序
- TransferData(0x36,0); //Extended Function Set:RE=1: extended instruction set
- delay(37); ////大于37uS的延时程序
- TransferData(0x3E,0); //EXFUNCTION(DL=8BITS,RE=1,G=1)
- delay(100); //大于100uS的延时程序
- TransferData(0x01,0); //CLEAR SCREEN
- delay(100); //大于100uS的延时程序
- }
- /******************************************************************/
- /* 主程序 */
- /******************************************************************/
- void main(void)
- {
- while(1)
- {
- //initina2(); //调用LCD显示图片(扩展)初始化程序
- // delayms(200);
- // DisplayGraphic(Photo1); //显示图片1
- // delayms(500);
- initinal(); //调用LCD字库初始化程序
- delay(100); //大于100uS的延时程序
- lcd_mesg(IC_DAT); //显示中文汉字1
- delayms(240);
- delayms(240);
-
- initinal(); //调用LCD字库初始化程序
- delay(100); //大于100uS的延时程序
- lcd_mesg(IC_DAT2); //显示中文汉字2
- delayms(240);
- delayms(240);
- }
- }
- /******************************************************************/
- /* 函数声明 */
- /******************************************************************/
- void lcd_mesg(unsigned char code *adder1)
- {
- unsigned char i;
- TransferData(0x80,0); //Set Graphic Display RAM Address
- delay(100);
- for(i=0;i<16;i++)
- {
- TransferData(*adder1,1);
- adder1++;
- }
- TransferData(0x90,0); //Set Graphic Display RAM Address
- delay(100);
- for(i=0;i<16;i++)
- {
- TransferData(*adder1,1);
- adder1++;
- }
- TransferData(0x88,0); //Set Graphic Display RAM Address
- delay(100);
- for(i=0;i<16;i++)
- {
- TransferData(*adder1,1);
- adder1++;
- }
- TransferData(0x98,0); //Set Graphic Display RAM Address
- delay(100);
- for(i=0;i<16;i++)
- {
- TransferData(*adder1,1);
- adder1++;
- }
-
- }
- /******************************************************************/
- /* 函数声明 */
- /******************************************************************/
- void TransferData(char data1,bit DI) //传送数据或者命令,当DI=0是,传送命令,当DI=1,传送数据.
- {
- WRD=0;
- RS=DI;
- delay(1);
- P0=data1;
- E=1;
- delay(1);
- E=0;
- }
- void delayms(unsigned int n) //延时10×n毫秒程序
- {
- unsigned int i,j;
- for(i=0;i<n;i++)
- for(j=0;j<2000;j++);
- }
- void delay(unsigned int m) //延时程序
- {
- unsigned int i,j;
- for(i=0;i<m;i++)
- for(j=0;j<10;j++);
- }
复制代码
http://www.51hei.com/bbs/dpj-50055-1.html
http://www.51hei.com/bbs/dpj-79329-1.html
|