C51 COMPILER V9.56.0.0 LCD 04/06/2022 21:56:10 PAGE 1 C51 COMPILER V9.56.0.0, COMPILATION OF MODULE LCD OBJECT MODULE PLACED IN lcd.OBJ COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE lcd.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND TABS(2) line level source 1 #include "lcd.h" 2 3 4 void Read_Busy() //忙检测函数,判断bit7是0,允许执行;1禁止 5 { 6 1 unsigned char sta; // 7 1 LCD1602_DB = 0xff; 8 1 LCD1602_RS = 0; 9 1 LCD1602_RW = 1; 10 1 do 11 1 { 12 2 LCD1602_EN = 1; 13 2 sta = LCD1602_DB; 14 2 LCD1602_EN = 0; //使能,用完就拉低,释放总线 15 2 }while(sta & 0x80); 16 1 } 17 18 void Lcd1602_Write_Cmd(unsigned char cmd) //写命令 19 { 20 1 Read_Busy(); 21 1 LCD1602_RS = 0; 22 1 LCD1602_RW = 0; 23 1 LCD1602_DB = cmd; 24 1 LCD1602_EN = 1; 25 1 LCD1602_EN = 0; 26 1 } 27 28 void Lcd1602_Write_Data(unsigned char dat) //写数据 29 { 30 1 Read_Busy(); 31 1 LCD1602_RS = 1; 32 1 LCD1602_RW = 0; 33 1 LCD1602_DB = dat; 34 1 LCD1602_EN = 1; 35 1 LCD1602_EN = 0; 36 1 } 37 38 void LcdSetCursor(unsigned char x,unsigned char y) //坐标显示 39 { 40 1 unsigned char addr; 41 1 if(y == 0) 42 1 addr = 0x00 + x; 43 1 else 44 1 addr = 0x40 + x; 45 1 46 1 Lcd1602_Write_Cmd(addr|0x80); 47 1 } 48 49 //按指定位置显示一个字符 50 void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData) 51 { 52 1 Y &= 0x1; 53 1 X &= 0xF; //限制X不能大于15,Y不能大于1 54 1 if (Y) X |= 0x40; //当要显示第二行时地址码+0x40; 55 1 X |= 0x80; //算出指令码 C51 COMPILER V9.56.0.0 LCD 04/06/2022 21:56:10 PAGE 2 56 1 Lcd1602_Write_Cmd(X); //发命令字 57 1 Lcd1602_Write_Data(DData); //发数据 58 1 } 59 60 61 void LcdShowStr(unsigned char x,unsigned char y,unsigned char *str) //显示字符串 62 { 63 1 LcdSetCursor(x,y); //当前字符的坐标 64 1 while(*str != '\0') 65 1 { 66 2 Lcd1602_Write_Data(*str++); 67 2 } 68 1 } 69 70 void InitLcd1602() //1602初始化 71 { 72 1 Lcd1602_Write_Cmd(0x38); //打开,5*8,8位数据 73 1 Lcd1602_Write_Cmd(0x0c); 74 1 Lcd1602_Write_Cmd(0x06); 75 1 Lcd1602_Write_Cmd(0x01); //清屏 76 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 157 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = ---- 3 IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)