这几天一直在用周工的EASYARM2131调这块液晶,代码是原来在51用过的,移植上来的,感觉上没什么问题,用示波器测试电平也很好,液晶没有问题,在51上调出来正常,是ARM上的驱动电流不够,还是程序有问题,搞了好几天都没有结果,请高人指点,以下为我的代码。 #include "config.h"
#ifndef __LCD12864_H #define __LCD12864_H
#define LCD_DI 1 << 8 #define LCD_RW 1 << 9 #define LCD_E 1 << 10 #define LCD_CSA 1 << 11 #define LCD_CSB 1 << 12 #define LCD_RST 1 << 13 #define LCD_BUSY 0x00000080 #define LCD_DAT 0xff
#define LCD_ALL_DIR() IO0DIR = IO0DIR | (LCD_DI | LCD_RW | LCD_E | LCD_CSA | LCD_CSB | LCD_RST)
#define LCD_ALL_CLR() IO0CLR = 0x00003fff
#define DI_H() IO0SET = LCD_DI #define DI_L() IO0CLR = LCD_DI #define RW_H() IO0SET = LCD_RW #define RW_L() IO0CLR = LCD_RW #define E_H() IO0SET = LCD_E #define E_L() IO0CLR = LCD_E #define CSA_H() IO0SET = LCD_CSA #define CSA_L() IO0CLR = LCD_CSA #define CSB_H() IO0SET = LCD_CSB #define CSB_L() IO0CLR = LCD_CSB #define RST_H() IO0SET = LCD_RST #define RST_L() IO0CLR = LCD_RST extern void LCD_Init(void); extern void LCD_CLR(uint8 dat); extern void LCD_Delay(uint32 dly); extern void SendData(uint8 data); extern void Write_Cmd_L(uint8 cmd); extern void Write_Cmd_R(uint8 cmd); extern void Write_Dat_L(uint8 dat); extern void Write_Dat_R(uint8 dat); extern void write_data(uint8 xpos,uint8 ypos,uint8 lcddata); extern void lcd_putchar8x8( uint8 x,uint8 y,uint8 ch );
#endif #include "config.h" #include "zifu8_8.h"
/*********LCD初始化*****************/ void LCD_Init(void) { uint32 i; PINSEL0=0x00000000; LCD_ALL_DIR(); LCD_ALL_CLR(); RST_L(); for(i=0; i<10000; i++); RST_H(); for(i=0; i<10000; i++); CSA_H(); CSB_H(); LCD_Delay(30); Write_Cmd_L(0x3e); //关显示 Write_Cmd_R(0x3e); Write_Cmd_L(0xc0); //起始行 Write_Cmd_R(0xc0); Write_Cmd_L(0x3f); //开显示 Write_Cmd_R(0x3f); LCD_CLR(0x00); LCD_Delay(2000); } /***********************************/ /***********************************/ void LCD_CLR(uint8 dat) { uint8 i,j,page; for( i = 0; i < 8; i++ ) { page = i; page |= 0xb8; Write_Cmd_L( page ); LCD_Delay(10); Write_Cmd_L( 0x40 ); for( j = 0; j < 64; j++ ){ Write_Dat_L(dat); LCD_Delay(10);} Write_Cmd_R( page ); LCD_Delay(10); Write_Cmd_R( 0x40 ); for( j = 0; j < 64; j++ ){ Write_Dat_R(dat); LCD_Delay(10);} } }
/***********************************/
/***********延时********************/ void LCD_Delay(uint32 dly) { uint16 i; for(i=0;i<dly;i++); } /***********************************/
/**********命令数据写出**************/ void SendData(uint8 dat) { IO0CLR = 0xff; //先清零,在送数据 IO0SET = dat&0xff; } /***********************************/
/**********写左命令*****************/ void Write_Cmd_L(uint8 cmd) { uint32 bak; CSB_H(); CSA_L(); RW_H(); DI_L(); IO0DIR = 0x00003f00 ; LCD_Delay(10); do{ E_H(); LCD_Delay(100); bak = IO0PIN; E_L(); }while(bak&LCD_BUSY); IO0DIR = 0x00003fff; LCD_Delay(10); RW_L(); LCD_Delay(10); SendData(cmd); LCD_Delay(100); E_H(); LCD_Delay(100); E_L(); } /************************************/
/**********写右命令*****************/ void Write_Cmd_R(uint8 cmd) { uint32 bak; CSB_L(); CSA_H(); RW_H(); DI_L(); IO0DIR = 0x00003f00 ;//定义数据口为输入方式 LCD_Delay(10); do{ E_H(); LCD_Delay(100); bak = IO0PIN; E_L(); }while(bak&LCD_BUSY); IO0DIR = 0x00003fff;//定义数据口为输出方式 LCD_Delay(10); RW_L(); LCD_Delay(10); SendData(cmd); LCD_Delay(100); E_H(); LCD_Delay(100); E_L(); } /************************************/
/**********写左数据*****************/ void Write_Dat_L(uint8 dat) { uint32 bak; CSB_H(); CSA_L(); RW_H(); DI_L(); IO0DIR = 0x00003f00 ; LCD_Delay(10); do{ E_H(); LCD_Delay(100); bak = IO0PIN; E_L(); }while(bak&LCD_BUSY); IO0DIR = 0x00003fff ; LCD_Delay(10); DI_H(); LCD_Delay(10); RW_L(); LCD_Delay(10); SendData(dat); RW_H(); E_H(); LCD_Delay(100); E_L(); } /************************************/
/**********写右数据*****************/ void Write_Dat_R(uint8 dat) { uint32 bak; CSB_L(); CSA_H(); RW_H(); DI_L(); IO0DIR = 0x00003f00 ; LCD_Delay(10); do{ E_H(); LCD_Delay(100); bak = IO0PIN; E_L(); }while(bak&LCD_BUSY); IO0DIR = 0x00003fff ; LCD_Delay(10); DI_H(); LCD_Delay(10); RW_L(); LCD_Delay(10); SendData(dat); LCD_Delay(100); E_H(); LCD_Delay(100); E_L(); } /************************************/
/************写数据*****************/ void write_data(uint8 xpos,uint8 ypos,uint8 lcddata) { if(xpos<128) { if( ( xpos & 0xc0 )== 0 ) { Write_Cmd_L( 0xb8 | ypos ); //写页命令 LCD_Delay(10); Write_Cmd_L( 0x40 | xpos); //写行命令 LCD_Delay(10); Write_Dat_L( lcddata ); //写左边数据 LCD_Delay(10); } else if( ( xpos & 0xc0 )== 0x40 ) { Write_Cmd_R( 0xb8 | ypos ); LCD_Delay(10); Write_Cmd_R( 0x40 | xpos ); LCD_Delay(10); Write_Dat_R( lcddata ); LCD_Delay(10); } } } /************************************/ /************显示一个字符************/ void lcd_putchar8x8( uint8 x,uint8 y,uint8 ch ) { uint8 i; for( i = 0; i < 8; i ++ ) { write_data( x+i, y, zifu[(ch - 0x20)*8 + i] ); LCD_Delay(10); } }
|