先看效果图:
再看部分源码: 头文件以及调试语句请自行修改。 //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
"); 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
"); } } 相关链接:https://bbs.21ic.com/upfiles/img/200711/200711118145351.rar |