Answer the question
In order to leave comments, you need to log in
Why not output image to lcd 16x2 in Proteus?
The library is working - it worked on a real lcd.
Moreover, if you turn off d4, it will start showing, but most of the symbols are not the same.
lcd.h
library
#include "stm32l0xx_hal.h"
#include "gpio.h"
#define d4_set() HAL_GPIO_WritePin(GPIOA, disp_d4_Pin, GPIO_PIN_SET)
#define d4_reset() HAL_GPIO_WritePin(GPIOA, disp_d4_Pin, GPIO_PIN_RESET)
#define d5_set() HAL_GPIO_WritePin(GPIOC, disp_d5_Pin, GPIO_PIN_SET)
#define d5_reset() HAL_GPIO_WritePin(GPIOC, disp_d5_Pin, GPIO_PIN_RESET)
#define d6_set() HAL_GPIO_WritePin(GPIOA, disp_d6_Pin, GPIO_PIN_SET)
#define d6_reset() HAL_GPIO_WritePin(GPIOA, disp_d6_Pin, GPIO_PIN_RESET)
#define d7_set() HAL_GPIO_WritePin(GPIOA, disp_d7_Pin, GPIO_PIN_SET)
#define d7_reset() HAL_GPIO_WritePin(GPIOA, disp_d7_Pin, GPIO_PIN_RESET)
#define e1 HAL_GPIO_WritePin(GPIOA, disp_e_Pin, GPIO_PIN_SET) // установка линии E в 1
#define e0 HAL_GPIO_WritePin(GPIOA, disp_e_Pin, GPIO_PIN_RESET) // установка линии E в 0
#define rs1 HAL_GPIO_WritePin(GPIOB, disp_rs_Pin, GPIO_PIN_SET) // установка линии RS в 1 (данные)
#define rs0 HAL_GPIO_WritePin(GPIOB, disp_rs_Pin, GPIO_PIN_RESET) // установка линии RS в 0 (команда)
void LCD_WriteData(uint8_t dt);
void delay(void);
void LCD_ini(void);
void LCD_Command(uint8_t dt);
void LCD_Data(uint8_t dt);
void LCD_Clear(void);
void LCD_SendChar(char ch);
void LCD_String(char* st);
void LCD_SetPos(uint8_t x, uint8_t y);
lcd.c
#include "lcd.h"
#include "gpio.h"
void delay(void)
{
uint16_t i;
for(i=0;i<1000;i++);
}
void LCD_Command(uint8_t dt)
{
rs0;
LCD_WriteData(dt>>4);
e1;
delay();
e0;
LCD_WriteData(dt);
e1;
delay();
e0;
}
void LCD_WriteData(uint8_t dt)
{
if(((dt >> 3)&0x01)==1) {d7_set();} else {d7_reset();}
if(((dt >> 2)&0x01)==1) {d6_set();} else {d6_reset();}
if(((dt >> 1)&0x01)==1) {d5_set();} else {d5_reset();}
if((dt&0x01)==1) {d4_set();} else {d4_reset();}
}
void LCD_ini(void)
{
HAL_Delay(40);
rs0;
LCD_WriteData(3);
e1;
delay();
e0;
HAL_Delay(1);
LCD_WriteData(3);
e1;
delay();
e0;
HAL_Delay(1);
LCD_WriteData(3);
e1;
delay();
e0;
HAL_Delay(1);
LCD_Command(0x28);//режим 4 бит, 2 линии (для нашего большого дисплея это 4 линии), шрифт 5х8
HAL_Delay(1);
LCD_Command(0x28);//еще раз для верности
HAL_Delay(1);
LCD_Command(0x0C);//дисплей включаем (D=1), также включаем пока все курсоры //0x0F - вкл курс
HAL_Delay(1);
LCD_Command(0x01);//уберем мусор
HAL_Delay(2);
LCD_Command(0x06);//пишем влево.
HAL_Delay(1);
LCD_Command(0x02);//возврат курсора в нулевое положение
HAL_Delay(2);
}
void LCD_Data(uint8_t dt)
{
rs1;
LCD_WriteData(dt>>4);
e1;
delay();
e0;
LCD_WriteData(dt);
e1;
delay();
e0;
}
void LCD_Clear(void)
{
LCD_Command(0x01);
HAL_Delay(2);
}
void LCD_SendChar(char ch)
{
LCD_Data((uint8_t) ch);
delay();
}
void LCD_String(char* st)
{
uint8_t i=0;
while(st[i]!=0)
{
LCD_Data(st[i]);
HAL_Delay(1);
i++;
}
}
void LCD_SetPos(uint8_t x, uint8_t y)
{
switch(y)
{
case 0:
LCD_Command(x|0x80);
HAL_Delay(1);
break;
case 1:
LCD_Command((0x40+x)|0x80);
HAL_Delay(1);
break;
default: break;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question