参考代码: (用了8个月左右了)
------------------------------文件lcd1602.c-----------------------
#include "lcd1602.h"
#include "main.h"
#include "delay.h"
extern unsigned char lcd_code;
extern unsigned char flg_showcard;
void LCD_wait_Ready(void) //等待LCD空闲
{
LCD_DATA_DDR &= ~0x80; //PD7 I/O口方向设置为输入
//LCD_RW_PORT |= LCD_RW; //RW=1
LCD_RS_PORT &= ~LCD_RS; //RS=0
LCD_EN_PORT |= LCD_EN; //EN=1
while (!( LCD_DATA_PIN&0x80 ) == 0); //RW=1,读PD7,为0表示空闲;
LCD_EN_PORT &= ~LCD_EN; //EN=0
LCD_DATA_DDR |= 0xf0;
}
void LCD_init(void)
{
unsigned int i=0;
//DDRA|=LCD_DATA; // 数据为输出