ÿþ#include "REG51.h" #include "intrins.h" sbit LCD_CS = P0^7; sbit LCD_RES = P0^6; sbit LCD_A0 = P0^5; sbit LCD_CLK = P0^4; sbit LCD_SDI = P0^3; //======================================================================== // Function name: void LCD_DataWrite(unsigned int Data) // Description: Write 1 byte date to display RAM // Parameters: Write data // Return: None // Comments: None // Version: // 2007/05/17 First version //======================================================================== void LCD_DataWrite(unsigned char Dat)//,_Fill_Dot_LCD { unsigned char Num; LCD_CS = 0; LCD_A0 = 1; for(Num=0;Num<8;Num++) { if((Dat&0x80) == 0) LCD_SDI = 0; else LCD_SDI = 1; Dat = Dat << 1; LCD_CLK = 0; LCD_CLK = 1; } LCD_CS = 1; 12 } //======================================================================== // Function name: void LCD_RegWrite(unsigned char Command) // Description: Write 1 byte data to control register // Parameters: Command , write data // Return: None // Comments: None // Version: // 2007/05/17 First version //======================================================================== void LCD_RegWrite(unsigned char Command) { unsigned char Num; LCD_CS = 0; LCD_A0 = 0; for(Num=0;Num<8;Num++) { if((Command&0x80) == 0) LCD_SDI = 0; else LCD_SDI = 1; Command = Command << 1; LCD_CLK = 0; LCD_CLK = 1; } LCD_CS = 1; } Users can refer to following code to write LCD initial function.(*Recommended) //======================================================================== // Function name: void LCD_Init(void) // Description: LCD initial function. Users can refer to ST7565 datasheet for more information // Parameters: None // Return: None // Comments: None // Version: // 2006/10/15 First version // 2007/01/09 V1.2 //======================================================================== //Delay void TimeDelay(int Time) 13 { int i; if(Time > 0) { for(i = 0;i < 800;i++) { } Time --; } } void LCD_Init(void) { //Initial all of port LCD driver use(if necessary) // LCD_PortInit(); TimeDelay(200); LCD_RS = 0; TimeDelay(200); LCD_RS = 1; LCD_RegWrite(0xaf); // LCD On LCD_RegWrite(0x2f); // Set power control mode LCD_RegWrite(0x81); // Set electronic volume mode LCD_RegWrite(0x1f); // Command data 0x0000~0x003f LCD_RegWrite(0x27); // Set V5 internal voltage adjustment resistor LCD_RegWrite(0xa2); // Set LCD bias LCD_RegWrite(0xc8); // Com scan direction set, reverse LCD_RegWrite(0xa0); // Select segment direction, normal LCD_RegWrite(0xa4); // Set all point ON/OFF command LCD_RegWrite(0xa6); // Set normal/reverse display command LCD_RegWrite(0xac); // Close static indicator LCD_RegWrite(0x00); // Command data LCD_RegWrite(0x40 +0); // Set start common RAM LCD_RegWrite(0xe0); // Set read/write mode }