独闷闷网

 找回密码
 立即注册
搜索
查看: 3012|回复: 0
打印 上一主题 下一主题
收起左侧

[原创] 两片选的19264液晶模块的C语言程序

[复制链接]
跳转到指定楼层
楼主
发表于 2013-12-30 23:33:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
//                19264  两个片选信号
//***************************************************************************
//连线表:  CPU=89C52
//RS=P3.0     R/W=P3.1     E=P3.2      DB0-DB7=P1.0-P1.7
//CSA=P3.3    CSB=P3.4     RES=P3.5
//SysClock=12MHz   
//***************************************************************************
//转自电子开发者论坛
#include <reg52.h>
#include <intrins.h>

#define        LcmXPixel 192        //横像素
#define        LcmYPixel 64        //纵像素

sbit        RS  =P3^0;        //数据指令
sbit        RW  =P3^1;        //读写
sbit        E   =P3^2;        //使能
sbit        CSA =P3^3;        //1片选
sbit        CSB =P3^4;        //2片选
sbit        RES =P3^5;        //复位

unsigned char Page;
unsigned char Col;

unsigned char code BMP1[];

void Delay(unsigned int MS);
void wtcom(void);


void Busy(unsigned char CSn)
{
        CSA = 1;        //先都置高
        CSB = 1;
        switch (CSn&0x0f)
        {
                case 1: {CSA=0;CSB=0;break;}
                case 2: {CSA=0;CSB=1;break;}
                case 3: {CSA=1;CSB=0;break;}
                default : {break;}
        }
        wtcom();
}
//转自电子开发者论坛
void wtcom(void)
{
        RS = 0;                //指令
        RW = 1;
        P1 = 0xFF;        //输出0xff以便读取正确
        E  = 1;
        _nop_();
        _nop_();
        while(P1 & 0x80);        //Status Read Bit7 = BUSY
        E  = 0;
        _nop_();
        _nop_();
        _nop_();
}

void Locatexy(void)
{
        unsigned char x,y;
       
        switch (Col&0xc0)        /*  col.and.0xC0        */
        {                        /*条件分支执行                */
                case 0:                {Busy(1);break;}/*左区        */
                case 0x40:        {Busy(2);break;}/*中区        */
                case 0x80:        {Busy(3);break;}/*右区        */
        }
       
        x = Col&0x3F|0x40;        /* col.and.0x3f.or.Set Y Address*/
        y = Page&0x07|0xB8;        /* row.and.0x07.or.set Page        */
        wtcom();                /* waitting for enable        */
        RS = 0;                        //指令
        RW = 0;                        //写
        P1 = y;                        //设置页面地址
        E  = 1;
        _nop_();
        _nop_();
        E  = 0;
        _nop_();
        _nop_();
        wtcom();                /*  waitting for enable        */
        RS = 0;
        RW = 0;
        P1 = x;                        //设置列地址
        E  = 1;
        _nop_();
        _nop_();
        E  = 0;
        _nop_();
        _nop_();
}


void WriteCommand( unsigned char CSn,unsigned char CommandByte )
{
        Busy(CSn);
        P1 = CommandByte;
        RS = 0;                //指令
        RW = 0;
        E  = 1;
        _nop_();
        _nop_();
        E  = 0;
        _nop_();
        _nop_();
}
//转自电子开发者论坛
unsigned char ReadData( void )
{
        unsigned char DataByte;
        Locatexy();
        RS = 1;       
        RW = 1;
        P1 = 0xFF;
        _nop_();
        _nop_();
        E  = 1;       
        DataByte = P1;
        E  = 0;
        _nop_();
        _nop_();
        return DataByte;
}


void WriteData( unsigned char DataByte )
{
        Locatexy();        /*坐标定位,返回时保留分区状态不变        */
        RS = 1;                /*数据输出*/
        RW = 0;                /*写输出  */
        P1 = DataByte;        /*数据输出到数据口 */
        E  = 1;                /*写入到LCM*/
        _nop_();
        _nop_();
        _nop_();
        E  = 0;
        _nop_();
        _nop_();
        _nop_();
}

void LcmClear( void )
{
        Page = 0;
        Col  = 0;
        for(Page=0age<(LcmYPixel/8)age++)
                for(Col=0;Col<LcmXPixel;Col++)
                        WriteData(0);
}

void LcmInit( void )
{
        WriteCommand(1,0x3f);        //开显示
        WriteCommand(2,0x3f);
        WriteCommand(3,0x3f);
       
        WriteCommand(1,0xc0);        //设置起始地址=0
        WriteCommand(2,0xc0);
        WriteCommand(3,0xc0);
       
        WriteCommand(1,0x3f);        //开显示
        WriteCommand(2,0x3f);
        WriteCommand(3,0x3f);
       
        Col = 0;
        Page= 0;
        Locatexy();
}

void LcmPutDots( unsigned char DotByte,unsigned char n )
{
        unsigned char i,j;
        Page = 0;
        Col  = 0;
        for(Page=0age<(LcmYPixel/8)age++)
        {
                Col=0;
                for(j=0;j<(LcmXPixel/n);j++)
                {
                        for(i=0;i<n;i++)
                        {
                                WriteData( DotByte );
                                Col++;
                        }
                        DotByte = ~DotByte;
                }
                if(n>=8) DotByte = ~DotByte;
               
        }
}

