BASIC4MCU | 질문게시판 | lcd 모니터를 내려서 표기하
페이지 정보
작성자 수포자 작성일2023-04-06 19:29 조회1,535회 댓글5건본문
안녕하세요 stm32의 가지고 코딩중입니다
lcd모니터에가다 영어를 아래줄에 나타내는 방법이 궁금하고
void lcd char(char s) ->하나 나타내는 함수
void lcd char(char x, char, y) 16비트중 원하는곳에 나타내는 함수
{ GPIO_ResetBits(GPIOB, TLCD_RS);
GPIO_ResetBits(GPIOB, TLCD_RW);
if(y==0) GPIO_Write(DATA, x+0x80);
else if(y==1) GPIO_Write(DATA, x+0xc0);
E_Pules();
}
등 이걸 실행시킬려면 기존에 있는 코드를 지우고 수정하는건지 추가하는건지 알려주시면 감사합니다
추가도 해보고 기존에 있는걸 지워서 수정해도 계속 오류가 나서 뭔지를 모르겠습니다...
#include "stm32f4xx.h"
#define TLCD_RS GPIO_Pin_0 //LCD RS 신호
#define TLCD_RW GPIO_Pin_1 //LCD RW 신호
#define TLCD_E GPIO_Pin_2 //LCD E 신호
#define TLCD_EN { GPIO_ResetBits(GPIOB, TLCD_E); GPIO_SetBits(GPIOB, TLCD_E);}
#define DATA GPIOC
// delay 함수
static void Delay(const uint32_t Count)
{
__IO uint32_t index = 0;
for(index = (16800 * Count); index != 0; index--);
}
static void Delay_us(const uint32_t Count)
{
__IO uint32_t index = 0;
for(index = (16 * Count); index != 0; index--);
}
void Port_lnit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|
GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void E_Pulse(void)
{
GPIO_SetBits(GPIOB, TLCD_E);
Delay(5);
GPIO_ResetBits(GPIOB, TLCD_E);
}
void TLCD_DATA(unsigned char data)
{
GPIO_Write(DATA, data);
TLCD_EN;
}
void Func_Set(void)
{
GPIO_ResetBits(GPIOB, TLCD_RW);
GPIO_ResetBits(GPIOB, TLCD_RS);
GPIO_Write(DATA, 0x38);
E_Pulse();
}
void lnit_LCD(void)
{
GPIO_ResetBits(GPIOB, TLCD_E);
Delay(15);
Func_Set();
Delay(10);
Func_Set();
Delay_us(150);
Func_Set();
GPIO_Write(DATA, 0x0f);
E_Pulse();
GPIO_Write(DATA, 0x06);
E_Pulse();
GPIO_Write(DATA, 0x01);
E_Pulse();
}
void lcd_char(char s)
{
GPIO_SetBits(GPIOB, TLCD_RS);
GPIO_Write(DATA, s);
E_Pulse();
}
int main()
{
Port_lnit();
lnit_LCD();
lcd_char('1');
lcd_char('2');
lcd_char('3');
lcd_char('4');
while(1);
}
댓글 5
조회수 1,535master님의 댓글
master 작성일
#include "stm32f4xx.h"
//
#define TLCD_RS GPIO_Pin_0 //LCD RS 신호
#define TLCD_RW GPIO_Pin_1 //LCD RW 신호
#define TLCD_E GPIO_Pin_2 //LCD E 신호
#define TLCD_EN {GPIO_ResetBits(GPIOB,TLCD_E); GPIO_SetBits(GPIOB,TLCD_E);}
#define DATA GPIOC
//
static void Delay_ms(const uint32_t Count){ __IO uint32_t index=0; for(index=(16800*Count);index!=0;index--); }
static void Delay_us(const uint32_t Count){ __IO uint32_t index=0; for(index=( 16*Count);index!=0;index--); }
//
void Port_lnit(void){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
//
void E_Pulse(void){ GPIO_SetBits(GPIOB,TLCD_E); Delay(5); GPIO_ResetBits(GPIOB,TLCD_E); Delay(5); }
//
void LCD_INST(unsigned char d){ GPIO_ResetBits(GPIOB,TLCD_RW); GPIO_ResetBits(GPIOB,TLCD_RS); GPIO_Write(DATA,d); E_Pulse(); }
void LCD_DATA(unsigned char d){ GPIO_ResetBits(GPIOB,TLCD_RW); GPIO_SetBits(GPIOB,TLCD_RS); GPIO_Write(DATA,d); E_Pulse(); }
void LCD_Str(unsigned char *s){ while(*s)TLCD_DATA(*s++); }
//
//
void lnit_LCD(void){
GPIO_ResetBits(GPIOB,TLCD_E); Delay(15);
LCD_INST(0x38); Delay(10); LCD_INST(0x38); Delay_us(150); LCD_INST(0x38);
LCD_INST(0x0f);
LCD_INST(0x06);
LCD_INST(0x01);
}
//
void lcd_char(char s){
GPIO_SetBits(GPIOB,TLCD_RS); GPIO_Write(DATA,s); E_Pulse();
}
//
int main(){
Port_lnit();
lnit_LCD();
LCD_INST(0x80); LCD_Str("Lcd Test");
LCD_INST(0xC0); LCD_Str("1234");
while(1);
}
수포자님의 댓글
수포자
#include "stm32f4xx.h"
//
#define TLCD_RS GPIO_Pin_0 //LCD RS 신호
#define TLCD_RW GPIO_Pin_1 //LCD RW 신호
#define TLCD_E GPIO_Pin_2 //LCD E 신호
#define TLCD_EN {GPIO_ResetBits(GPIOB,TLCD_E); GPIO_SetBits(GPIOB,TLCD_E);}
#define DATA GPIOC
//
static void Delay(const uint32_t Count){ __IO uint32_t index=0; for(index=(16800*Count);index!=0;index--); }
static void Delay_us(const uint32_t Count){ __IO uint32_t index=0; for(index=( 16*Count);index!=0;index--); }
//
void Port_lnit(void){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
//
void E_Pulse(void){ GPIO_SetBits(GPIOB,TLCD_E); Delay(5); GPIO_ResetBits(GPIOB,TLCD_E); Delay(5); }
//
void LCD_INST(unsigned char d){ GPIO_ResetBits(GPIOB,TLCD_RW); GPIO_ResetBits(GPIOB,TLCD_RS); GPIO_Write(DATA,d); E_Pulse(); }
void LCD_DATA(unsigned char d){ GPIO_ResetBits(GPIOB,TLCD_RW); GPIO_SetBits(GPIOB,TLCD_RS); GPIO_Write(DATA,d); E_Pulse(); }
void LCD_Str(unsigned char *s){ while(*s);LCD_DATA(*s++); }
//
//
void TLCD_DATA(unsigned char data)
{
GPIO_Write(DATA, data);
TLCD_EN;
}
void lnit_LCD(void){
GPIO_ResetBits(GPIOB,TLCD_E); Delay(15);
LCD_INST(0x38); Delay(10); LCD_INST(0x38); Delay_us(150); LCD_INST(0x38);
LCD_INST(0x0f);
LCD_INST(0x06);
LCD_INST(0x01);
}
//
void lcd_char(char s){
GPIO_SetBits(GPIOB,TLCD_RS); GPIO_Write(DATA,s); E_Pulse();
}
//
int main(){
Port_lnit();
lnit_LCD();
LCD_INST(0x80); LCD_Str("1234");
LCD_INST(0xC0); LCD_Str("test");
while(1);
}
마스터님 마스터님껄로 돌려봤는데 오류가 3개 떠서 이렇게 수정했습니다 그런데 화면에 안뜨는 이유가 뭔지 여쭤봐도 될까요?
수포자님의 댓글
수포자 작성일아 이진수를 대입해야 되는군요 감사합니다 아 그리고 여러개를 표기할려면 따음표도 배워갑니다
master님의 댓글
master
잘 되는가 봅니다.
수포자님의 댓글
수포자
// stm32f4xx의 각 레지스터들을 정의한 헤더파일
#include "stm32f4xx.h"
#define TLCD_RS GPIO_Pin_0 //LCD RS 신호
#define TLCD_RW GPIO_Pin_1 //LCD RW 신호
#define TLCD_E GPIO_Pin_2 //LCD E 신호
#define TLCD_EN { GPIO_ResetBits(GPIOB, TLCD_E); GPIO_SetBits(GPIOB, TLCD_E);}
#define DATA GPIOC
// delay 함수
static void Delay(const uint32_t Count)
{
__IO uint32_t index = 0;
for(index = (16800 * Count); index != 0; index--);
}
static void Delay_us(const uint32_t Count)
{
__IO uint32_t index = 0;
for(index = (16 * Count); index != 0; index--);
}
void Port_lnit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|
GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void E_Pulse(void)
{
GPIO_SetBits(GPIOB, TLCD_E);
Delay(5);
GPIO_ResetBits(GPIOB, TLCD_E);
}
void TLCD_DATA(unsigned char data)
{
GPIO_Write(DATA, data);
TLCD_EN;
}
void Func_Set(void)
{
GPIO_ResetBits(GPIOB, TLCD_RW);
GPIO_ResetBits(GPIOB, TLCD_RS);
GPIO_Write(DATA, 0x38);
E_Pulse();
}
void lnit_LCD(void)
{
GPIO_ResetBits(GPIOB, TLCD_E);
Delay(15);
Func_Set();
Delay(10);
Func_Set();
Delay_us(150);
Func_Set();
GPIO_Write(DATA, 0x0f);
E_Pulse();
GPIO_Write(DATA, 0x06);
E_Pulse();
GPIO_Write(DATA, 0x01);
E_Pulse();
}
void lcd_char(char s)
{
GPIO_SetBits(GPIOB, TLCD_RS);
GPIO_Write(DATA, s);
E_Pulse();
}
void lcd_disp(char x, char y)
{ GPIO_ResetBits(GPIOB, TLCD_RS);
GPIO_ResetBits(GPIOB, TLCD_RW);
if(y==0) GPIO_Write(DATA, x+0x80);
else if(y==1) GPIO_Write(DATA, x+0xc0);
E_Pulse();
}
int main()
{
Port_lnit();
lnit_LCD();
lcd_char('l');
lcd_char('s');
lcd_char('a')
lcd_char('n');
lcd_disp(0,1);
lcd_char('2');
lcd_char('0');
while(1);
}
이런식으로 고쳐서 했더니 나왔습니다 감사합니다!