#include "lcd_1602.h" static void delay_us(uint32_t delay){ delay*=32; while(delay--); } static void lcd_send_4bit(uint8_t data) { if(data & 0x10) d4(1); else d4(0); if(data & 0x20) d5(1); else d5(0); if(data & 0x40) d6(1); else d6(0); if(data & 0x80) d7(1); else d7(0); } static void lcd_send(int8_t rs,uint8_t data){ // rs : 1=data | 2=command // rw : 0=write | 1=read // en : 1=senddata | 0=donothing rs(rs); rw(0); lcd_send_4bit(data); //MSB en(1); delay_us(100); en(0); lcd_send_4bit(data<<4); //LSB en(1); delay_us(100); en(0); } void lcd_cmd(uint8_t command){ lcd_send(1,command); } void lcd_data(char c){ lcd_send(1,(uint8_t)c); } void lcd_init(void){ //bl(1); // lcd_send(0x22); // 4 bit initialisation lcd_send(0,0x20); // 4bit mode HAL_Delay(10); // Display initialisation lcd_send(0,0x28); // Function set --> DL=0 (4 bit mode), N = 1 (2 line display) F = 0 (5x8 characters) HAL_Delay(1); lcd_send(0,0x08); //Display on/off control --> D=0,C=0, B=0 ---> display off HAL_Delay(1); lcd_send(0,0x01); // clear display HAL_Delay(2); lcd_send(0,0x06); //Entry mode set --> I/D = 1 (increment cursor) & S = 0 (no shift) HAL_Delay(1); lcd_send(0,0x0C); //Display on/off control --> D = 1, C and B = 0. (Cursor and blink, last two bits) HAL_Delay(2); } void lcd_clr(void){ lcd_send(0,0x01); HAL_Delay(2); } void lcd_gotoxy(char x, char y){ lcd_send(0,0x80+x+(y*0x40)); HAL_Delay(2); } void lcd_puts(char *text){ while (*text) lcd_data (*text++); }