完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
代码在此 #include #define LCD1602_DB P0 ***it LCD1602_RS = P1^0; ***it LCD1602_RW = P1^1; ***it LCD1602_E = P1^5; /* 等待液晶准备好 */ void LcdWaitReady() { unsigned char sta; LCD1602_DB = 0xFF; LCD1602_RS = 0; LCD1602_RW = 1; do { LCD1602_E = 1; sta = LCD1602_DB; //读取状态字 LCD1602_E = 0; } while (sta & 0x80); //bit7等于1表示液晶正忙,重复检测直到其等于0为止 } /* 向LCD1602液晶写入一字节命令,cmd-待写入命令值 */ void LcdWriteCmd(unsigned char cmd) { LcdWaitReady(); LCD1602_RS = 0; LCD1602_RW = 0; LCD1602_DB = cmd; LCD1602_E = 1; LCD1602_E = 0; } /* 向LCD1602液晶写入一字节数据,dat-待写入数据值 */ void LcdWriteDat(unsigned char dat) { LcdWaitReady(); LCD1602_RS = 1; LCD1602_RW = 0; LCD1602_DB = dat; LCD1602_E = 1; LCD1602_E = 0; } /* 设置显示RAM起始地址,亦即光标位置,(x,y)-对应屏幕上的字符坐标 */ void LcdSetCursor(unsigned char x, unsigned char y) { unsigned char addr; if (y == 0) //由输入的屏幕坐标计算显示RAM的地址 addr = 0x00 + x; //第一行字符地址从0x00起始 else addr = 0x40 + x; //第二行字符地址从0x40起始 LcdWriteCmd(addr | 0x80); //设置RAM地址 } /* 在液晶上显示字符串,(x,y)-对应屏幕上的起始坐标,str-字符串指针 */ void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str) { LcdSetCursor(x, y); //设置起始地址 while (*str != ' |