void lcd_setup() { /* open drain(*) / push-pull: P2.0*LCD_SBUF P2.1 LCD_CLK P2.2*LCD_MISO P2.3 LCD_MOSI P2.4 LCD_SS P2.5 P2.6 LED0 P2.7 LED1 */ SFRPAGE = CONFIG_PAGE; P2MDOUT = 0xFA; // stop all macros lcd_send("MS", 3); lcd_clear(); // change display orientation lcd_send("DO\01", 3); // change default font and color lcd_font(3); lcd_fontcolor(WHITE, BLACK); lcd_fontzoom(2, 2); }
void lcd_set_contrast(int val) { // NOTE: this should not interfere with lcd_update_rect imx233_lcdif_wait_ready(); imx233_lcdif_set_word_length(8); // set contrast lcd_send(false, 0xc7); lcd_send(true, val); }
/* Displays a separator at current cursor location */ void lcd_sep() { lcd_base_addr(lcdCacheIdx); // 5 pixel wide characters and add space lcd_send(0x44, LCD_DATA); lcd_send(0, LCD_DATA); lcdCacheIdx += 2; }
void lcd_extrachar(int num) { unsigned char i; for(i=0;i<10;i++) { lcd_send(extraChars[num][i], LCD_DATA); } lcd_send(0, LCD_DATA); // Пропускаем пиксел между буквами }
// the most basic function, set a single pixel void drawPixel(unsigned char x, unsigned char y, int color) {//unsigned char color) { int pixel_addr = x + y/CHAR_HEIGHT * LCD_WIDTH; lcd_send(0x80 |(pixel_addr % LCD_WIDTH), LCD_CMD); lcd_send(0x40 |(pixel_addr / LCD_WIDTH), LCD_CMD); if (color) lcd_send(color, LCD_DATA); //"black pixel" else lcd_send(0, LCD_DATA); //"remove black pixel" }
/* Displays a character at current cursor location */ void lcd_chr(char chr) { lcd_base_addr(lcdCacheIdx); // 5 pixel wide characters and add space for(unsigned char i=0;i<5;i++) { lcd_send(pgm_read_byte(&font5x7[chr-32][i]) << 1, LCD_DATA); } lcd_send(0, LCD_DATA); lcdCacheIdx += 6; }
/* Performs IO & LCD controller initialization */ void Nlcd_init( volatile uint8_t *port_SCE, uint8_t dq_SCE, volatile uint8_t *port_RST, uint8_t dq_RST, volatile uint8_t *port_DC, uint8_t dq_DC, volatile uint8_t *port_DATA, uint8_t dq_DATA, volatile uint8_t *port_CLK, uint8_t dq_CLK ) { // save configuration m_port_SCE = port_SCE; m_dq_SCE = dq_SCE; m_port_RST = port_RST; m_dq_RST = dq_RST; m_port_DC = port_DC; m_dq_DC = dq_DC; m_port_DATA= port_DATA;m_dq_DATA = dq_DATA; m_port_CLK = port_CLK; m_dq_CLK = dq_CLK; // Pull-up on reset pin Set(m_port_RST, m_dq_RST, 1); //LCD_PORT |= LCD_RST_PIN; // Set output bits on lcd port Set(Port2DDR(m_port_RST), m_dq_RST, 1); Set(Port2DDR(m_port_SCE), m_dq_SCE, 1); Set(Port2DDR(m_port_DC), m_dq_DC, 1); Set(Port2DDR(m_port_DATA), m_dq_DATA, 1); Set(Port2DDR(m_port_CLK), m_dq_CLK, 1); //LCD_DDR |= LCD_RST_PIN | LCD_SCE_PIN | LCD_DC_PIN | LCD_DATA_PIN | LCD_CLK_PIN; // Wait after VCC high for reset (max 30ms) _delay_ms(15); // Toggle display reset pin Set(m_port_RST, m_dq_RST, 0); //LCD_PORT &= ~LCD_RST_PIN; //lcd_delay(); /// delay macro function #define lcd_delay() for(int i=-32000;i<32000;i++) _delay_ms(64); Set(m_port_RST, m_dq_RST, 1);//LCD_PORT |= LCD_RST_PIN; // Disable LCD controller Set(m_port_SCE, m_dq_SCE, 0);//LCD_PORT |= LCD_SCE_PIN; lcd_send(0x21, LCD_CMD); // LCD Extended Commands lcd_send(0xC8, LCD_CMD); // Set LCD Vop(Contrast) lcd_send(0x06, LCD_CMD); // Set Temp coefficent lcd_send(0x13, LCD_CMD); // LCD bias mode 1:48 lcd_send(0x20, LCD_CMD); // Standard Commands, Horizontal addressing lcd_send(0x0C, LCD_CMD); // LCD in normal mode // Clear lcd lcd_clear(); // Set display contrast. Note: No change is visible at ambient temperature int contrast = 0x40; lcd_send(0x21, LCD_CMD); // LCD Extended Commands lcd_send(0x80 | contrast, LCD_CMD); // Set LCD Vop(Contrast) lcd_send(0x20, LCD_CMD); // LCD std cmds, hori addr mode }
void lcd_init(void) // Инициализация LCD { unsigned int i; LCD_CLK_PIN = 0; LCD_RST_PIN = 1; // Устанавливаем Reset = 1 delay_ms(15); // Ждем после подачи VCC LCD (max 30ms) LCD_RST_PIN = 0; // Сброс LCD (Reset = 0) lcd_delay(); LCD_RST_PIN = 1; // Восстанавливаем сброс (Reset = 1) lcd_send(0x21, LCD_CMD); // Перевод LCD в режим внешних команд lcd_send(0xC6, LCD_CMD); lcd_send(0x06, LCD_CMD); // Установить температурный коэффициент lcd_send(0x13, LCD_CMD); // LCD bias mode 1:48 lcd_send(0x20, LCD_CMD); // Перевод LCD в режим cтандартных команд, Горизонтальная адресация (внутренние команды) lcd_send(0x80, LCD_CMD); for (i=0;i<504;i++) { lcd_send(0x00, LCD_DATA); } lcd_send(0x0C, LCD_CMD); // LCD в нормальный режим отображения (черным по белому) }
// initialize LCD void lcd_init(void) { // set up registers DDRC = DDRC | 0b00110000; // pc4 rs, pc5 enable DDRD = DDRD | 0xFF; // data _delay_ms(15); //wait for power up //initialisation of LCD screen lcd_send(0,0b00011100); // function set (5x7 dot format, 2 line mode, 8-bit data) lcd_send(0,0b00110000); // Blink OFF, underline OFF, Display ON lcd_send(0,0b01100000); // character entry mode with increment and display shift OFF lcd_clear(); lcd_return(); }
int8_t lcd_display_write(char *text1, char *text2) { size_t l1 = strlen(text1); size_t l2 = strlen(text2); size_t size; uint8_t *str = malloc(18); /* * create a mem area to hold the actual string plus additional commands * (two here). */ uint8_t i = 18; if (l1 <= LCD_DIS_LEN && l2 <= LCD_DIS_LEN && str) { do { str[i] = ' '; // Initialize all places with spaces. } while (i--); str[0] = 0x01|_BV(LCD_CONTROL); // Set first byte to issue a clear command. memcpy(str+1, text1, l1); str[8] = 0xC0; // Issue address set to be in second half. memcpy(str+9, text2, l2); size = l1+l2; free(text1); free(text2); lcd_send(str, size); } else { size = -1; } return size; }
void lcd_font(unsigned char f) { if (f == 1) { _sx = 4; _sy = 6; } else if (f == 2) { _sx = 6; _sy = 8; } else if (f == 3) { _sx = 7; _sy = 12; } else if (f == 4) { _sx = 5; _sy = 10; } else if (f == 5) { _sx = 7; _sy = 14; } else if (f == 6) { _sx = 15; _sy = 30; } _buf[03] = 'Z'; _buf[1] = 'F'; _buf[2] = f; lcd_send(_buf, 3); }
void LCD_test(){ lcd_set_state(LCD_ENABLE, CURSOR_DISABLE); int i=0; while(i<0xFF){ lcd_set_xy(0,0); lcd_write_dec_xxx(i); lcd_set_xy(0,1); lcd_send(i, DATA); i++; delay_ms(700); } lcd_set_xy(0, 0); //lcd_out("ÀÁÂÃÄŨÆÇÈÉÊËÌÍÎÏ"); lcd_set_xy(0, 1); //lcd_out("ðñòóôõö÷øùúûüýþÿ"); //lcd_out("àáâãäå¸æçèéêëìíîï"); //lcd_out("ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß"); delay_ms(17000); }
static inline void wr_dat_only (unsigned short c) { lcd_send(c); //LCD_WR(0); //wait(); //LCD_WR(1); }
void lcd_col(char chr) { lcd_base_addr(lcdCacheIdx); lcd_send(chr, LCD_DATA); lcdCacheIdx++; }
// Displays a character at current cursor location or moves to new line if enter char is given void lcd_chr(char chr) { if (chr == '\n') { // move to next line and first column lcdCacheIdx = lcdCacheIdx + LCD_WIDTH - lcdCacheIdx % LCD_WIDTH; //next line and x=0 } else { lcd_base_addr(lcdCacheIdx); // 5 pixel wide characters and add space for(unsigned char i=0; i < CHAR_WIDTH - 1; i++) lcd_send(pgm_read_byte(&font5x7[chr-32][i]) << 1, LCD_DATA); lcd_send(0, LCD_DATA); // right empty separator line of 8 vertical pixels lcdCacheIdx += CHAR_WIDTH; } }
/****************************************************************************** ** Function name: lcd_cursor ** ** Descriptions: set the cursor to row and column ** ** parameters: None ** Returned value: None ** ******************************************************************************/ void lcd_cursor (int row, int col) { char configbuf[4]; configbuf[0] = 0x78; configbuf[1] = 0x00; configbuf[2] = 0x80 | (col + row*0x40); lcd_send(configbuf, 3); }
void lcd_fontcolor(unsigned char fg, unsigned char bg) { _buf[0] = 'F'; _buf[1] = 'Z'; _buf[2] = fg; _buf[3] = bg; lcd_send(_buf, 4); }
void lcd_single_command(INT8U cmd) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { GPIO_PORTD_DATA_R &= ~LCD_RS; // Select instruction register delay(); lcd_send( cmd ); // Send command to LCD }
void lcd_putch(char chr) // Вывод символа на LCD в текущую позицию курсора { unsigned char i; if ( (chr >= 0x20) && (chr <= 0x7F) ) // Смещение в таблице для символов ASCII[0x20-0x7F] {chr -= 32;} else if ( chr >= 0xC0 ) // Смещение в таблице для символов CP1251[0xC0-0xFF] { chr -= 96; } else // Остальные игнорируем (их просто нет в таблице для экономии памяти) { chr = 95; } for(i=0;i<5;i++) // Ширина буквы 5 пикселов { lcd_send(font5x7[chr][i], LCD_DATA); } lcd_send(0, LCD_DATA); // Пропускаем пиксел между буквами }
static void Write_Dat( int data){ cs::set( 0 ); rs::set( 1 ); rd::set( 1 ); lcd_send( data ); wr::set( 0 ); wr::set( 1 ); cs::set( 1 ); }
static void Write_Cmd( int reg ){ cs::set( 0 ); rs::set( 0 ); rd::set( 1 ); lcd_send( reg ); wr::set( 0 ); wr::set( 1 ); cs::set( 1 ); }
void lcd_clear(void) { // Очистка дисплея unsigned int i; lcd_gotoxy(0,0); for (i=0;i<504;++i) { lcd_send(0x00, LCD_DATA); } }
// Clears an area on a line void lcd_clear_area(unsigned char line, unsigned char startX, unsigned char endX) { // Start and end positions of line int start = line * LCD_WIDTH + startX; int end = line * LCD_WIDTH + endX; lcd_base_addr(start); // Clear all data in range from cache for(unsigned int i = start; i < end; i++) lcd_send(0, LCD_DATA); }
// Clears the display void lcd_clear(void) { lcdCacheIdx = 0; lcd_base_addr(lcdCacheIdx); // Set the entire cache to zero and write 0s to lcd int lcd_size = ((LCD_WIDTH * LCD_HEIGHT) / CHAR_HEIGHT); for(int i=0;i<lcd_size;i++) lcd_send(0, LCD_DATA); }
void lcd_fontzoom(unsigned char zx, unsigned char zy) { _zx = zx; _zy = zy; _buf[0] = 'Z'; _buf[1] = 'Z'; _buf[2] = zx; _buf[3] = zy; lcd_send(_buf, 4); }
/* Clears the display */ void lcd_clear(void) { lcdCacheIdx = 0; lcd_base_addr(lcdCacheIdx); // Set the entire cache to zero and write 0s to lcd for(int i=0;i<LCD_CACHE_SIZE;i++) { lcd_send(0, LCD_DATA); } }
void lcd_init_cmd(void) { char configbuf[12]; configbuf[0] = 0x78; configbuf[1] = 0x00; configbuf[2] = 0x38; configbuf[3] = 0x39; configbuf[4] = 0x14; configbuf[5] = 0x78; configbuf[6] = 0x5e; configbuf[7] = 0x6d; configbuf[8] = 0x0c; configbuf[9] = 0x01; configbuf[10] = 0x06; lcd_send(configbuf, 11); delayMs(0, 10); }
void lcd_command(INT8U cmd) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { GPIO_PORTD_DATA_R &= ~LCD_RS; // Select instruction register delay(); lcd_send( cmd >> 4 ); // Send high nibble to LCD //delay(); lcd_send( cmd & 0x0F ); // Send low nibble to LCD //delay(); }
void lcd_write(INT8U character) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { GPIO_PORTD_DATA_R |= LCD_RS; // Select data register delay(); lcd_send( character >> 4 ); // Send high nibble to LCD //delay(); lcd_send( character & 0x0F ); // Send low nibble to LCD //delay(); }
/* Performs IO & LCD controller initialization */ void lcd_init(void) { // Pull-up on reset pin LCD_PORT |= LCD_RST_PIN; // Set output bits on lcd port LCD_DDR |= LCD_RST_PIN | LCD_CE_PIN | LCD_DC_PIN | LCD_DATA_PIN | LCD_CLK_PIN; // Wait after VCC high for reset (max 30ms) _delay_ms(15); // Toggle display reset pin LCD_PORT &= ~LCD_RST_PIN; lcd_delay(); LCD_PORT |= LCD_RST_PIN; // Disable LCD controller LCD_PORT |= LCD_CE_PIN; lcd_send(0x21, LCD_CMD); // LCD Extended Commands lcd_send(0xC8, LCD_CMD); // Set LCD Vop(Contrast) lcd_send(0x06, LCD_CMD); // Set Temp coefficent lcd_send(0x13, LCD_CMD); // LCD bias mode 1:48 lcd_send(0x20, LCD_CMD); // Standard Commands, Horizontal addressing lcd_send(0x0C, LCD_CMD); // LCD in normal mode // Clear lcd lcd_clear(); // For using printf //fdevopen(lcd_chr, 0); }