1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include "lcd1602.h"
static void LCD1602_Cmd(uint8_t cmd) { EN_LOW; RS_LOW; GPIO_Write(Dx_PORT, cmd); EN_HIGH; Delay_ms(15); EN_LOW; GPIO_Write(Dx_PORT, cmd<<4); EN_HIGH; Delay_ms(15); EN_LOW; }
static void LCD1602_Data(uint8_t data) { EN_LOW; RS_HIGH; GPIO_Write(Dx_PORT, data); EN_HIGH; Delay_ms(15); EN_LOW; GPIO_Write(Dx_PORT, data<<4); EN_HIGH; Delay_ms(15); EN_LOW; }
void LCD1602_Init(void) { GPIO_Init(Dx_PORT, (GPIO_Pin_TypeDef)Dx_FOUR_PINS, GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(Rx_PORT, (GPIO_Pin_TypeDef)Rx_FOUR_PINS, GPIO_MODE_OUT_PP_HIGH_FAST);
LCD1602_Cmd(0x20); Delay_ms(20); LCD1602_Cmd(0x28); Delay_ms(20); LCD1602_Cmd(0x01); LCD1602_Cmd(0x06); LCD1602_Cmd(0x0C); }
static void LCD1602_SetCursor(uint8_t x, uint8_t y) { LCD1602_Cmd(x + (y ? LINE1:LINE0)); }
void LCD1602_PrintStr(uint8_t x, uint8_t y, uint8_t *str) { LCD1602_SetCursor(x, y); while(*str != '\0') { LCD1602_Data(*str++); } }
|