27 #include "common/delay.h" 28 #include "lcd/drivers/drv_lcd_interface.h" 43 #define LCD_ADDRESS_LINE_1 0x00 44 #define LCD_ADDRESS_LINE_2 0x40 46 #define LCD_DISPLAYSIZE_X 16 47 #define LCD_DISPLAYSIZE_Y 2 49 #define LCD_CLEAR 0x01 52 #define CURSOR_nSHIFT 0x00 53 #define CURSOR_SHIFT 0x01 54 #define DATA_DECREMENT 0x00 55 #define DATA_INCREMENT 0x02 56 #define LCD_ENTRY_MODE 0x04 58 #define CURSOR_OFF 0x00 59 #define CURSOR_ON 0x02 60 #define BLINK_OFF 0x00 62 #define LCD_DISPLAY_OFF 0x08 63 #define LCD_DISPLAY_ON 0x0C 65 #define FUNCTION_nIS 0x00 66 #define FUNCTION_IS 0x01 67 #define FUNCTION_1_HIGH 0x00 68 #define FUNCTION_2_HIGH 0x04 69 #define FUNCTION_1_LINE 0x00 70 #define FUNCTION_2_LINE 0x08 71 #define FUNCTION_4BITS 0x00 72 #define FUNCTION_8BITS 0x10 74 #define LCD_FUNCTION 0x20 76 #define LCD_CGRAM_ADDRESS(adr) (0x40 | (adr & 0x3F)) 77 #define LCD_DDRAM_ADDRESS(adr) (0x80 | (adr & 0x7F)) 82 #define FREQ_CNTRL(f) (f&0x07) 83 #define LCD_OSC_FREQ 0x10 85 #define LCD_ICON_ADDRESS(adr) (0x40 | (adr & 0x0F)) 91 #define CONTRAST(c) (c&0x03) 92 #define LCD_PWR_CONTROL 0x50 94 #define FOLLOWER_GAIN(g) (g&0x07) 95 #define LCD_FOLLOWER_OFF 0x60 96 #define LCD_FOLLOWER_ON 0x68 98 #define LCD_CONTRAST(c) (0x70 | (c & 0x0F)) 100 #define LCD_BUSY_FLAG_MASK 0x80 101 #define LCD_ADDRESS_MASK 0x7F 107 const uint8_t line_address[] = {LCD_ADDRESS_LINE_1, LCD_ADDRESS_LINE_2};
110 uint8_t change_position =
false;
126 void dev_Lcd_Initialize(
void)
128 drv_LcdInterface_Initialize();
129 drv_LcdInterface_Reset();
131 drv_LcdInterface_SendCmd(LCD_FUNCTION | FUNCTION_8BITS | FUNCTION_1_HIGH | FUNCTION_1_LINE | FUNCTION_nIS);
135 drv_LcdInterface_SendCmd(LCD_FUNCTION | FUNCTION_8BITS | FUNCTION_1_HIGH | FUNCTION_1_LINE | FUNCTION_nIS);
136 drv_LcdInterface_SendCmd(LCD_FUNCTION | FUNCTION_8BITS | FUNCTION_1_HIGH | FUNCTION_1_LINE | FUNCTION_nIS);
139 drv_LcdInterface_SendCmd(LCD_FUNCTION | FUNCTION_8BITS | FUNCTION_1_HIGH | FUNCTION_2_LINE | FUNCTION_IS);
140 drv_LcdInterface_SendCmd(LCD_OSC_FREQ | BIAS_1_5 | FREQ_CNTRL(4));
141 drv_LcdInterface_SendCmd(LCD_PWR_CONTROL | nICON | BOOSTLCD | CONTRAST(2));
142 drv_LcdInterface_SendCmd(LCD_FOLLOWER_ON | FOLLOWER_GAIN(5));
143 drv_LcdInterface_SendCmd(LCD_CONTRAST(0));
147 drv_LcdInterface_SendCmd(LCD_DISPLAY_ON | CURSOR_OFF | BLINK_OFF);
148 drv_LcdInterface_SendCmd(LCD_ENTRY_MODE | CURSOR_nSHIFT | DATA_INCREMENT);
149 drv_LcdInterface_SendCmd(LCD_CLEAR);
166 void dev_Lcd_Clear(
void)
168 drv_LcdInterface_SendCmd(LCD_CLEAR);
184 void dev_Lcd_GotoXY(
volatile uint8_t x,
volatile uint8_t y)
186 drv_LcdInterface_SendCmd(LCD_DDRAM_ADDRESS((line_address[y] + x)));
189 change_position =
false;
209 void dev_Lcd_WriteChar(
const char ch)
213 dev_Lcd_GotoXY(pos_x, pos_y);
214 change_position =
false;
223 change_position =
false;
228 change_position =
true;
232 change_position =
true;
236 change_position =
true;
239 if (pos_x < LCD_DISPLAYSIZE_X && pos_y < LCD_DISPLAYSIZE_Y)
240 drv_LcdInterface_SendChar(ch);
241 if (++pos_x >= LCD_DISPLAYSIZE_X)
245 change_position =
true;
272 void dev_Lcd_WriteString(
const char *str)
276 dev_Lcd_WriteChar(*str);
305 void dev_Lcd_WriteStringXY(
volatile uint8_t column_index,
volatile uint8_t line_index,
const char *str)
307 dev_Lcd_GotoXY(column_index, line_index);
308 dev_Lcd_WriteString(str);