那是一个判忙,要比delay有效率,51判忙前要先置高电平,不同的主频时序上不太一样.
#include "LCDDriver.h"
/*//以下参数在19660800M晶振频率时测试,数值为手册标值
#define DELAY {_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}
#define TAS DELAY;//{}; //140ns
#define TDSW DELAY;DELAY;DELAY;DELAY;DELAY;DELAY;//195ns
#define TWEN DELAY;DELAY; //450ns
*/
//晶振12M
#define DELAY {_nop_();_nop_();_nop_();}
#define TAS DELAY;//{};
#define TDSW DELAY;DELAY;DELAY;DELAY;DELAY;DELAY;
#define TWEN DELAY;DELAY;
void LCD1602_Write_Command(uint8 cmd)
{
lcd_rw=1;
TAS;
do {
lcd_en=0;
lcd_en=1;
TWEN;
}while (LCD_BUSYBIT); //end check busy
DATA_PORT = cmd;
TDSW;
lcd_rw=0;
TAS;
lcd_en=0;
DATA_PORT = 0xff;
}
void LCD1602_Write_Data(uint8 dat)
{
lcd_rw=1;
TAS;
do {
lcd_en=0;
lcd_en=1;
TWEN;
} while (LCD_BUSYBIT);//end check busy
DATA_PORT = dat;
TDSW;
lcd_rs=1;
lcd_rw=0;
TAS;
lcd_en=0;
DATA_PORT = 0xff;
lcd_rs=0;
}
//LCD1602的初始化函数
void LCD1602_Init(uint8 mode)
{
uint16 i=0;
lcd_rs=0;
while (--i); //初始化等待
LCD1602_Write_Command(0x38);/*设置8位格式,2行,5*7*/
LCD1602_Write_Command(0x01);/*清除显示*/
LCD1602_Write_Command(0x06);/*设定输入方式,增量不移位*/
LCD1602_Write_Command(mode);/*0x0c整体显示,关光标,不闪烁*/
}
|