標(biāo)題:
LCD1602顯示一排黃方塊
[打印本頁(yè)]
作者:
xxhp
時(shí)間:
2023-5-14 20:09
標(biāo)題:
LCD1602顯示一排黃方塊
對(duì)比度調(diào)過(guò)了,硬件連接也跟仿真一樣沒(méi)啥問(wèn)題,大佬們幫我看看程序哪里有問(wèn)題,急。!lcd1602.c
#include "bsp-lcd1602.h"
void LCD1602_GPIO_Config(void)
{
RCC_APB2PeriphClockCmd(LCD1602_CLK, ENABLE);
GPIO_InitTypeDef LCD1602_GPIOStruct;
LCD1602_GPIOStruct.GPIO_Mode = GPIO_Mode_Out_PP;
LCD1602_GPIOStruct.GPIO_Speed = GPIO_Speed_10MHz;
LCD1602_GPIOStruct.GPIO_Pin = LCD1602_E | LCD1602_RS | LCD1602_RW ;
GPIO_Init(LCD1602_GPIO_PORT,&LCD1602_GPIOStruct);
LCD1602_GPIOStruct.GPIO_Mode = GPIO_Mode_Out_OD;
LCD1602_GPIOStruct.GPIO_Pin = DB0 | DB1 | DB2 |DB3 | DB4 | DB5|
DB6 | DB7 ;
GPIO_Init(LCD1602_GPIO_PORT,&LCD1602_GPIOStruct);
}
void LCD1602_WaitReady(void
{
uint8_t sta;
GPIOB->ODR =0x00FF;
RSO(0);
RWO(1);
EO(1);
SysTick_Delay_Us(1);
do{
sta=GPIO_ReadInputDataBit(LCD1602_GPIO_PORT,GPIO_Pin_7);
EO(0);
}while(sta);
}
void LCD1602_WriteCmd(uint8_t cmd
{
LCD1602_WaitReady();
RSO(0);
RWO(0);
EO(0);
SysTick_Delay_Us(1);
EO(1);
LCD1602_GPIO_PORT->ODR &= (cmd|0xFF00);
EO(0);
SysTick_Delay_Us(400);
}
void LCD1602_WriteDat(uint8_t dat
{
LCD1602_WaitReady();
RSO(1);
RWO(0);
SysTick_Delay_Us(30);
EO(1);
LCD1602_GPIO_PORT->ODR &=(dat|0xFF00);
EO(0);
SysTick_Delay_Us(400);
}
void LCD1602_SetCursor(uint8_t x, uint8_t y)
{
uint8_t addr;
if (y == 0)
addr = 0x00 + x;
else
addr = 0x40 + x;
LCD1602_WriteCmd(addr|0x80);
}
void LCD1602_ShowStr(uint8_t x, uint8_t y, uint8_t *str, uint8_t len)
{
LCD1602_SetCursor(x, y);
while (len--)
{
LCD1602_WriteDat(*str++);
}
}
void LCD_ShowNum(uint8_t x, uint8_t y,uint8_t num)
{
LCD1602_SetCursor(x, y);
LCD_ShowChar(x,y,num+'0');
}
void LCD_ShowChar(uint8_t x, uint8_t y,uint8_t dat)
{
LCD1602_SetCursor(x, y);
LCD1602_WriteDat(dat);
}
void LCD1602_Init(void)
{
LCD1602_GPIO_Config();
LCD1602_WriteCmd(0X38);
LCD1602_WriteCmd(0x0C);
LCD1602_WriteCmd(0x06);
LCD1602_WriteCmd(0x01);
}
main.c
#include "stm32f10x.h"
#include "bsp-lcd1602.h"
#include "delay.h"
#include "sys.h"
#include "adc.h"
#define LED PAout(3)
#define KEY1 PAin(8)
#define KEY2 PAin(9)
#define KEY3 PAin(10)
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_3);
}
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
int main(void)
{
int a,b,c,d;
float temp;
delay_init();
LCD1602_Init();
ADC1_GPIO_Config();
ADC_Config();
LCD1602_ShowStr(2,0,"Qiti=0.0mg/L",13);
LED_Init();
KEY_Init();
while(1)
{
b=ADC_GetConversionValue(ADC1);
temp=(float)b*(3.4/4096);
a=temp/1;
c=temp*10;
d=c%10;
LCD_ShowNum(7,0,a);
LCD_ShowNum(9,0,d);
if(KEY3==0)
{
if(temp>2) LED=1;
else LED=0;
}
else
{
if(KEY1==0) LED=1;
if(KEY2==0) LED=0;
}
delay_ms(200);
}
}
456.jpg
(66.93 KB, 下載次數(shù): 32)
下載附件
2023-5-14 20:09 上傳
作者:
heicad
時(shí)間:
2023-5-14 22:04
來(lái)看一下51hei論壇里面解決此問(wèn)題的痛苦經(jīng)歷吧:
51hei搜索框輸入"1602 方塊"或者"1602 黑塊"或者"1602 白塊"或者"1602 格":
這個(gè)是io口設(shè)置問(wèn)題,最終搞定了:
http://www.torrancerestoration.com/bbs/dpj-199732-1.html
http://www.torrancerestoration.com/bbs/dpj-168643-1.html
http://www.torrancerestoration.com/bbs/dpj-208189-1.html
http://www.torrancerestoration.com/bbs/dpj-210690-1.html
既有可能是軟件問(wèn)題也有硬件問(wèn)題
http://www.torrancerestoration.com/bbs/dpj-187378-1.html
http://www.torrancerestoration.com/bbs/dpj-160754-1.html
作者:
devcang
時(shí)間:
2023-5-15 10:02
調(diào)節(jié)顯示對(duì)比度
作者:
man1234567
時(shí)間:
2023-5-15 15:27
知道對(duì)比度調(diào)過(guò)了,可以再調(diào)回來(lái)。
也可以本壇搜索找一下成功的例子。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1