本帖最后由 siabc 于 2013-10-2 12:53 编辑
下面为我的驱动程序,在1602液晶上不显示字母a啊,求大家给看看,哪里写的不对啊,我用示波器看脉冲似乎是对的,疑惑
#include "stm32f10x.h"
#define uchar unsigned char
#define uint unsigned int
#define EN_Enable GPIO_WriteBit(GPIOB,GPIO_Pin_12, Bit_SET); //lcden使能
#define EN_Disable GPIO_WriteBit(GPIOB,GPIO_Pin_12, Bit_RESET);
#define RS_Enable GPIO_WriteBit(GPIOB,GPIO_Pin_13, Bit_SET); //rs使能
#define RS_Disable GPIO_WriteBit(GPIOB,GPIO_Pin_13, Bit_RESET);
#define WR_Enable GPIO_WriteBit(GPIOB,GPIO_Pin_14, Bit_SET); //写指令
#define WR_Disable GPIO_WriteBit(GPIOB,GPIO_Pin_14, Bit_RESET);
void delay()
{
unsigned int i;
char j=0;
for(j=0;j<10;j++)
for(i=0;i<1100;i++);
}
void Write_Com(uchar dat) //写命令
{
RS_Disable;
delay();
EN_Disable;
delay();
WR_Disable;
delay();
GPIOC->ODR=dat; //这里给PORTC复制是不是这么写的??
delay();
EN_Enable;
delay();
delay();
}
void Write_Dat(uchar dat) //写数据
{
RS_Enable;
delay();
EN_Disable;
delay();
WR_Disable;
delay();
GPIOC->ODR=dat; //这里给PORTC复制是不是这么写的??
delay();
EN_Enable;
delay();
delay();
}
void LCD_Init()
{
RS_Disable;
delay();
WR_Disable;
delay();
EN_Disable;
delay();
Write_Com(0x38);
Write_Com(0x0c);
Write_Com(0x06);
Write_Com(0x01);
Write_Com(0x80);
}
int main()
{
GPIO_InitTypeDef my_GPIO; //my_GPIO是结构体变量
my_GPIO.GPIO_Pin=GPIO_Pin_All;
my_GPIO.GPIO_Speed=GPIO_Speed_10MHz;
my_GPIO.GPIO_Mode=GPIO_Mode_Out_PP;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB,ENABLE);
GPIO_Init(GPIOC,&my_GPIO);//PORTC为RS,RW,LCDEN
GPIO_Init(GPIOB,&my_GPIO);//PORTB为数据端(只取低八位)
LCD_Init();
while(1)
{
Write_Com(0x80);//写地址
Write_Dat('a');//写数据
}
}
|