void LcmPutBMP( unsigned char *puts )
{
        unsigned int X=0;
        Page = 0;
        Col  = 0;
        for(Page=0age<(LcmYPixel/8)age++)
        {
                for(Col=0;Col<LcmXPixel;Col++)
                {
                        WriteData( puts[X] );
                        X++;
                }
        }
}
//转自电子开发者论坛
void LcmReverseBMP( void )
{
        unsigned char temp;
        Page = 0;
        Col  = 0;
        for(Page=0age<(LcmYPixel/8)age++)
        {
                for(Col=0;Col<LcmXPixel;Col++)
                {
                        temp = ReadData();
                        temp = ReadData();
                        temp = ~temp;
                        WriteData(temp);
                }
        }
}

void Delay(unsigned int MS)
{
        unsigned char us,usn;
        while(MS!=0)
        {
                usn = 2;        //for 12M
                while(usn!=0)
                {
                        us=0xf6;
                        while (us!=0){us--;};
                        usn--;
                }
                MS--;
        }
}
//转自电子开发者论坛
void Main( void )
{
        RES = 1;
        RES = 0;
        Delay(200);        //等待复位
        RES = 1;
        Delay(20);
        LcmInit();
        LcmClear();
        while(1)
        {
                LcmPutBMP(BMP1);
                Delay(1500);
                LcmReverseBMP();
                Delay(1500);
                LcmPutDots(0x55,1);
                Delay(1500);
                LcmPutDots(0xAA,1);
                Delay(1500);
                LcmPutDots(0xCC,2);
                Delay(1500);
                LcmPutDots(0x33,2);
                Delay(1500);
                LcmPutDots(0xF0,4);
                Delay(1500);
                LcmPutDots(0x0F,4);
                Delay(1500);
        }
}

unsigned char code BMP1[]={        //字节颠倒
/*--  宽度x高度=192x64  --*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xE0,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x60,0x40,0x00,0x80,0x80,
0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0x60,0x00,0x80,
0x80,0x80,0x80,0x80,0x80,0xE0,0xE0,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0xC0,0x40,0x40,0x40,0x40,0x40,0xC0,0xC0,0x40,0x40,0x40,0x40,
0x40,0x40,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x31,0x71,0xC1,0x81,0xF9,0x3F,
0x03,0x20,0x7C,0x1F,0x03,0x02,0xE2,0xE2,0x02,0x02,0x1A,0x3E,0x06,0x00,0x00,0x00,
0x00,0x20,0x20,0xE3,0xE3,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,
0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x60,0x78,0x1E,0xFF,0xFF,0x00,0x00,0x01,
0xF9,0xF9,0x19,0x19,0x19,0xFF,0xFF,0x19,0x19,0x19,0xF9,0xF9,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0x18,0x18,0x18,0x18,0x18,0xFF,0xFF,0x18,0x18,0x18,0x18,
0x18,0x18,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x0C,0xFE,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0xF8,0xFE,0x07,0x03,0x03,0x03,0x06,0xFE,0xF8,0x00,0x00,0x00,
0x38,0x3E,0x07,0x03,0x03,0x03,0x87,0xFE,0x7C,0x00,0x00,0x00,0xF0,0xFC,0xCE,0x63,
0x63,0x63,0xE7,0xCE,0x8C,0x00,0x00,0x00,0x00,0x80,0xC0,0xF0,0x3C,0x1E,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0x78,0x1F,0x07,0x0F,0x1C,
0x38,0x80,0xC0,0xE0,0x70,0x1F,0x07,0x1F,0x38,0x60,0xC0,0x80,0x80,0x00,0x00,0x00,
0x00,0x00,0x80,0xFF,0x7F,0xC0,0x80,0x88,0x9F,0x0C,0x0C,0x06,0x00,0x00,0x7F,0x00,
0x00,0x0C,0x0F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,
0x09,0x1D,0xB9,0xE1,0xE1,0xFF,0xC7,0x81,0x81,0x01,0x01,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0xE0,0xFF,0x0F,0x02,0x02,0x02,0x02,0x02,0xFF,0xFF,0x02,0x02,0x02,0x02,
0x02,0x02,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x31,0x73,0xE7,0xC6,0xC6,0xC6,0x73,0x3F,0x0F,0x00,0x00,0x00,
0xE0,0xF0,0xD8,0xCC,0xC6,0xC3,0xC1,0xC0,0xC0,0x00,0x00,0x00,0x0F,0x3F,0x60,0xC0,
0xC0,0xC0,0xE0,0x7F,0x1F,0x00,0x00,0x00,0x0E,0x0F,0x0F,0x0C,0x0C,0x0C,0xFF,0xFF,
0x0C,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x01,0x00,0x00,
0x00,0x03,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x02,
0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x03,0x03,0x03,0x00,0x00,0x00,
0x00,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,0x01,
0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,


};

乐于分享,勇于质疑!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|独闷闷网 ( 粤ICP备12007667号-2 )

GMT+8, 2024-4-24 11:24 , Processed in 0.350328 second(s), 18 queries .

快速回复 返回顶部 返回列表