原创 240X128LCD Driver,还热乎着~

2008-9-16 23:04 2160 7 8 分类: MCU/ 嵌入式
240X128LCD Driver,还热乎着~


先看效果图:
20071111888102.jpg
200711118845774.jpg
再看部分源码:
头文件以及调试语句请自行修改。
//lcd.h
#ifndef _H_LCD_H_
#define _H_LCD_H_

#include "type.h"

#define CM240_128_DAT_ADDR 0X8000
#define CM240_128_CMD_ADDR 0Xc000

#define LCD_WR_DAT(dat) do{(*(UINT8*)CM240_128_DAT_ADDR)=dat;}while(0)
#define LCD_WR_CMD(cmd) do{(*(UINT8*)CM240_128_CMD_ADDR)=cmd;}while(0)
#define LCD_RD_DAT() (*(UINT8*)CM240_128_DAT_ADDR)
#define LCD_RD_CMD() (*(UINT8*)CM240_128_CMD_ADDR)

#define LCD_CMD_ADD_PT_SET 0X24
#define LCD_CMD_GRAPHIC_ADDR_SET 0X42
#define LCD_CMD_GRAPHIC_AREA_SET 0X43
#define LCD_CMD_MODE_SET_CGRAM 0X88
#define LCD_CMD_DISP_MODE_T_OFF_G_ON 0X98
#define LCD_CMD_DAT_WR_NO_ADP_ACTION 0XC4
#define LCD_CMD_DAT_RD_NO_ADP_ACTION 0XC5

#define LCD_CHECK_TIME_MAX_MS 100


UINT8 LcdWrDat(UINT8 dat);
UINT8 LcdWrCmdByZeroPara(UINT8 cmd);
UINT8 LcdWrCmdByOnePara(UINT8 cmd,UINT8 dat);
UINT8 LcdWrCmdByTwoPara(UINT8 cmd,UINT8 dat1,UINT8 dat2);
UINT8 LcdCheckCmdDatWrRd(void);


UINT8 LcdInit(void);
void LcdTest(void);

#endif

//lcd.cpp
#include "includes.h"

static const  prog_uchar wolf[]={//数据比较多,21IC限字数,见链接.
};
UINT8 LcdWrDat(UINT8 dat)
{
    if(LcdCheckCmdDatWrRd())
    {
        LCD_WR_DAT(dat);
        return 0xff;
    }
    else
        return 0x00;
}



UINT8 LcdWrCmdByZeroPara(UINT8 cmd)
{
    if(LcdCheckCmdDatWrRd())
    {
        LCD_WR_CMD(cmd);
        return 0xff;
    }
    else
        return 0x00;
}


UINT8 LcdWrCmdByOnePara(UINT8 cmd,UINT8 dat)
{
    if(LcdCheckCmdDatWrRd())
    {
        LCD_WR_DAT(dat);

        if(LcdCheckCmdDatWrRd())
        {
            LCD_WR_CMD(cmd);
            return 0xff;
        }
        else
        {
            return 0x00;
        }
    }
    else
    {
        return 0x00;
    }
}




UINT8 LcdWrCmdByTwoPara(UINT8 cmd,UINT8 dat1,UINT8 dat2)
{
    if(LcdCheckCmdDatWrRd())
    {
        LCD_WR_DAT(dat1);

        if(LcdCheckCmdDatWrRd())
        {
            LCD_WR_DAT(dat2);
            
            if(LcdCheckCmdDatWrRd())
            {
                LCD_WR_CMD(cmd);
                
                return 0xff;
            }
            else
            {
                return 0x00;
            }
        }
        else
        {
            return 0x00;
        }
    }
    else
    {
        return 0x00;
    }
}

UINT8 LcdCheckCmdDatWrRd(void)
{
    static UINT32 ct="0";

    while((LCD_RD_CMD()&0x03)!=0x03)
    {
        wdt_reset();
        ct++;
        if(ct>(UINT32)(LCD_CHECK_TIME_MAX_MS*1.0/(1000.0/SYSTEM_FREQUENCY_HZ)))
        {
            ct=0;
            return 0x00;
        }
    }

    ct=0;
    
    return 0xff;
}



UINT8 LcdInit(void)
{
    if(!LcdWrCmdByTwoPara(0x40, 0x00, 0x00))
        return 0x00;
    if(!LcdWrCmdByTwoPara(0x41, 0x1e, 0x00))
        return 0x00;
    if(!LcdWrCmdByTwoPara(LCD_CMD_GRAPHIC_ADDR_SET, 0x00, 0x00))
        return 0x00;
    if(!LcdWrCmdByTwoPara(LCD_CMD_GRAPHIC_AREA_SET, 0x1e, 0x00))
        return 0x00;
    if(!LcdWrCmdByZeroPara(0x80))// mode
        return 0x00;
    if(!LcdWrCmdByZeroPara(0xa4))
        return 0x00;
    if(!LcdWrCmdByZeroPara(0x98))
        return 0x00;
    return 0xff;
}

void LcdTest(void)
{
    UINT16 i;

    if(LcdInit())
    {
        WriteLog("lcd ok\r\n");
        for(i=0;i<30*128;i++)
        {
            wdt_reset();
            if(LcdWrCmdByTwoPara(LCD_CMD_ADD_PT_SET, i, (i)>>8))
            {
                if(!LcdWrCmdByOnePara(0xc4,pgm_read_byte(i+wolf)))
                {
                    WriteLog("E");
                }
                
            }
            else
            {
                WriteLog("e");
            }
            
        }
    }
    else
    {
        WriteLog("lcd error\r\n");
    }
}
点击下载源码
PARTNER CONTENT

文章评论1条评论)

登录后参与讨论

用户461316 2008-9-17 08:39

支持共享!!!
相关推荐阅读
用户1434095 2014-07-08 09:09
21QA百度关键词搜索排名跃居第一了~
有图有真相,感谢大家的支持~ ...
用户1434095 2010-10-16 18:37
LPC23XX之I2C使用总结
LPC23XX之I2C使用总结--- 原野之狼写于2010年重阳节之时 近来由于项目需要,玩了玩LPC23XX系列的I2C,这么一个小小的东西费了我一周的时间,实在是令人崩溃!首先要指出的是,原厂的L...
用户1434095 2009-12-08 01:21
十亿个掌声响起来
闲来无事,翻出硬盘整理资料,发现了收藏已久但一直没仔细看的邓丽君的演唱会《十亿个掌声》。邓丽君小姐英年早逝,但是却留下了这么经典的作品,她无愧为超级巨星,甜美的嗓音和完美的演唱技巧,带领人们走进真、善...
用户1434095 2009-03-12 19:31
漂泊四海 闯荡江湖
好久好久没有这么惬意了,住在十六层,明媚的阳光从窗户照进来,喝着茶,听着音乐。印象中,也就数高三那年的日子最开心了,完全放开了,考试啥的都统统见鬼去,要么跟一批死党们成天在教室门外狂侃海侃,要么是跟乐...
用户1434095 2008-10-28 22:10
PCI转并口 SJF 配置全过程
PCI转并口 SJF 配置全过程http://blog.chinaunix.net/u2/70540/showart_722069.html pci转并口卡+wiggler调试ARM的一点经验http...
用户1434095 2008-09-17 09:38
AVR单片机外部RAM访问
AVR单片机外部RAM访问<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />作者:原野...
EE直播间
更多
我要评论
1
7
关闭 站长推荐上一条 /3 下一条