/******************************************************************************/ /* 项目名称 : TX-1C扩展板 超声波测距 */ /* 主控芯片 : STC89C52 */ /* 文件名称 : 1602 */ /* 文件功能 : 1602液晶操作 */ /* 文件版权 : 北京天祥微控电子有限公司 */ /* 文件版本 : */ /******************************************************************************/ /************************************宏定义************************************/ #define uchar unsigned char #define uint unsigned int /************************************位定义************************************/ sbit dula = P2^6; sbit wela = P2^7; sbit rs = P3^5; sbit lcden = P3^4; /******************************************************************************/ /* 函数名称 : delay */ /* 函数描述 : 延时函数 */ /* 输入参数 : x */ /* 参数描述 : 延时时间 */ /* 返回值 : 无 */ /******************************************************************************/ void delay(uint x) { uint a,b; for(a = x;a > 0;a--) { for(b = 10;b > 0;b--) { ; } } } /******************************************************************************/ /* 函数名称 : write_com */ /* 函数描述 : 1602写命令函数 */ /* 输入参数 : com */ /* 参数描述 : 控制命令 */ /* 返回值 : 无 */ /******************************************************************************/ void write_com(uchar com) { P0 = com; rs = 0; lcden = 0; delay(10); lcden = 1; delay(10); lcden = 0; } /******************************************************************************/ /* 函数名称 : write_date */ /* 函数描述 : 1602写数据函数 */ /* 输入参数 : date */ /* 参数描述 : 要写入的数据 */ /* 返回值 : 无 */ /******************************************************************************/ void write_date(uchar date) { P0 = date; rs = 1; lcden = 0; delay(10); lcden = 1; delay(10); lcden = 0; } /******************************************************************************/ /* 函数名称 : initLCD */ /* 函数描述 : 1602初始化函数 */ /* 输入参数 : 无 */ /* 参数描述 : 无 */ /* 返回值 : 无 */ /******************************************************************************/ void initLCD(void) { dula = 0; wela = 0; write_com(0x38); delay(20); write_com(0x0f); delay(20); write_com(0x06); delay(20); write_com(0x01); delay(20); } /******************************************************************************/