|
对比度调过了,硬件连接也跟仿真一样没啥问题,大佬们帮我看看程序哪里有问题,急!!!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);
}
}
|
|