void OpenXLCD(unsigned char lcdtype) { // 4-bit mode #ifdef UPPER // Upper 4-bits of the port DATA_PORT &= 0x0f; TRIS_DATA_PORT &= 0x0F; #else // Lower 4-bits of the port DATA_PORT &= 0xf0; TRIS_DATA_PORT &= 0xF0; #endif TRIS_RW = 0; // All control signals made outputs TRIS_RS = 0; TRIS_E = 0; RW_PIN = 0; // R/W pin made low RS_PIN = 0; // Register select pin made low E_PIN = 0; // Clock pin made low // Delay for 15ms to allow for LCD Power on reset DelayPORXLCD(); //-------------------reset procedure through software---------------------- WriteCmdXLCD(0x30); Delay1KTCYx(33); WriteCmdXLCD(0x30); Delay1KTCYx(0x01); WriteCmdXLCD(0x32); while( BusyXLCD() ); //------------------------------------------------------------------------------------------ // Set data interface width, # lines, font while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(lcdtype); // Function set cmd // Turn the display on then off while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(DOFF&CURSOR_OFF&BLINK_OFF); // Display OFF/Blink OFF while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON); // Display ON/Blink ON // Clear display while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(0x01); // Clear display // Set entry mode inc, no shift while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(SHIFT_CUR_LEFT); // Entry Mode // Set DD Ram address to 0 while(BusyXLCD()); // Wait if LCD busy SetDDRamAddr(0x80); // Set Display data ram address to 0 return; }
/******************************************************************* Function Name: OpenXLCD Description: This function configure the IO pins and initializes the LCD controller the lcdtype should contain data on the type of interface and number of lines of display. Input parameters: char lcdtype Return value: none ********************************************************************/ void OpenXLCD(char lcdType) { /* Allow a delay for POR.(minimum of 15ms) */ DelayPORXLCD(); /*Initialize the data port/control pins to zero */ DATA_PIN_7 = 0; DATA_PIN_6 = 0; DATA_PIN_5 = 0; DATA_PIN_4 = 0; # ifdef EIGHT_BIT_INTERFACE DATA_PIN_3 = 0; DATA_PIN_2 = 0; DATA_PIN_1 = 0; DATA_PIN_0 = 0; #endif RW_PIN = 0; RS_PIN = 0; E_PIN = 0; /* Configure the data pins as outputs */ TRIS_DATA_PIN_7 = 0; TRIS_DATA_PIN_6 = 0; TRIS_DATA_PIN_5 = 0; TRIS_DATA_PIN_4 = 0; #ifdef EIGHT_BIT_INTERFACE TRIS_DATA_PIN_3 = 0; TRIS_DATA_PIN_2 = 0; TRIS_DATA_PIN_1 = 0; TRIS_DATA_PIN_0 = 0; #endif /* Make all control pins as outputs */ TRIS_RW = 0; TRIS_RS = 0; TRIS_E = 0; /* First Step - Function Set as specified by lcdType*/ WriteCmdXLCD(lcdType); /* wait for command completion */ while(BusyXLCD()); /* Second Step - Display ON/OFF CONTROL*/ WriteCmdXLCD(DON & BLINK_OFF & CURSOR_ON); /* wait for command completion */ while(BusyXLCD()); /* Third Step - LCD Clear */ WriteCmdXLCD(CLEAR_XLCD); /* wait for command completion */ while(BusyXLCD()); /*Fourth Step - Entry Mode Set */ WriteCmdXLCD(ENTIRE_SHIFT_OFF & INCR_MODE); /* wait for command completion */ while(BusyXLCD()); } /* end of function */
/******************************************************************** * Function Name: lcd_init() * * Return Value: void * * Parameters: void * * Description: Basée sur le coontroleur d'afficheur Hitachi* * HD44780 LCD, cette fonction initialise * * l'écran LCD * ********************************************************************/ void lcd_init() { PORTD = 0; // tous les signaux à 0 TRISD = 0xF0; // signaux de contrôle en sortie et signaux de données en entrées DelayPORXLCD(); // Delay for 15ms to allow for LCD Power on reset // Setup interface to LCD TRIS_DATA_PORT &= 0x0f; // Port données en écriture DATA_PORT &= 0x0f; // Masque pour effacer le port de données DATA_PORT |= 0b00110000; // Masque pour écrire 0011 (cmd) sur le port de données E_PIN = 1; // Clock the cmd in - Validation de l'écriture de cmd DelayxxTCY(); E_PIN = 0; // Delay for at least 4.1ms DelayXLCD(); // Setup interface to LCD DATA_PORT &= 0x0f; // On recommence à écrire cmd DATA_PORT |= 0b00110000; // E_PIN = 1; // Clock the cmd in DelayxxTCY(); E_PIN = 0; // Delay for at least 100us DelayXLCD(); // Setup interface to LCD DATA_PORT &= 0x0f; // Function set cmd DATA_PORT |= 0b00110000; E_PIN = 1; // Clock cmd in DelayxxTCY(); E_PIN = 0; DelayXLCD(); // Setup interface to LCD DATA_PORT &= 0x0f; // Function set cmd(4-bit interface) DATA_PORT |= 0b00100000; E_PIN = 1; // Clock cmd in DelayxxTCY(); E_PIN = 0; TRIS_DATA_PORT |= 0xf0; // Port de données en entrée // Set data interface width, # lines, font while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(LCD_TYPE); // Function set cmd // Turn the display on then off while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(DOFF&CURSOR_OFF&BLINK_OFF); // Display OFF/Blink OFF while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON); // Display ON/Blink ON // Clear display while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(0x01); // Clear display // Set entry mode inc, no shift while(BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(SHIFT_CUR_LEFT); // Entry Mode // Set DD Ram address to 0 while(BusyXLCD()); // Wait if LCD busy lcd_gotoyx(1,1); // Set Display data ram address to 0 return; }