//============================================================= // WINSTAR Display Co.,Ltd // LCM :WO12864 // Contraller: ST7565 // Author :Brian lin 2008/01/05 // history : //============================================================== #include "reg52.h" // define 8051 registers #include typedef unsigned char UB8; /* 8-bit data */ //============================================ #define LCM_PORT P1 //DB0~DB7,DATA BUS sbit LCM_RS = P3^0; sbit LCM_RW = P3^7; sbit LCM_ENABLE = P3^4; sbit LCM_CS1 = P3^1; sbit LCM_PS1 = P3^6; sbit LCM_RESET = P3^2; sbit LCM_C86 = P3^5; char bdata flag; sbit busy_f = flag^0; sbit STP=P2^0; sbit S_S=P2^1; void Initial_ST7565(void); void Write_command(UB8); void Write_data(UB8); void clear(); void show_picture(void); void full_on(); void vertical(); void Horizontal_line(); void Cross_Dot(); void delay(UB8); void stp_sc(); unsigned char code picture[8][128]; unsigned char code picture1[8][128]; unsigned char code picture2[8][128]; unsigned char code picture3[8][128]; void main() { P2 = 0x00; Initial_ST7565(); while(1) { clear(); full_on(); delay(5); stp_sc(); vertical(); stp_sc(); delay(5); Horizontal_line(); stp_sc(); delay(5); Cross_Dot(); stp_sc(); delay(5); show_picture(); stp_sc(); delay(5); } } //================================== // initial ST7565 //================================== void Initial_ST7565() { LCM_C86 = 1; LCM_PS1 = 1; LCM_CS1 = 0; Write_command(0xA0); // SET ACD = 0 S1 TO S128 Write_command(0xC8); // SET SHL = 0 C1 TO C64 Write_command(0xA2); // SET BIAS = 1 1/9 Bias 1/65 Duty Write_command(0x2F); //power contral, Write_command(0x26); // Ref .R select 00100--- Write_command(0x81); //Set Voltage Ref. Mode Write_command(0x28); //LEVEL 32 xx------ // Write_command(0x40); //Initial Display Line 01------ // Write_command(0xB0); //Set Page From 0 // Write_command(0x10); //Set Column Address MSB // Write_command(0x80); //Set Column Address LSB Write_command(0xAF); //Set Display ON // Write_command(0xA7); // Write_command(0xA1); //Write_command(0xC0); } //------------------------------------------------- // Write Data Function //------------------------------------------------- void Write_data(UB8 datap) { LCM_RS = 1; LCM_RW = 0; LCM_PORT=datap; LCM_ENABLE = 1; _nop_(); LCM_ENABLE = 0; } //------------------------------------------------- // WRITE_COMMAND //------------------------------------------------- void Write_command(UB8 command) { LCM_RS = 0; LCM_RW = 0; LCM_PORT = command; LCM_ENABLE = 1; _nop_(); LCM_ENABLE = 0; } //========================================================== void clear() { UB8 x,y,page=0xb0; for(x=0;x<8;x++) { Write_command(page);//==========set page page++; Write_command(0x10);//==========set address high bit Write_command(0x00);//===========set address low bit for(y = 0;y<128;y++) { Write_data(0x00); } } } //========================================================== void full_on() { UB8 x,y,page=0xb0; for(x = 0;x<8;x++) { Write_command(page); page++; Write_command(0x10); Write_command(0x00); for(y = 0;y<128;y++) { Write_data(0xff); } } delay(5); } //============================================================ void vertical() { UB8 x,y,page=0xb0; for(x=0;x<8;x++) { Write_command(page);//==========set page page++; Write_command(0x10);//==========set address high bit Write_command(0x00);//===========set address low bit for(y=0;y<128;y++) { Write_data(0x55); } } delay(5); } void Horizontal_line() { UB8 x,y,page=0xb0; for(x=0;x<8;x++) { Write_command(page);//==========set page page++; Write_command(0x10);//==========set address high bit Write_command(0x00);//===========set address low bit for(y=0;y<64;y++) { Write_data(0xff); Write_data(0x00); } } delay(5); } //========================================================== void Cross_Dot() { UB8 x,y,page=0xb0; for(x=0;x<8;x++) { Write_command(page);//==========set page page++; Write_command(0x10);//==========set address high bit Write_command(0x00);//===========set address low bit for(y=0;y<64;y++) { Write_data(0x55); Write_data(0xaa); } } delay(5); } //======================================================== void delay(UB8 m) { UB8 i,j,k; for(j=0;j