//---------------------------------------------------------------------- /*EASTRISING TECHNOLOGY CO,.LTD.*/ // Module : ERM1602-5 SERIES // Lanuage : C51 Code // Create : JAVEN // Date : Dec-19-2018 // INTERFACE : 3LINE SPI // MCU : AT89C52 // VDD : 5V //---------------------------------------------------------------------- #include #include #define uchar unsigned char #define uint unsigned int sbit CS=P2^0; sbit SCL=P2^1; sbit SDA=P2^2; sbit PSB=P1^0; sbit RST=P1^1; bit log=0; sbit int0=P3^2; void LCD_initialize(void); void Write_CGRAM(uchar a[]); void Write_LCM(uchar dat); void Busy(void); void Delay(uint n); void Delay1(uint n); void Write_DDRAM(uchar a); void write_CGROM(uchar a); void shaw_character_string(uchar a[]); uchar code character_string[]= { "EastRisingTechnologyEastRisingTechnology" "EastRisingTechnologyEastRisingTechnology" }; uchar code font[]= { 0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00, 0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f, 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, 0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a, 0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02, //Äê 0x0f,0x09,0x0f,0x09,0x0f,0x09,0x09,0x13, //ÔÂ 0x1f,0x11,0x11,0x1f,0x11,0x11,0x11,0x1F, //ÈÕ 0x0C,0x0a,0x11,0x1f,0x09,0x09,0x09,0x13, //·Ö }; void Step(void) interrupt 0 using 0 { Delay1(500); if(int0==0) log=!log; while(!int0); return; } void Delay1(uint n) {while(n--); } void Delay(uint n) {while(n) { n--; } for(;log==1;) { } } void Write_LCM(uchar p) { unsigned char i; Delay1(50); CS = 0; SCL = 1; for(i=0;i<8;i++) { if (p&0x80) SDA = 1; else SDA = 0; SCL = 0; p = p<<1; SCL = 1; } CS = 1; } void Write_CGRAM(uchar a[]) {uchar i=64,k; Write_LCM(0x40); //CGRAM ADDRESS Delay1(40); Write_LCM(0x3c); //FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0xbf); //Set display data length 64 Delay1(40); for(k=0;k<64;k++) {Write_LCM(a[k]); } } void LCD_initialize(void) { PSB=0; RST=0; Delay1(10000); RST=1; Delay1(10000); Write_LCM(0x38);//FUNCTION SET#1, EXT=0 Delay1(40); Write_LCM(0x0c); //DISPLAY ON Delay(40); Write_LCM(0x01);//DISPLAY CLEAR Delay1(2000); Write_LCM(0x06);//ENTRY MODE SET Delay1(40); Write_CGRAM(font); } void Write_DDRAM(uchar a) {uchar j; Write_LCM(0x38);//FUNCTION SET#1, EXT=0 Delay1(40); Write_LCM(0x80);//1ST LINE ADDRESS Delay1(40); Write_LCM(0x3c); //FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0x8f);//Set display data length 16 Delay1(40); for(j=0;j<16;j++) {Write_LCM(a); } Write_LCM(0x38);//FUNCTION SET#1, EXT=0 Delay1(40); Write_LCM(0xc0);//2ST LINE ADDRESS Delay1(40); Write_LCM(0x3c); //FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0x8f);//Set display data length 16 Delay1(20); for(j=0;j<16;j++) {Write_LCM(a); } Delay(35000); Delay(65000); } void write_CGROM(uchar a) {uchar j; Write_LCM(0x38);//FUNCTION SET#1, EXT=0 Delay1(40); Write_LCM(0x80);//1ST LINE ADDRESS Delay1(40); Write_LCM(0x3c); //FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0x8f);//Set display data length 16 Delay1(40); for(j=0;j<16;j++) {Write_LCM(a);a+=1; } Write_LCM(0x38);//FUNCTION SET#1, EXT=0 Delay1(40); Write_LCM(0xc0);//2ST LINE ADDRESS Delay1(40); Write_LCM(0x3c);//FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0x8f);//Set display data length 16 Delay1(40); for(j=0;j<16;j++) {Write_LCM(a);a+=1; } Delay(35000); Delay(65000); } void shaw_character_string(uchar a[]) {uchar j; Write_LCM(0x38);//FUNCTION SET#1, EXT=0 Delay1(40); Write_LCM(0x80);//1ST LINE ADDRESS Delay1(40); Write_LCM(0x3c);//FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0x8f);//Set display data length 16 Delay1(20); for(j=0;j<16;j++) {Write_LCM(a[j]); } Write_LCM(0x38);//FUNCTION SET#1, EXT=0 Delay1(40); Write_LCM(0xc0);//2ST LINE ADDRESS Delay1(40); Write_LCM(0x3c);//FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0x8f);//Set display data length 16 Delay1(40); for(j=0;j<16;j++) {Write_LCM(a[j]); } Delay(35000); Delay(65000); } void main(void) { IE=0x81; IP=0x01; TCON=0x01; int0=1; P1=0xff; P2=0xff; Delay(50000); LCD_initialize(); while(1) { Write_LCM(0x3c);//FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0x40); //SEG,COM direction Delay1(40); Write_DDRAM(0xff); Write_LCM(0x01); Delay(35000); shaw_character_string(character_string); Write_DDRAM(0); Write_DDRAM(1); Write_DDRAM(2); Write_DDRAM(3); write_CGROM(0xA0); Write_DDRAM(4); Write_DDRAM(5); Write_DDRAM(6); Write_DDRAM(7); Write_LCM(0x3c);//FUNCTION SET#2, EXT=1 Delay1(40); Write_LCM(0x4F); //SEG,COM direction Delay1(40); Write_DDRAM(0xff); Write_LCM(0x01); Delay(35000); shaw_character_string(character_string); Write_DDRAM(0); Write_DDRAM(1); Write_DDRAM(2); Write_DDRAM(3); write_CGROM(0xA0); Write_DDRAM(4); Write_DDRAM(5); Write_DDRAM(6); Write_DDRAM(7); } }