LCD没有放映, 请高手看下, Fosc = 12M ,
/******************************************************************************************/ /* filename : LCDDRV.C */ /* author : Steven */ /* description : lcd drive io initial, and drive functions */ /* LPC2131 connect with ST7565 */ /* D0 ~ D7 -------- P0.8 ~ P0.15 */ /* /CS1 -------- P0.4 */ /* RST -------- P0.5 */ /* D/I -------- P0.6 */ /* R/W -------- P0.7 */ /* Enable -------- P0.16 */ /* D/I : LOW - I , HIGH - D */ /* R/W : LOW - WR, HIGH - RD */ /******************************************************************************************/ #define CS1 4 #define CS1_LOW IO0CLR |= 1 << CS1; #define CS1_HIGH IO0SET |= 1 << CS1;
#define LCD_RST 5 #define LCD_RST_LOW IO0CLR |= 1 << LCD_RST #define LCD_RST_HIGH IO0SET |= 1 << LCD_RST
#define D_I 6 #define LCD_CMD IO0CLR |= 1 << D_I; #define LCD_DATA IO0SET |= 1 << D_I;
#define R_W 7 #define LCD_RD IO0CLR |= 1 << R_W; #define LCD_WR IO0SET |= 1 << R_W;
#define EN 16 #define LCD_EN IO0SET |= 1 << EN; #define LCD_DIS IO0CLR |= 1 << EN;
#define OutData( dat ) { IO0CLR |= 0xff << 8; Io0SET |= (dat & 0xff) << 8; }
/*********Lcd Cmd *****/ #define DisplayOff 0xAE #define DisplayOn 0xAF #define DisplayStart 0x40 #define PageAddr 0xB0 #define ColAddrHi 0x10 #define ColAddrLo 0x00 #define SegRemapOff 0xA0 #define SegRemapOn 0xA1 #define NormalDisp 0xA6 #define ReverseDisp 0xA7 #define SWReset 0xE2 #define ComRemapOff 0xC0 #define ComRemapOn 0xC8 #define IntRegRatio 0x20 #define ContCtrlReg 0x81 #define BoostLevel 0x86 #define R_Mod_W 0xE0 /*If enter Read-Modify-Write mode, the column will not increase automatically*/ #define End_R_Mod_W 0xEE /*End of Read-Modify-Write*/ #define ModOscFreq 0xA9 #define PwrCtrlReg 0x2A #define EntireDispOff 0xA4 #define IntVolBstrON 0x04 #define OPampBufferON 0x01
static void IoInitial( void ); static void LcdInitialCmd( void ); static void WriteLcdData( uint8 data ); static void WriteLcdCmd ( uint8 cmd ); void FullScreanBlack( void ); void clrscr( void ); void gotoxy(uint8 x, uint8 y ) void LcdInitial( void ) { IoInitial(); LcdInitialCmd(); clrscr(); FullScreanBlack( ); } static void IoInitial( void ) { PINSEL0 &= 0xf; PINSEL1 &= 0xfffffffc; IO0DIR |= 0x1fff0; } static void LcdInitialCmd( void ) { LcdReset(); WriteLcdCmd(BoostLevel); WriteLcdCmd(DisplayOff); WriteLcdCmd(SegRemapOn); WriteLcdCmd(ComRemapOn); WriteLcdCmd(IntRegRatio|0x04); WriteLcdCmd(PwrCtrlReg|IntVolBstrON|OPampBufferON); WriteLcdCmd(DisplayOn); WriteLcdCmd(DisplayStart); } void LcdReset() { LCD_RST_LOW; delay(500); LCD_RST_HIGH; } static void WriteLcdData( uint8 data ) { CS1_LOW; LCD_DATA; OutData(data); LCD_WR; LCD_EN; LCD_RD; LCD_DIS; CS1_HIGH;
} static void WriteLcdCmd ( uint8 cmd ) { CS1_LOW; LCD_CMD; LCD_WR; OutData(cmd); LCD_EN; LCD_RD; LCD_DIS; CS1_HIGH; } void clrscr( void ) { uint i, j; for( i = 0; i < 8 ; i++) for( j = 0; j < 128; j++) { gotoxy( i, j); WriteLcdData( 0x00 ); } } void FullScreanBlack( void ) { uint8 i, j; for( i = 0; i < 8 ; i++) for( j = 0; j < 128; j++) { gotoxy( i, j); WriteLcdData( 0xc6 ); } } void delay(uint32 i) { while( i-- > 0) ; } void gotoxy(uint8 x, uint8 y ) { uint8 i; x &= 0x0f; x |= PageAddr; WriteLcdCmd( x ); i = y; i = (i >> 4) & 0x0f; i |= ColAddrHi; WriteLcdCmd( i ); y &= 0x0f; y |= ColAddrLo; WriteLcdCmd( y ); } |