我的代码是这样的总是不成功,数据端口和三条控制端口都已经上拉10k到5 v了还是不能成功,看在我弄了好多天的份上就帮帮忙吧
[mw_shl_code=c,true]#include"sys.h"
#include"delay.h"
#include"lcd1602.h"
int main(void)
{
Stm32_Clock_Init(9);
delay_init(72);
delay_ms(500);
LCD1602_Init();
Write_Char(0,0,'j');
Write_Char(1,8,'j');
Write_String(1,1,"jsjl");
while(1);
}
[/mw_shl_code]
[mw_shl_code=c,true]#include"lcd1602.h"
#include"sys.h"
#include"delay.h"
/***********************************************************
RS------PC6
RW------PC7
EN------PC8
DATAOUT------PB0-7
***********************************************************/
void Write_Com(u8 com);
void LCD1602_Init(void)
{
RCC->APB2ENR|=1<<3; //PORTB
RCC->APB2ENR|=1<<4; //PORTC
GPIOB->CRL&=0X00000000; //开漏输出 PB0-7
GPIOB->CRL|=0X77777777;
GPIOB->ODR|=0X00FF;
GPIOC->CRL&=0X00FFFFFF; //PC6 PC7
GPIOC->CRL|=0X77000000;
GPIOC->ODR|=0X0C00;
GPIOC->CRH&=0XFFFFFFF0; // PC8
GPIOC->CRH|=0X00000007;
GPIOC->ODR|=0X0100;
Write_Com(0x38);delay_ms(15);
Write_Com(0x38);delay_ms(15);
Write_Com(0x38);delay_ms(15);
Write_Com(0x0c);
Write_Com(0x06);
Write_Com(0x01);
}void Write_Com(u8 com)
{
delay_ms(4);
LCD_RW=0;
LCD_RS=0;
LCD_EN=0;
LCD_EN=1;
GPIOB->ODR|=com&0x00ff;
delay_ms(2);
LCD_EN=0;
}
void Write_Data(u8 d)
{
delay_ms(4);
LCD_RW=0;
LCD_RS=1;
LCD_EN=0;
LCD_EN=1;
GPIOB->ODR|=d&0x00ff;
delay_ms(2);
LCD_EN=0;
}
void Write_Char(unsigned char x,unsigned char y,unsigned char ch)
{
if(y==0)
{
Write_Com(0x80+x);
}
else
{
Write_Com(0x80+0x40+x);
}
Write_Data(ch);
}
void Write_String(unsigned char x,unsigned char y,unsigned char * p)
{
while(*p)
{
Write_Char(x,y,*p);
x++;p++;
}
}
[/mw_shl_code]
[mw_shl_code=c,true]#ifndef __LCD1602_H
#define __LCD1602_H
#include"sys.h"
#define LCD_EN PCout(8)
#define LCD_RW PCout(7)
#define LCD_RS PCout(6)
#define DATAOUT(X) GPIOB->ODR=(GPIOB->ODR&0XFF00)|(X&0X00FF)
void LCD1602_Init(void);
void Write_Com(u8 com);
void Write_Char(u8 x,u8 y,u8 h);
void Write_String(unsigned char x,unsigned char y,unsigned char * p);
#endif
[/mw_shl_code]
|