| ??? 05/21/03 17:47 Read: times |
#46270 - c code Responding to: ???'s previous message |
hi again
the code is here: //------------------------------------------------------------------------------ // include files //------------------------------------------------------------------------------ #include <REG52.H> // Header file for the AT89C52 MCU #include <intrins.h> //------------------------------------------------------------------------------ // Function Declarations //------------------------------------------------------------------------------ void StartupLCD(void); void LCD_SetStartDisplayLine(unsigned char StartDisplayLine); void LCD_SetPageAddress( unsigned char PageAddress); void LCD_On(void); void LCD_Off(void); void LCD_SetContrast (unsigned char Contrast); void LCD_SetPowerMode(void); void LCD_SetADCNormal(void); void LCD_SetADCReverse(void); void LCD_SetNormalDisplay(void); void LCD_SetInverseDisplay(void); void LCD_ClearDisplay(void); void LCD_ResetBias(void); void LCD_Reset(void); void LCD_WriteCommand(unsigned char Command); void LCD_WriteData(unsigned char LCDData); void LCD_SetColumnAddress(unsigned char ColumnAddress); void LCD_Sequence(unsigned char A0Status,unsigned char WriteData); void ShortPause(void); void LCD_FillDisplay(void); void LongPause(void); //------------------------------------------------------------------------------ // GLCD routines //------------------------------------------------------------------------------ void StartupLCD(void) { LCD_Reset();// Reset module LongPause(); LCD_On();// Switch LCD on LongPause(); // LCD_SetInverseDisplay();// Black on white or inverse? Default=B on W //LongPause(); LCD_SetPowerMode(); LongPause(); LCD_SetADCNormal(); LongPause(); LCD_SetContrast(15); // Contrast to medium LongPause(); LCD_SetStartDisplayLine(0); // Set pointer to start of display RAM LongPause(); LCD_SetPageAddress(0); // Switch to LCD RAM Page 0 (first page) LongPause(); // LCD_ClearDisplay(); // Clear contents of display RAM LCD_FillDisplay(); // Fill contents of display RAM LongPause(); LCD_FillDisplay(); // Fill contents of display RAM } // LCD_SetStartDisplayLine() // ------------------------- // Set the display line for TOS (top of screen). // --------------------------------------------- void LCD_SetStartDisplayLine(unsigned char StartDisplayLine) { if (StartDisplayLine>63) StartDisplayLine=0; LCD_WriteCommand(64+StartDisplayLine); } // LCD_SetPageAddress() // -------------------- // Set the page address to which data is written. // ---------------------------------------------- void LCD_SetPageAddress( unsigned char PageAddress) { if (PageAddress>8) PageAddress=0; LCD_WriteCommand(0xb0+PageAddress); } // LCD_On() // -------- // Swith LCD module on. // -------------------- void LCD_On(void) { LCD_WriteCommand(0xaF); } // LCD_Off() // --------- // Swith LCD module off. // --------------------- void LCD_Off(void) { LCD_WriteCommand(0xaE); } // LCD_SetContrast() // ----------------- // Sets LCD contrast. // ------------------ void LCD_SetContrast (unsigned char Contrast) { if (Contrast >31) Contrast = 31; LCD_WriteCommand(128+Contrast); } // LCD_SetPowerMode() // ------------------ // Set the LCD driver power mode. Refer to datasheet. // -------------------------------------------------- void LCD_SetPowerMode(void) { LCD_WriteCommand(0x2f); } // LCD_SetADCNormal() // ------------------ // Refer to datasheet. // ------------------- void LCD_SetADCNormal(void) { LCD_WriteCommand(0xa0); } // LCD_SetADCReverse() // ------------------- // Refer to datasheet. // ------------------- void LCD_SetADCReverse(void) { LCD_WriteCommand(0xa1); } // LCD_SetNormalDisplay() // ---------------------- // Set display-mode to 'black on white'. // ------------------------------------ void LCD_SetNormalDisplay(void) { LCD_WriteCommand(0xa6); } // LCD_SetInverseDisplay() // ---------------------- // Set display-mode to 'white on black'. // ------------------------------------ void LCD_SetInverseDisplay(void) { LCD_WriteCommand(0xa7); } // LCD_ClearDisplay() // ------------------ // Write all zero's to the LCD module RAM, effectively clearing the display. // ------------------------------------------------------------------------- void LCD_ClearDisplay(void) { unsigned char Page; unsigned char Column; for (Page=0;Page<8;Page++) // Loop for 8 memory 'pages' { LCD_SetColumnAddress(0); // Reset to column 0 LCD_SetPageAddress(Page); // Goto page for (Column=0;Column<100;Column++) LCD_WriteData(0); //Repeat for 100 columns , Write '0' } } // LCD_ResetBias() // -------------- // Reset LCD module bias voltage. Refer to datasheet. // -------------------------------------------------- void LCD_ResetBias(void) { LCD_WriteCommand(0xa2); } // LCD_Reset() // ----------- // Force a software reset of the controller. Refer to datasheet. // ------------------------------------------------------------- void LCD_Reset(void) { // LCD_WriteCommand(0xee); LCD_RES = 0; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); LCD_RES = 1; _nop_(); _nop_(); _nop_(); } // LCD_WriteCommand() // ------------------ // Write a command for the LCD controller to the module. // ----------------------------------------------------- void LCD_WriteCommand(unsigned char Command) { LCD_Sequence(0,Command); } // LCD_WriteData() // --------------- // Write a byte of data to the LCD module. RAM pointer is automatically // incremented by LCD controller after the write operation. // -------------------------------------------------------------------- void LCD_WriteData(unsigned char LCDData) { LCD_Sequence(1,LCDData); } // LCD_SetColumnAddress() // ---------------------- // Write a new column-address to the LCD controller. This action is done in // two separate write-commands: for high and low address. Refer to LCD module // datasheet. // ------------------------------------------------------------------------- void LCD_SetColumnAddress(unsigned char ColumnAddress) { unsigned char CALow, CAHigh; if (ColumnAddress>0x83) ColumnAddress=0; //if greater than 131 CALow = ColumnAddress; // Split column address in 2 4-bit nibbles CALow &= 0x0F; CAHigh = (ColumnAddress>>4); LCD_WriteCommand(0x10+CAHigh); // Set high nibble LCD_WriteCommand(CALow); // Set low nibble } // LCD_Sequence() // -------------- // General routine to send data and/or commands to the LCD controller. // The A0 line determines if the data to be output is a command or // actually data. Refer to LCD controller datasheet for more info. // ------------------------------------------------------------------ void LCD_Sequence(unsigned char A0Status,unsigned char WriteData) { if (A0Status == 1) { LCD_A0 = 1; // Set A0 for data } else { LCD_A0 = 0; // or reset for command } LCD_RW = 0; // Make sure RW line is low LCD_DATA = WriteData; // Put data/command on data-bus LCD_ENABLE = 0; // Clear ENABLE line LCD_CSA = 0; // Set SEL line // LCD_CSB = 1; // Set SEL line LCD_ENABLE = 1; // Set ENABLE line ShortPause(); // Insert a short pause to allow all lines to become LCD_ENABLE = 0; // stable; without this pause, the LCD may 'scramble' ShortPause(); LCD_CSA = 1; // Release the SELECT line; data is clocked in now ... // LCD_CSB = 0; // Release the SELECT line; data is clocked in now ... LCD_A0 = 0; } // ShortPause() // -------------- // Generate a short pause to allow all lcd lined to become stable // ------------------------------------------------------------------ void ShortPause(void) { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); } // LCD_FillDisplay() // ------------------ // Write all 1's to the LCD module RAM, effectively clearing the display. // ------------------------------------------------------------------------- void LCD_FillDisplay(void) { unsigned char Page; unsigned char Column; for (Page=0;Page<8;Page++) // Loop for 8 memory 'pages' { LCD_SetColumnAddress(0); // Reset to column 0 LongPause(); LCD_SetPageAddress(Page); // Goto page LongPause(); for (Column=0;Column<100;Column++) { LCD_WriteData(0x55); //Repeat for 100 columns , Write '0' LongPause(); } } } // LongPause() // -------------- // Generate a Long pause to allow all lcd lined to become stable // ------------------------------------------------------------------ void LongPause(void) { unsigned int k; for(k = 0; k<10000;k++); } |
| Topic | Author | Date |
| SED1530 LCD driver code | 01/01/70 00:00 | |
| c code | 01/01/70 00:00 | |
RE: SED1530 LCD driver code | 01/01/70 00:00 |



