128*64液晶显示器

 

 

以数据并行的方式在DDRAM中实现基本的文本输出

#include <reg52.h>
#include <intrins.h>

#define NOP() _nop_()

#define uchar unsigned char
#define uint unsigned int
           
uchar code table0[] = "welcome zcmaker";
uchar code table1[] = "我愿意这条情路";
uchar code table2[] = "我会送你红色玫瑰";
uchar code table3[] = "未来有你梦才会完美";

sbit du = P2^6;
sbit we = P2^7;
                                                                   
sbit LCDRS = P3^5;
sbit LCDRW = P3^6;
sbit LCDEN = P3^4;
sbit LCDPSB = P3^7;

void delayNms(uchar ms);
void init();
void writeCmd(uchar cmd);
void writeData(uchar dat);
uchar readState();

void main()
{
    uint i = 0;
    init();
    
    /*注意点设定 与 游标或显示移位控制的区别:
    当设定了点设定的内容时,写入的每一个内容都会 
    按照这个设定方式移动,而游标或显示移位控制只在
    写入一条命令时移动一次
    */

/*****以下 实现了行屏幕左移动***************/
/*    writeCmd(0x07);//点设顶,画面左移
    writeCmd(0x87);    
    while(table0[i] != '\0')
    {                                         
        writeData(table0[i++]);
        delayNms(500);
    }*/
/******************************************/
             
/*********检测DDRAM的地址为0xa0之后能否显示,结果是不能,数据没有存入到DDRAM中*******/
/*    writeCmd(0x9f);
    writeData('1');
    delayNms(500);
    writeCmd(0x18);*/
/**************************************************************/

/**************游标或显示移位设定*****************************/
    /*while(table0[i++] != '\0')
    {
        writeCmd(0x18);
        delayNms(500);
    }*/
/*********************************************************/
       while(1);
}

void delayNms(uchar ms)
{
    uchar i;
    while(ms--)
    {
        for(i = 105; i>0; i--)
            NOP();
    }        
}

void init()
{
    we = 0;
    du = 0;

    LCDPSB = 1;
    writeCmd(0x30);//功能设定,基本指令集
    delayNms(1);
    writeCmd(0x30);//这里为什么又多了个功能设定
    delayNms(1);
    writeCmd(0x0f);//显示开,游标开,游标位置开
    delayNms(1);
    writeCmd(0x01);//清频
    delayNms(0x015);
    writeCmd(0x06);//游标右移 ,整体显示不动

}
void writeCmd(uchar cmd)
{
    LCDEN = 0;
    while((readState() & 0x80) !=0);  //判忙
    LCDRS = 0;
    LCDRW = 0;
    NOP();
    LCDEN = 1;
    P0 = cmd;
    NOP();
    NOP();
    LCDEN = 0;
}

void writeData(uchar dat)
{
    LCDEN = 0;
    while((readState() & 0x80) !=0);
    LCDRS = 1;
    LCDRW = 0;
    NOP();
    LCDEN = 1;
    P0 = dat;
    NOP();
    NOP();
    LCDEN = 0;

}
uchar readState()
{
    uchar dat;
    LCDEN = 0;
    LCDRS = 0;
    LCDRW = 1;
    NOP();
    LCDEN = 1;
    dat = P0;
    NOP();
    NOP();
    LCDEN = 0;
    return dat;
}

 

在液晶上面实现了绘图的功能

#include <reg52.h>
#include <intrins.h>

#define NOP() _nop_()

