//---------------------------------------------------------------------- /*EASTRISING TECHNOLOGY CO,.LTD.*/ // Module : ERM1602F7-6 or ERM1602DN7-6 with RGB backlight // Lanuage : C51 Code // Create : JAVEN // Date : May-23-2019 // Drive IC : KS0066/31066 // INTERFACE : 6800_8bit/4bit // MCU : AT89C52 12M // VDD : 5V //---------------------------------------------------------------------- #include #include #define uchar unsigned char #define uint unsigned int sbit BUSY=P1^7; sbit RS=P2^0; sbit R_W=P2^1; sbit E=P2^2; bit log=0; sbit int0=P3^2; sbit RED=P2^5; sbit GREEN=P2^4; sbit BLUE=P2^3; #define DATA_BUS P1 #define TIMING 8 //8: 8 bit data transmission 4: 4 bit data transmission void LCD_initialize(void); void Write_CGRAM(uchar a[]); void Write_Command(uchar cmd); void Write_Data(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[]= { "*buydisplay.com*" "EastRising tech" }; 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, //Year 0x0f,0x09,0x0f,0x09,0x0f,0x09,0x09,0x13, //Month 0x1f,0x11,0x11,0x1f,0x11,0x11,0x11,0x1F, //Day 0x0C,0x0a,0x11,0x1f,0x09,0x09,0x09,0x13, //minute }; 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 Busy(void) { RS=0;R_W=1; BUSY=1; E=1; while(BUSY); E=0; } //8-bit data bus #if (TIMING==8) void Write_Data(uchar dat) { Busy(); RS=1; R_W=0; DATA_BUS=dat; E=1; _nop_(); E=0; } #else //4-bit data bus void Write_Data(uchar dat) { Delay(20); // Busy(); RS=1; R_W=0; DATA_BUS=dat&0xf0; E=1; _nop_(); E=0; dat<<=4; DATA_BUS=dat&0xf0; E=1; _nop_(); E=0; } #endif //8-bit data bus #if (TIMING==8) void Write_Command(uchar cmd) { Busy(); RS=0; R_W=0; DATA_BUS=cmd; E=1; _nop_(); E=0; } //4-bit data bus #else void Write_Command(uchar cmd) { Delay(20); // Busy(); RS=0; R_W=0; DATA_BUS=cmd&0xf0; E=1; _nop_(); E=0; cmd<<=4; DATA_BUS=cmd&0xf0; E=1; _nop_(); E=0; } #endif void Write_CGRAM(uchar a[]) {uchar i=64,k; Write_Command(0x40); for(k=0;k<64;k++) {Write_Data(a[k]); } } void LCD_initialize(void) { if(TIMING==8) //8bit mcu interface { Write_Command(0x38); //Must be set to 2 lines Write_Command(0x38); //Must be set to 2 lines Write_Command(0x38); //Must be set to 2 lines } else //8bit mcu interface { Write_Command(0x28); //Must be set to 2 lines Write_Command(0x28); //Must be set to 2 lines Write_Command(0x28); //Must be set to 2 lines } //4bit mcu interface Write_Command(0x0c); //display on , cursor off , cursor blink off Write_Command(0x01); // clear display Delay(1000); Write_Command(0x06); // ddram address is increased by 1 Write_CGRAM(font); //writing font data to cgram } void Write_DDRAM(uchar a) {uchar j; Write_Command(0x02); Delay(1000); Write_Command(0x80); //1line start address is 0x80 for(j=0;j<16;j++) {Write_Data(a); } Write_Command(0xc0); //2line start address is 0xc0 for(j=0;j<16;j++) {Write_Data(a); } Delay(65000); Delay(65000); } void write_CGROM(uchar a) {uchar j; Write_Command(0x02); Delay(1000); Write_Command(0x80); //1line start address is 0x80 for(j=0;j<16;j++) {Write_Data(a); } Write_Command(0xc0); //2line start address is 0xc0 for(j=0;j<16;j++) {Write_Data(a);a+=1; } Delay(65000); Delay(65000); } void shaw_character_string(uchar a[]) {uchar j; Write_Command(0x02); Delay(1000); Write_Command(0x80); //1line start address is 0x80 for(j=0;j<16;j++) {Write_Data(a[j]); } Write_Command(0xc0); //2line start address is 0xc0 for(j=0;j<16;j++) {Write_Data(a[j]); } Delay(65000); Delay(65000); } void main(void) { IE=0x81; IP=0x01; TCON=0x01; int0=1; DATA_BUS=0xff; RED=1; GREEN=1; BLUE=1; Delay(20000); //wait fo more than 30ms after vdd rises to 4.5v LCD_initialize(); while(1) {Write_DDRAM(0xff); Write_Command(0x01); Delay(35000); RED=1; GREEN=0; BLUE=0; shaw_character_string(character_string); RED=0; GREEN=1; BLUE=0; Write_DDRAM(0); RED=0; GREEN=0; BLUE=1; Write_DDRAM(1); RED=1; GREEN=1; BLUE=1; Write_DDRAM(2); RED=0; GREEN=1; BLUE=1; Write_DDRAM(3); RED=1; GREEN=1; BLUE=0; write_CGROM(0x30); RED=1; GREEN=0; BLUE=1; Write_DDRAM(4); RED=1; GREEN=1; BLUE=1; Write_DDRAM(5); Write_DDRAM(6); Write_DDRAM(7); } }