/// Procedura inicjalizacji kontrolera HD44780. void LCD_init(void) { unsigned char i; LCD_DB4_DIR |= LCD_DB4; // Konfiguracja kierunku pracy wyprowadzeń LCD_DB5_DIR |= LCD_DB5; // LCD_DB6_DIR |= LCD_DB6; // LCD_DB7_DIR |= LCD_DB7; // LCD_E_DIR |= LCD_E; // LCD_RS_DIR |= LCD_RS; // _delay_ms(15); // oczekiwanie na ustalibizowanie się napiecia zasilajacego LCD_RS_PORT &= ~LCD_RS; // wyzerowanie linii RS LCD_E_PORT &= ~LCD_E; // wyzerowanie linii E for(i = 0; i < 3; i++) // trzykrotne powtórzenie bloku instrukcji { LCD_E_PORT |= LCD_E; // E = 1 _LCD_OutNibble(0x03); // tryb 8-bitowy LCD_E_PORT &= ~LCD_E; // E = 0 _delay_ms(5); // czekaj 5ms } LCD_E_PORT |= LCD_E; // E = 1 _LCD_OutNibble(0x02); // tryb 4-bitowy LCD_E_PORT &= ~LCD_E; // E = 0 _delay_ms(1); // czekaj 1ms LCD_writeCommand(HD44780_FUNCTION_SET | HD44780_FONT5x7 | HD44780_TWO_LINE | HD44780_4_BIT); // interfejs 4-bity, 2-linie, znak 5x7 LCD_writeCommand(HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_OFF); // wyłączenie wyswietlacza LCD_writeCommand(HD44780_CLEAR); // czyszczenie zawartosći pamieci DDRAM _delay_ms(2); LCD_writeCommand(HD44780_ENTRY_MODE | HD44780_EM_SHIFT_CURSOR | HD44780_EM_INCREMENT);// inkrementaja adresu i przesuwanie kursora LCD_writeCommand(HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_ON | HD44780_CURSOR_OFF | HD44780_CURSOR_NOBLINK); // włącz LCD, bez kursora i mrugania }
/*-------------------------------------------------------------------------------------------------- Name : LCD_gotoXY Description : Sets cursor location to xy location corresponding to basic font size. Argument(s) : x - range: 0 to 84 y -> range: 0 to 5 Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_gotoXY ( unsigned char x, unsigned char y ) { LCD_writeCommand (0x80 | x); //column LCD_writeCommand (0x40 | y); //row cursor_x = x; cursor_y = y; }
void LCD_goto(uint8_t x, uint8_t y) { LCD_writeCommand(0x80 | x); //column LCD_writeCommand(0x40 | y); //row cursor_row = y; cursor_col = x; }
/*-------------------------------------------------------------------------------------------------- Name : LCD_gotoXY Description : Sets cursor location to xy location corresponding to basic font size. Argument(s) : x - range: 0 to 84 y -> range: 0 to 6 Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_gotoXY ( unsigned char x, unsigned char y ) { //LCD_writeCommand (0x20); LCD_writeCommand (0x80 | x); //column LCD_writeCommand (0x40 | y); //row cursor_row = y; cursor_col = x; //+ 84*y; }
/* *------------------------------------------------------------------------------ * void InitializeLcd(void) * * Summary : Initialize LCD and setup LCD task to run. * * Input : None * * Output : None * *------------------------------------------------------------------------------ */ void LCD_init(void) { // Initialize LCD hardware InitLcd(); // Clear the display at startup LCD_writeCommand(DISPLAY_CLEAR); lcd.NOofChar = 0; }
/*-------------------------------------------------------------------------------------------------- Name : LCD_init Description : LCD controller initialization. Argument(s) : None. Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_init ( void ) { DDRB |= (1<<PB0) | (1<<PB1) | (1<<PB2); CLEAR_RST_PIN; //reset LCD _delay_ms(2); CLEAR_SCE_PIN; //Enable LCD _delay_ms(2); SET_RST_PIN; SET_SCE_PIN; //disable LCD LCD_writeCommand( 0x21 ); // LCD Extended Commands. LCD_writeCommand( 0x80 | 0x30); // Set LCD Vop (Contrast). LCD_writeCommand( 0x04 ); // Set Temp coefficent. LCD_writeCommand( 0x13 ); // LCD bias mode 1:48. LCD_writeCommand( 0x20 ); // LCD Standard Commands, Horizontal addressing mode. LCD_writeCommand( 0x09 ); // all display segments on _delay_ms(500); LCD_writeCommand( 0x0c ); // LCD in normal mode. LCD_clear(); _delay_ms(500); }
/* *------------------------------------------------------------------------------ * void UpdateLcdTask(void) * * Summary : Copies the contents of the local LCDText[] array into the * LCD's internal display buffer. Null terminators in * LCDText[] terminate the current line, so strings may be * printed directly to LCDText[]. * * Input : None * * Output : None * *------------------------------------------------------------------------------ */ void writetoLCD(UINT8 *buff) { UINT8 i; LCD_writeCommand(DISPLAY_CLEAR); // Output first line for(i = 0; i < DISPLAY_MAX_COLUMNS_PER_ROW; i++) { lcd.buff[0][i]= *buff; *buff++; } LCD_writeCommand(DISPLAY_DPY_2ND_LINE); for(i = 0; i < DISPLAY_MAX_COLUMNS_PER_ROW; i++) { lcd.buff[0][i]= *buff; *buff++; } }
void setColumn(uint8_t col) { if(col > LCD_MAX_WIDTH) col = 0; uint8_t lsb = col & 0x0F; uint8_t msb = (col & 0xF0) >> 4; msb |= 0x10; uint8_t cmd[] = {msb,lsb}; LCD_writeCommand(cmd,2); }
void scrollLines(uint8_t lines) { scrolled_lines = scrolled_lines + lines; lines = 64 - scrolled_lines%64; lines |= BIT6; lines &= ~BIT7; uint8_t cmd[] = {lines}; LCD_writeCommand(cmd,1); }
void LCD_putChar(UINT8 data) { UINT8 i; if(data == lcd.bckspc) { if(lcd.NOofChar == 0) { return; } if(lcd.NOofChar == 16) { LCD_writeCommand(DISPLAY_DPY_1ST_LINE); for(i=0;i<16;i++) LCD_writeCommand(DISPLAY_SHIFT_RIGHT_CUR); } LCD_writeCommand(DISPLAY_SHIFT_LEFT_CUR); LCD_writeData(' '); LCD_writeCommand(DISPLAY_SHIFT_LEFT_CUR); lcd.NOofChar--; return; } if(lcd.NOofChar == DISPLAY_MAX_COLUMNS_PER_ROW) LCD_writeCommand(DISPLAY_DPY_2ND_LINE); else if(lcd.NOofChar >= DISPLAY_MAX_CHARS) { lcd.NOofChar = 0; LCD_writeCommand(DISPLAY_RETURN_HOME); } LCD_writeData(data); lcd.NOofChar++; }
void LCD_init(void) { SPI_DDR |= (1 << DC) | (1 << SCE) | (1 << RST) | (1 << SCK) | (1 << MOSI); SET_RST_PIN; SPCR = 0x50; //setup SPI TIMER_delay_ms(100); CLEAR_SCE_PIN; //Enable LCD CLEAR_RST_PIN; //reset LCD TIMER_delay_ms(100); SET_RST_PIN; SET_SCE_PIN; //disable LCD LCD_writeCommand(0x21); // LCD Extended Commands. LCD_writeCommand(0xE0); // Set LCD Vop (Contrast). LCD_writeCommand(0x04); // Set Temp coefficent. LCD_writeCommand(0x13); // LCD bias mode 1:48. LCD_writeCommand(0x20); // LCD Standard Commands, Horizontal addressing mode. LCD_writeCommand(0x0c); // LCD in normal mode. LCD_clear(); }
void LCD_update( void ) { int i,j; #ifdef LCD_NO_SKIP_UPDATE if(1) #else if(LCD.update_rows) //if any rows to update #endif { for(i=0; i<HW_ROWS; i++) { #ifdef LCD_FORCE_TOTAL_UPDATE if(1) #else if(LCD.update_rows & (1<<i)) #endif { #ifdef LCD_UPDATE_DEBUG bit_flip(lcd_update_toggler,1<<i); #endif LCD_writeCommand (0x80); //column LCD_writeCommand (0x40|(HW_ROWS-1-i)); //row for(j=HW_COLUMNS; j>0; j--) { #ifdef LCD_UPDATE_DEBUG if(lcd_update_toggler&(1<<i)) LCD_writeData(~lcd_buffer[i][j-1]); else #endif LCD_writeData(lcd_buffer[i][j-1]); } } } LCD.update_rows=0; LCD_gotoXY (0,0); //bring the XY position back to (0,0) } }
/* *------------------------------------------------------------------------------ * void InitLcd(void) * * Summary : Initialize the LCD-Controller HD44780, * 4-bit data bus; 2 Rows; 5x7 Dot. * * Input : None * * Output : None * Note : 1/20 MHz = 0.00000005 sec = 0.05us x = 50uc *------------------------------------------------------------------------------ */ void InitLcd(void) { INT8 retValue; dataPortOut(); // Wait the required time for the LCD to reset DelayMs(40); // FUNC. SET: interface is 8 bit long rawWriteCommand8ToLcd(0x30); DelayMs(10); // Wait 10ms // FUNC. SET: interface is 8 bit long rawWriteCommand8ToLcd(0x30); DelayMs(10); // Wait 10ms // FUNC. SET: interface is 8 bit long rawWriteCommand8ToLcd(0x30); DelayMs(10); // Wait 10ms // FUNC.SET:interface is 4 bit long rawWriteCommand8ToLcd(0x20); DelayMs(10); // Wait 10ms // FUNC.SET:interface is 4 bit long 0x 28 LCD_writeCommand(0x28); retValue = busyLcd (); // Check if Display is present if(retValue == 0) { //Display ON, Cursor on 0x0C LCD_writeCommand(0x0F); // Display Clear 0x01 LCD_writeCommand(0x01); // Entry Mode Set 0x04 LCD_writeCommand(0x04); // Entry Mode Set 0x06 LCD_writeCommand(0x06); } return; }
void setPage(uint8_t page) { //resto 1 para indexar de 0 a 7 //resto el valor original de page porque el LCD considera la de abajo como pag 0 y yo quiero la de arriba page = (LCD_MAX_PAGES-1) - page; //máscara según la especificación del datasheet page |= BIT7 | BIT5 | BIT4; page &= ~BIT6; //Mando el comando al LCD uint8_t cmd[] = {page}; LCD_writeCommand(cmd,1); }
void LCD_init(void) { // Port initialization for LCD operation CD_RST_DIR |= RST; // Reset is active low CD_RST_OUT &= ~RST; // Reset is active low CD_RST_OUT |= RST; // Chip select for LCD CS_BACKLT_DIR |= CS; // CS is active low CS_BACKLT_OUT &= ~CS; // Command/Data for LCD CD_RST_DIR |= CD; // CD Low for command CD_RST_OUT &= ~CD; // P4.1 option select SIMO SPI_SEL |= SPI_SIMO; SPI_DIR |= SPI_SIMO; // P4.3 option select CLK SPI_SEL |= SPI_CLK; SPI_DIR |= SPI_CLK; // Initialize USCI_B1 for SPI Master operation // Put state machine in reset UCB1CTL1 |= UCSWRST; //3-pin, 8-bit SPI master UCB1CTL0 = UCCKPH | UCMSB | UCMST | UCMODE_0 | UCSYNC; // Clock phase - data captured first edge, change second edge // MSB // Use SMCLK, keep RESET UCB1CTL1 = UCSSEL_2 | UCSWRST; UCB1BR0 = 0x02; UCB1BR1 = 0; // Release USCI state machine UCB1CTL1 &= ~UCSWRST; UCB1IFG &= ~UCRXIFG; LCD_writeCommand(LCD_initMacro, n_init_commands); // Deselect chip CS_BACKLT_OUT |= CS; }
/*-------------------------------------------------------------------------------------------------- Name : LCD_init Description : LCD controller initialization. Argument(s) : None. Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_init ( void ) { SET_RST_PIN; SET_SCE_PIN; CLEAR_RST_PIN; delay_ms(100); SET_RST_PIN; LCD_writeCommand( 0x21 ); // LCD Extended Commands. //LCD_writeCommand( 0x04 ); // Set Temp coefficent. LCD_writeCommand( 0x13 ); // LCD bias mode 1:48. LCD_writeCommand( 0xC2 ); // Set LCD Vop (Contrast). LCD_writeCommand( 0x20 ); // LCD Standard Commands, Horizontal addressing mode. LCD_writeCommand( 0x09 ); // all display segments on delay_ms(1); LCD_clear(); LCD_writeCommand( 0x08 ); //blank LCD_writeCommand( 0x0c ); //normal operation LCD_gotoXY(0,0); }
/*-------------------------------------------------------------------------------------------------- Name : LCD_init Description : LCD controller initialization. Argument(s) : None. Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_init ( void ) { DDRD |= LCD_BACKLIGHT_PIN | LCD_SS_PIN | LCD_DC_PIN_IO | LCD_RST_PIN_IO;//sets LCD pins as outputs delay_ms(100); CLEAR_SCE_PIN; //Enable LCD CLEAR_RST_PIN; //reset LCD delay_ms(100); SET_RST_PIN; SET_SCE_PIN; //disable LCD LCD_writeCommand( 0x21 ); // LCD Extended Commands. LCD_writeCommand( 0xC8 ); // Set LCD Vop (Contrast). LCD_writeCommand( 0x06 ); // Set Temp coefficent. LCD_writeCommand( 0x13 ); // LCD bias mode 1:48. LCD_writeCommand( 0x20 ); // LCD Standard Commands, Horizontal addressing mode. LCD_writeCommand( 0x0c ); // LCD in normal mode. LCD_clear(); }
/// Funkcja ustawienia współrzędnych ekranowych void LCD_goto(unsigned char x, unsigned char y) { LCD_writeCommand(HD44780_DDRAM_SET | (x + (0x40 * y))); }
/// Funkcja przywrócenia początkowych współrzędnych wyświetlacza. void LCD_home(void) { LCD_writeCommand(HD44780_HOME); _delay_ms(2); }
void LCD_clear(void) { LCD_writeCommand(DISPLAY_CLEAR); lcd.NOofChar = 0; }
void LCD_setAllPixels(int status) { uint8_t s = (uint8_t) status; uint8_t cmd[] = {SET_ALL_PIXEL_ON + s}; LCD_writeCommand(cmd, 1); }
/// Funkcja czyszczenia ekranu wyświetlacza. void LCD_clear(void) { LCD_writeCommand(HD44780_CLEAR); _delay_ms(2); }