/****************************************************** Project : TESTLCD.PRJ Author : HC Raisonance 1998 File : LCD.C Subject : Sample test for 51-Monitor using LCD display C routines ******************************************************/ // LCD display functions prototypes and structure defintions #include // LCD mapping addresses at LCD_BASE xdata tLCD LCD_demo; static unsigned char dd_ram_addr = 0x80; #pragma NOAREGS void clrscr() { LCDclear(); } int putchar(const int v) { unsigned char v1; v1 = (unsigned char) v; switch (v1) { case '\n' : LCDCrLf(); break; case '\r' : LCDCrLf(); break; default : LCDPutchar(v); break; } // end switch(v) return(v); } // end putchar(v) /********************************************************* Function DelayMSEC : delay for k msec with a crystal at 14.7456 MHz in small memory model *********************************************************/ void DelayMSEC (unsigned int k) { unsigned int i,j; for ( j = 0; j < k; j++) for (i = 0; i <= MILLI_SEC;) // 1 millisecond { i++; } } /********************************************************* Function LCDWait : Waits for display to be finished *********************************************************/ void LCDWait (void) { while (LCD_demo.ird & 0x80); } /********************************************************* Function LCDClear : Clears LCD display *********************************************************/ void LCDClear (void) { while (LCD_demo.ird & 0x80); LCD_demo.iwr = CLEAR_DISPLAY; } /********************************************************* Function LCDHome : Moves cursor to home *********************************************************/ void LCDHome (void) { while (LCD_demo.ird & 0x80); LCD_demo.iwr = LCD_HOME; } /********************************************************* Function LCDShr : Moves cursor one step to the right *********************************************************/ void LCDShr (void) { while (LCD_demo.ird & 0x80); LCD_demo.iwr = 0x1c; } /********************************************************* Function LCDShl : Moves cursor one step to the left *********************************************************/ void LCDShl (void) { while (LCD_demo.ird & 0x80); LCD_demo.iwr = 0x18; } /********************************************************* Function LCDEntryMode : Set LCD into a specific mode *********************************************************/ void LCDEntryMode (unsigned char mode) { while (LCD_demo.ird & 0x80); LCD_demo.iwr = 0x04 + (mode & 0x3); } /* lcd_crlf passe l'affichage d'une ligne a l'autre */ /********************************************************* Function LCDCrLf : Change LCD display current line *********************************************************/ void LCDCrLf (void) { int i; while (LCD_demo.ird & 0x80); dd_ram_addr ^= 0x40; // Display address = 0 (1st line) or 0x40 (2nd line) LCD_demo.iwr = dd_ram_addr; // for (i = 0; i < 16; i++) // Fill the line with spaces (ASCII 0x20)remplissage de la ligne avec des ' ' // LCDPutchar(' '); while (LCD_demo.ird & 0x80); LCD_demo.iwr = dd_ram_addr; // Back to the beginning of line } /********************************************************* Function LCDCr : Return at home LCD display current line *********************************************************/ void LCDCr (void) { while (LCD_demo.ird & 0x80); // Wait busy dd_ram_addr ^= 0x40; // Display address = 0 (1st line) or 0x40 (2nd line) while (LCD_demo.ird & 0x80); // Wait busy LCD_demo.iwr = dd_ram_addr; // Back to the beginning of line } /********************************************************* Function LCDDisplay : Displays the text pointed by ptr This function is ok for '\n', calling LCDCrLf if necessary. *********************************************************/ void LCDDisplay (char * ptr) { while (*ptr) { if (*ptr == '\n') { LCDCrLf(); ptr++; } else LCDPutchar(*ptr++); } } /********************************************************* Function LCDPuts : Put a string on LCD display *********************************************************/ void LCDPuts (char * ptr) { while (*ptr) LCDPutchar(*ptr++); } /********************************************************* Function LCDInit : LCD Initializations *********************************************************/ void LCDInit (void) { DelayMSEC(15); LCD_demo.iwr = FUNCTION_SET; DelayMSEC(10); LCD_demo.iwr = FUNCTION_SET; DelayMSEC(10); LCD_demo.iwr = FUNCTION_SET; LCDWait(); LCD_demo.iwr = ENTRY_MODE; LCDWait(); LCD_demo.iwr = DISPLAY_CONTROL; LCDWait(); LCD_demo.iwr = CLEAR_DISPLAY; LCDWait(); LCD_demo.iwr = SET_DD_RAM_ADDR; dd_ram_addr = 0x80; } /********************************************************* Function LCDPutchar : Display 'c' on LCD *********************************************************/ int LCDPutchar (const int c) { while (LCD_demo.ird & 0x80); LCD_demo.dwr = (unsigned char) c; return (c); }