//---------------------------------------------------------------------- /*EASTRISING TECHNOLOGY CO,.LTD.*/ // Module : ER-OLED1602-4 series // Lanuage : C51 Code // Create : JAVEN // Date : Aug-02-2014 // Drive IC : US2066 // INTERFACE : 8080_8-bit parallel interafce // MCU : AT89LV52 // VDD : 3V //---------------------------------------------------------------------- #include #include #define uchar unsigned char #define uint unsigned int sbit CS=P2^4; sbit RES=P2^3; sbit DC=P2^2; sbit _RW=P2^1; sbit _RD=P2^0; bit log=0; sbit int0=P3^2; #define DATA_BUS P1 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 show_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 Busy(void) { uchar flag=0xff; DC=0;CS=0;_RW=1;_RD=1; while ((flag&0x80)==0x80) { P1=0xff; _RD=0; _nop_(); flag=DATA_BUS; _RD=1; } CS=1; } void Write_Data(uchar dat) { Busy(); DC=1; CS=0; _RD=1; _RW=0; DATA_BUS=dat; _nop_(); _RW=1; CS=1; } void Write_Command(uchar cmd) { Busy(); DC=0; CS=0; _RD=1; _RW=0; DATA_BUS=cmd; _nop_(); _RW=1; CS=1; } 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) { RES=0; Delay(200); RES=1; Delay(200); Write_Command(0x2a); //RE=1 Write_Command(0x71); //Function Selection A Write_Data(0x00); //Disable internal VDD Write_Command(0x28); //RE=0,IS=0 Write_Command(0x08); //display OFF Write_Command(0x2a); //RE=1 Write_Command(0x79); //SD=1 OLED command set is enabled Write_Command(0xD5); //Set Display Clock Divide Ratio/ Oscillator Frequency Write_Command(0x70); Write_Command(0x78); //SD=0 OLED command set is disabled Write_Command(0x08); //5-dot font width, black/white inverting of cursor disable, 1-line or 2-line display mode Write_Command(0x06); //COM0 -> COM31 SEG99 -> SEG0, Write_Command(0x72); //Function Selection B. Select the character no. of character generator Select character ROM Write_Data(0x01); //CGRAOM 248 COGRAM 8 Select ROM A Write_Command(0x2a); //RE=1 Write_Command(0x79); //SD=1 OLED command set is enabled Write_Command(0xDA); //Set SEG Pins Hardware Configuration Write_Command(0x10); //Alternative (odd/even) SEG pin configuration, Disable SEG Left/Right remap Write_Command(0xDC); //Function Selection C Set VSL & GPIO Write_Command(0x00); //Internal VSL represents GPIO pin HiZ, input disabled (always read as low) Write_Command(0x81); //Set Contrast Control Write_Command(0x8F); Write_Command(0xD9); //Set Phase Length Write_Command(0xF1); Write_Command(0xDB); //Set VCOMH Deselect Level ( Write_Command(0x30); //0.83 x VCC Write_Command(0x78); //SD=0 OLED command set is disabled Write_Command(0x28); //RE=0,IS=0 Write_Command(0x01); //Clear Display Write_Command(0x80); //Set DDRAM Address Delay(1000); Write_Command(0x0C); //Display ON Write_CGRAM(font); } void Write_DDRAM(uchar a) {uchar j; Write_Command(0x02); Delay(1000); Write_Command(0x80); for(j=0;j<40;j++) {Write_Data(a); } Write_Command(0xc0); for(j=0;j<40;j++) {Write_Data(a); } Delay(35000); Delay(65000); } void show_character_string(uchar a[]) {uchar j; Write_Command(0x02); Delay(1000); Write_Command(0x80); for(j=0;j<40;j++) {Write_Data(a[j]); } Write_Command(0xc0); for(j=40;j<80;j++) {Write_Data(a[j]); } Delay(35000); Delay(65000); } void write_CGROM(uchar a) {uchar j; Write_Command(0x02); Delay(1000); Write_Command(0x80); for(j=0;j<40;j++) {Write_Data(a);a+=1; } Write_Command(0xc0); for(j=0;j<40;j++) {Write_Data(a);a+=1; } Delay(35000); Delay(65000); } void main(void) {uchar a=0x81; IE=0x81; IP=0x01; TCON=0x01; int0=1; DATA_BUS=0xff; P2=0xff; Delay(1000); LCD_initialize(); while(1) {Write_DDRAM(0x1f); show_character_string(character_string); Write_DDRAM(0); Write_DDRAM(1); Write_DDRAM(2); Write_DDRAM(3); Write_DDRAM(4); Write_DDRAM(5); Write_DDRAM(6); Write_DDRAM(7); write_CGROM(0x30); } }