#define uchar unsigned char
const uchar code fill[] = {"                "};
const uchar code table0[] = {"欢迎来到"};
const uchar code table1[] = {"   zcmaker's lab"};
const uchar code table2[] = {"谢谢观看"};           
const uchar code qq[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,
0x00,0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x7F,0x80,0x00,0x00,
0x00,0x03,0xFF,0xFF,0xFE,0x00,0x00,0x01,0xFF,0xE0,0x00,0x01,0xFF,0xE0,0x00,0x00,
0x00,0x07,0xFF,0xFF,0xFE,0x00,0x00,0x07,0xFF,0xF0,0x00,0x07,0xFF,0xF0,0x00,0x00,
0x00,0x0F,0xF9,0xFD,0xFF,0x00,0x00,0x0F,0xFF,0xF8,0x00,0x0F,0xFF,0xF8,0x00,0x00,
0x00,0x0F,0xF0,0xF0,0xFF,0x80,0x00,0x1F,0xFF,0xFC,0x00,0x1F,0xFF,0xFC,0x00,0x00,
0x00,0x1F,0xF0,0x70,0x7F,0x80,0x00,0x3F,0xFF,0xFC,0x00,0x3F,0xFF,0xFC,0x00,0x00,
0x00,0x1F,0xE1,0x70,0x7F,0x80,0x00,0x7F,0xFF,0xFE,0x00,0x7F,0xFF,0xFE,0x00,0x00,
0x00,0x3F,0xE1,0x66,0x7F,0xC0,0x00,0xFF,0xFF,0xFE,0x00,0xFF,0xFF,0xFE,0x00,0x00,
0x00,0x3F,0xE3,0xE0,0x7F,0xC0,0x01,0xFF,0xFF,0xFE,0x01,0xFF,0xFF,0xFE,0x00,0x00,
0x00,0x3F,0xE0,0x60,0x7F,0xE0,0x01,0xFF,0xEF,0xFF,0x01,0xFF,0xEF,0xFF,0x00,0x00,
0x00,0x7F,0xF0,0xF0,0x7F,0xC0,0x03,0xFF,0x87,0xFF,0x03,0xFF,0x87,0xFF,0x00,0x00,
0x00,0x3F,0xF0,0xF8,0xFF,0xE0,0x03,0xFF,0x83,0xFF,0x83,0xFF,0x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FF,0xFF,0x00,0x21,0xFF,0xFF,0x00,0x20,0x00,
0x3F,0x87,0xF0,0x00,0x00,0x3F,0x00,0xFF,0xFF,0x00,0x40,0xFF,0xFF,0x00,0x40,0x00,
0x7F,0x83,0xF8,0x00,0x00,0x3F,0x00,0x1F,0xFF,0x80,0x40,0x1F,0xFF,0xC0,0xC0,0x00,
0x7F,0x87,0xF0,0x00,0x00,0x3F,0x00,0x00,0x00,0xC1,0x80,0x00,0x00,0xE3,0x80,0x00,
0x7F,0xC3,0xF8,0x00,0x00,0x3F,0x80,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,
0x7B,0x83,0xF0,0x00,0x00,0x3F,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x1C,0x00,0x00,
0x79,0xC1,0xF0,0x00,0x00,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x21,0xC0,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xE0,0x00,0x00,0x00,0x40,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0xE0,0x00,0x00,0x00,0xC0,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x30,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x38,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x9C,0x00,0x00,0x06,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x07,0x00,0x00,0x0C,0x60,0x07,0xF8,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x70,
0x01,0x81,0xC0,0x00,0x38,0x10,0x03,0x30,0x00,0x00,0x00,0x03,0x60,0x00,0x00,0x30,
0x01,0x00,0xF8,0x00,0xE0,0x10,0x03,0x30,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x30,
0x01,0x00,0x03,0xAD,0x00,0x10,0x01,0xE1,0xE3,0xF7,0xF8,0x06,0x01,0xE1,0xE1,0xF0,
0x00,0xA0,0x0B,0x0E,0xA2,0xA0,0x01,0xE3,0x31,0xC3,0x30,0x06,0x03,0x33,0x33,0x30,
0x00,0x00,0x54,0x00,0x00,0x00,0x01,0xE3,0xF1,0x81,0xE0,0x06,0xF3,0x33,0x33,0x30,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE3,0x01,0x81,0xE0,0x06,0x63,0x33,0x33,0x30,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC3,0x31,0x80,0xC0,0x03,0x63,0x33,0x33,0x30,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xE3,0xE0,0xC0,0x01,0xC1,0xE1,0xE1,0xF8,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

sbit du = P2^6;
sbit we = P2^7;
                                                                   
sbit LCDRS = P3^5;
sbit LCDRW = P3^6;
sbit LCDEN = P3^4;
sbit LCDPSB = P3^7;

void delayNms(uchar ms);
void init();
void writeCmd(uchar cmd);
void writeData(uchar dat);
uchar readState();

void funcTest();
void clearGDRAM();
void drawPic(uchar *dat);
void writeChar(uchar loc, uchar *dat);

void main()
{
    init();
    writeCmd(0x0c);//光标不显示
    
    writeChar(0x80, table0);
    delayNms(500);
    writeChar(0x90, table1);
    delayNms(500);
//    writeCmd(0x01);//清空DDRAM ,这句话导致图片显示的句子不正确,想不到是什么原因
/**************一下4句话作为代替,清空DDRAM中的内容********************/
    writeChar(0x80, fill);
    writeChar(0x88, fill);
    writeChar(0x90, fill);
    writeChar(0x98, fill);
/***********************************************************************/
    drawPic(qq);
    delayNms(500);
    clearGDRAM();
    writeChar(0x88, table2);
    delayNms(500);
    writeCmd(0x01);
    /*writeCmd(0x01);
    drawPic(qq);
    delayNms(500);
    delayNms(500);
    delayNms(500);
    writeCmd(0x01);*/
       while(1);
}

void delayNms(uchar ms)
{
    uchar i;
    while(ms--)
    {
        for(i = 105; i>0; i--)
            NOP();
    }        
}

void init()
{
    we = 0;
    du = 0;

    LCDPSB = 1;
    writeCmd(0x30);//功能设定,基本指令集
    delayNms(1);
    writeCmd(0x30);//这里为什么又多了个功能设定
    delayNms(1);
    writeCmd(0x0f);//显示开,游标开,游标位置开
    delayNms(1);
    writeCmd(0x01);//清频
    delayNms(0x015);
    writeCmd(0x06);//游标右移 ,整体显示不动

}
void writeCmd(uchar cmd)
{
    LCDEN = 0;
    while((readState() & 0x80) !=0);  //判忙
    LCDRS = 0;
    LCDRW = 0;
    NOP();    
    LCDEN = 1;
    P0 = cmd;
    NOP();
    NOP();
    LCDEN = 0;
}

void writeData(uchar dat)
{
    LCDEN = 0;
    while((readState() & 0x80) !=0);
    LCDRS = 1;
    LCDRW = 0;
    NOP();
    LCDEN = 1;
    P0 = dat;
    NOP();
    NOP();
    LCDEN = 0;

}
uchar readState()
{
    uchar dat;
    LCDEN = 0;
    LCDRS = 0;
    LCDRW = 1;
    NOP();
    LCDEN = 1;
    dat = P0;
    NOP();
    NOP();
    LCDEN = 0;
    return dat;
}

void clearGDRAM()
{
    uchar i, j, k;
    writeCmd(0x34);//进入扩展指令集    就可以对GDRAM中的数据进行设定
    k = 0x80;
    for(i = 0; i < 32; i++)
    {
        writeCmd(k++);//注意
        writeCmd(0x80);
        for(j = 0; j < 16; j++ )
        {
            writeData(0);
            writeData(0);
        }
    }
    writeCmd(0x30);//回到基本指令集
}
void drawPic(uchar *dat)
{
    uchar i, j;
    writeCmd(0x34);//进入扩展指令集    就可以对GDRAM中的数据进行设定
    for(i = 0; i < 32; i++)
    {
        writeCmd(0x80 + i);//注意
        writeCmd(0x80);
        for(j = 0; j < 8; j++ )
        {
            writeData(*dat++);
            writeData(*dat++);
        }
    }
                                    
    for( i = 0; i< 32; i++)
    {
        writeCmd(0x80 + i);
        writeCmd(0x88);
        for(j = 0; j< 8; j++)
        {
            writeData(*dat++);
            writeData(*dat++);
        }
    }
    writeCmd(0x36);
    writeCmd(0x30);//回到基本指令集        
}
void funcTest()
{
    writeCmd(0x34);//进入 补充指令集,不开绘图功能
//    writeCmd(0x04);//1 3反白
//    writeCmd(0x01);//进入待命模式
//    writeCmd(0x08);//睡眠模式    
}

void writeChar(uchar loc, uchar *dat)
{
    uchar i = 0;
    writeCmd(loc);
    while(dat[i] != '\0')
    {                                         
        writeData(dat[i++]);      
    }    
}
posted on 2012-11-23 15:15  WithYouTh  阅读(463)  评论(0编辑  收藏  举报