دوستان کسی کتاب خانه برای lcd16*2 بر اساس کتابخانه hal دارد؟؟
برای stm32f103 میخام!!
برای stm32f103 میخام!!
#include "stm32f1xx_hal.h"[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_GPIO GPIOA/* Connections between LCD and STM32F373cct6 */[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_RS GPIO_PIN_1[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_RW GPIO_PIN_2[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_EN GPIO_PIN_3[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D4 GPIO_PIN_4[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D5 GPIO_PIN_5[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D6 GPIO_PIN_6[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D7 GPIO_PIN_7[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_PORT LCD_GPIO // Port that is connected the LCD (current port is PORT B)[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D_ALL (GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6| GPIO_PIN_7)void delay_ms(int ms);void delay_us(int us);unsigned char LCD_ReadByte(void);void LCD_SendByte(unsigned char cmd);void LCD_SendCmd (unsigned char cmd);void LCD_SendData(unsigned char data);void LCD_SendText(char x,char y,char *text);void LCD_GoTo (unsigned char line, unsigned char column);void LCD_Clear (void);void LCD_Init (void);
#include "stm32f1xx_hal.h"
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_GPIO GPIOA
/* Connections between LCD and STM32F373cct6 */
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_RS GPIO_PIN_1
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_RW GPIO_PIN_2
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_EN GPIO_PIN_3
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D4 GPIO_PIN_4
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D5 GPIO_PIN_5
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D6 GPIO_PIN_6
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D7 GPIO_PIN_7
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_PORT LCD_GPIO // Port that is connected the LCD (current port is PORT B)
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] LCD_D_ALL (GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6| GPIO_PIN_7)
void delay_ms(int ms);
void delay_us(int us);
unsigned char LCD_ReadByte(void);
void LCD_SendByte(unsigned char cmd);
void LCD_SendCmd (unsigned char cmd);
void LCD_SendData(unsigned char data);
void LCD_SendText(char x,char y,char *text);
void LCD_GoTo (unsigned char line, unsigned char column);
void LCD_Clear (void);
void LCD_Init (void);
#include "HD44780.h"
const char UserFont[8][8] = { /* 8 user defined characters to be loaded into CGRAM (used for bargraph)*/
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
{ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10 },
{ 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18 },
{ 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C },
{ 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E },
{ 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F },
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
};
//==========================================================================================
//
//==========================================================================================
void delay_ms(int ms)
{
long i, tms;
tms = 9000*ms;
for(i=0;i<tms;i++);
}
//==========================================================================================
//
//==========================================================================================
void delay_us(int us)
{
long i, tus;
tus = 9*us;
for(i=0;i<tus;i++);
}
//==========================================================================================
//
//==========================================================================================
uint8_t LCD_ReadByte(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
uint8_t ReadedData=0;
HAL_GPIO_WritePin(LCD_PORT, LCD_D_ALL,GPIO_PIN_SET);
GPIO_InitStruct.Pin = LCD_D4|LCD_D5|LCD_D6|LCD_D7;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(LCD_GPIO, &GPIO_InitStruct);
HAL_GPIO_WritePin(LCD_PORT, LCD_RW,GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_SET);
if(HAL_GPIO_ReadPin(LCD_PORT, LCD_D7))
ReadedData |= 0x80;
if(HAL_GPIO_ReadPin(LCD_PORT, LCD_D6))
ReadedData |= 0x40;
if(HAL_GPIO_ReadPin(LCD_PORT, LCD_D5))
ReadedData |= 0x20;
if(HAL_GPIO_ReadPin(LCD_PORT, LCD_D4))
ReadedData |= 0x10;
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_RESET);
delay_us(50);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_SET);
if(HAL_GPIO_ReadPin(LCD_PORT, LCD_D7))
ReadedData |= 0x08;
if(HAL_GPIO_ReadPin(LCD_PORT, LCD_D6))
ReadedData |= 0x04;
if(HAL_GPIO_ReadPin(LCD_PORT, LCD_D5))
ReadedData |= 0x02;
if(HAL_GPIO_ReadPin(LCD_PORT, LCD_D4))
ReadedData |= 0x01;
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_RESET);
GPIO_InitStruct.Pin = LCD_D4|LCD_D5|LCD_D6|LCD_D7;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(LCD_GPIO, &GPIO_InitStruct);
return ReadedData;
}
//==========================================================================================
//
//==========================================================================================
void LCD_SendByte(uint8_t cmd)
{
uint8_t tcmd = 0;
HAL_GPIO_WritePin(LCD_PORT, LCD_RW,GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_PORT, LCD_D_ALL,GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_SET);
tcmd = cmd >> 4;
if( tcmd & 0x01 )
HAL_GPIO_WritePin(LCD_PORT, LCD_D4,GPIO_PIN_SET);
if( tcmd & 0x02 )
HAL_GPIO_WritePin(LCD_PORT, LCD_D5,GPIO_PIN_SET);
if( tcmd & 0x04 )
HAL_GPIO_WritePin(LCD_PORT, LCD_D6,GPIO_PIN_SET);
if( tcmd & 0x08 )
HAL_GPIO_WritePin(LCD_PORT, LCD_D7,GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_RESET);
delay_us(50);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_PORT, LCD_D_ALL,GPIO_PIN_RESET);
cmd &= 0x0F;
if( cmd & 0x01 )
HAL_GPIO_WritePin(LCD_PORT, LCD_D4,GPIO_PIN_SET);
if( cmd & 0x02 )
HAL_GPIO_WritePin(LCD_PORT, LCD_D5,GPIO_PIN_SET);
if( cmd & 0x04 )
HAL_GPIO_WritePin(LCD_PORT, LCD_D6,GPIO_PIN_SET);
if( cmd & 0x08 )
HAL_GPIO_WritePin(LCD_PORT, LCD_D7,GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_PORT, LCD_D_ALL,GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_PORT, LCD_RS,GPIO_PIN_RESET);
while(LCD_ReadByte() & 0x80);
}
//==========================================================================================
//
//==========================================================================================
void LCD_SendCmd(uint8_t cmd)
{
HAL_GPIO_WritePin(LCD_PORT, LCD_RS,GPIO_PIN_RESET);
delay_us(50);
LCD_SendByte(cmd);
}
//==========================================================================================
//
//==========================================================================================
void LCD_SendData(uint8_t data)
{
HAL_GPIO_WritePin(LCD_PORT, LCD_RS,GPIO_PIN_SET);
delay_us(50);
LCD_SendByte(data);
}
//==========================================================================================
// print a string on LCD.
//==========================================================================================
void LCD_SendText(char x,char y,char *text)
{
LCD_GoTo(x,y);
while(*text)
{
LCD_SendData(*text);
text++;
}
}
//==========================================================================================
// Clear the LCD display.
//==========================================================================================
void LCD_Clear(void)
{
LCD_SendCmd(0x01);
}
//==========================================================================================
// Set cursor position on LCD display.
//==========================================================================================
void LCD_GoTo (unsigned char line, unsigned char column)
{
uint8_t position = 0;
position = (line * 0x40) + column;
position = 0x80 + (position & 0x7F);
LCD_SendCmd(position);
}
//==========================================================================================
// Initialize the LCD.
//==========================================================================================
void LCD_Init(void)
{
uint8_t i;
char const *p;
GPIO_InitTypeDef GPIO_InitStruct;
__GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = (LCD_D7 | LCD_D6 | LCD_D5 | LCD_D4 | LCD_EN | LCD_RW | LCD_RS);
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(LCD_GPIO, &GPIO_InitStruct);
delay_ms(30);
HAL_GPIO_WritePin(LCD_PORT, LCD_RS,GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_RESET);
for(i = 0; i<3; i++)
{
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_PORT, LCD_D4 | LCD_D5,GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_PORT, LCD_D6 | LCD_D7,GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_RESET);
}
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_SET);
delay_ms(50);
HAL_GPIO_WritePin(LCD_PORT, LCD_D5,GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_PORT,LCD_D4 | LCD_D6 | LCD_D7,GPIO_PIN_RESET);
delay_ms(50);
HAL_GPIO_WritePin(LCD_PORT, LCD_EN,GPIO_PIN_RESET);
LCD_SendCmd(0x28);
LCD_SendCmd(0x08);
LCD_SendCmd(0x01);
LCD_SendCmd(0x06);
LCD_SendCmd(0x0C); //
delay_ms(5);
/* Load user-specific characters into CGRAM */
LCD_SendCmd(0x40); /* Set CGRAM address counter to 0 */
p = &UserFont[0][0];
for (i = 0; i < sizeof(UserFont); i++, p++)
LCD_SendData (*p);
LCD_SendCmd(0x80); /* Set DDRAM address counter to 0 */
}
دیدگاه