初学STM32,买了块MINI板想试着驱动下1602液晶屏,写了个小程序改了半天,一直没有找到问题所在,
硬件除了GND和5V,RS接的C7,RW接的C5,E接的C6,数据线接的B0-B7,用了很多方法改程序,还是不行,
后来用万用表量了下,GPIOC 5 6 7不能按照代码中预期的输出高电平,GPIOB也无法正常控制输出,请问
各位高手,我问问题出在哪呢?
代码:
#include "stm32f10x.h"
typedef volatile unsigned char uint8;
typedef volatile unsigned int uint16;
typedef volatile unsigned long uint32;
#define LCD1602_RS0 GPIOC->BRR = 0x00000040;
#define LCD1602_RW0 GPIOC->BRR = 0x00000010;
#define LCD1602_EN0 GPIOC->BRR = 0x00000020;
#define LCD1602_RS1 GPIOC->BSRR = 0x00000040;
#define LCD1602_RW1 GPIOC->BSRR = 0x00000010;
#define LCD1602_EN1 GPIOC->BSRR = 0x00000020;
void Delay_us(uint32 Count)
{
signed char i;
while(Count--)
{
i = 10;
while(i--);
}
}
//写指令
void Write_LCD1602_Com(unsigned char Com)
{
LCD1602_RS0;
LCD1602_RW0;
LCD1602_EN0;
GPIOB->ODR = Com;
LCD1602_EN1;
Delay_us(340);
LCD1602_EN0;
}
//写数据
void Write_LCD1602_Data(unsigned char Data)
{
LCD1602_RS1;
LCD1602_RW0;
LCD1602_EN0;
GPIOB->ODR = Data;
LCD1602_EN1;
Delay_us(340);
LCD1602_EN0;
}
//重置液晶屏
void DISInit(void)
{
Write_LCD1602_Com(0x38);
Delay_us(6);
Write_LCD1602_Com(0x0C);
Delay_us(6);
Write_LCD1602_Com(0x06);
Delay_us(6);
Write_LCD1602_Com(0x01);
Delay_us(6);
}
int main(void)
{
*(unsigned int *)0X40021018 =0x0C; //配置GPIOB/C时钟
GPIOC->CRL |=((1<<(4*7))+(1<<(4*6))+(1<<(4*5)));
GPIOB->CRL |=((1<<(4*7))+(1<<(4*6))+(1<<(4*5))+(1<<(4*4))+(1<<(4*3))+(1<<(4*2))+(1<<(4*1))+(1<<(4*0)));
DISInit();
GPIOC->ODR &=~(1<<8);
GPIOB->ODR = 0x60;
while(1)
{
Write_LCD1602_Com(0x80+2); //写地址
Write_LCD1602_Data('A'); //液晶显示A
Write_LCD1602_Com(0x80+3);
Write_LCD1602_Data('A');
Delay_us(340);
Write_LCD1602_Com(0x80+4);
Write_LCD1602_Data('A');
Delay_us(340);
Write_LCD1602_Com(0x80+5);
Write_LCD1602_Data('A');
}
}
谢谢 |