C51 COMPILER V8.08   LCD1602                                                               08/18/2015 10:32:31 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE LCD1602
OBJECT MODULE PLACED IN LCD1602.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD1602.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "qxmcs51_config.h"
   2          #include "delay.h"
   3          #include "LCD1602.H"
   4          
   5          #define LCD1602_DataPort P0       //LCD1602数据端口
   6          //INT8U strDEC[4];
   7          INT8U strHEX[3];//INT8UtostrHEX函数转换的字符串显示16进制
   8          /*
   9          INT8U *INT8UtostrDEC(INT8U num)
  10          {
  11                  INT8U i2, i1, i0,i;
  12                  i2 = num / 100;
  13                  i1 = num % 100 / 10;
  14                  i0 = num % 100 % 10;
  15                  strDEC[i]=i2+48;
  16                  i++;    
  17                  strDEC[i]=i1+48;
  18                  i++;    
  19                  strDEC[i]=i0+48;
  20                  i++;
  21                  strDEC[i] = '\0';
  22                  return strDEC;  
  23          }
  24          */
  25          INT8U *INT8UtostrHEX(INT8U num) //将一个字节的数据转换为字符串
  26          {
  27   1              INT8U i = 0;
  28   1              switch(num/16)
  29   1              {
  30   2                      case 0:         strHEX[i] = '0';        i++;    break;
  31   2                      case 1:         strHEX[i] = '1';        i++;    break;
  32   2                      case 2:         strHEX[i] = '2';        i++;    break;
  33   2                      case 3:         strHEX[i] = '3';        i++;    break;
  34   2                      case 4:         strHEX[i] = '4';        i++;    break;
  35   2                      case 5:         strHEX[i] = '5';        i++;    break;
  36   2                      case 6:         strHEX[i] = '6';        i++;    break;
  37   2                      case 7:         strHEX[i] = '7';        i++;    break;
  38   2                      case 8:         strHEX[i] = '8';        i++;    break;
  39   2                      case 9:         strHEX[i] = '9';        i++;    break;
  40   2                      case 10:        strHEX[i] = 'A';        i++;    break;
  41   2                      case 11:        strHEX[i] = 'B';        i++;    break;
  42   2                      case 12:        strHEX[i] = 'C';        i++;    break;
  43   2                      case 13:        strHEX[i] = 'D';        i++;    break;
  44   2                      case 14:        strHEX[i] = 'E';        i++;    break;
  45   2                      case 15:        strHEX[i] = 'F';        i++;    break;
  46   2              }
  47   1      
  48   1              switch(num%16)
  49   1              {
  50   2                      case 0:         strHEX[i] = '0';        i++;    break;
  51   2                      case 1:         strHEX[i] = '1';        i++;    break;
  52   2                      case 2:         strHEX[i] = '2';        i++;    break;
  53   2                      case 3:         strHEX[i] = '3';        i++;    break;
  54   2                      case 4:         strHEX[i] = '4';        i++;    break;
  55   2                      case 5:         strHEX[i] = '5';        i++;    break;
C51 COMPILER V8.08   LCD1602                                                               08/18/2015 10:32:31 PAGE 2   

  56   2                      case 6:         strHEX[i] = '6';        i++;    break;
  57   2                      case 7:         strHEX[i] = '7';        i++;    break;
  58   2                      case 8:         strHEX[i] = '8';        i++;    break;
  59   2                      case 9:         strHEX[i] = '9';        i++;    break;
  60   2                      case 10:        strHEX[i] = 'A';        i++;    break;
  61   2                      case 11:        strHEX[i] = 'B';        i++;    break;
  62   2                      case 12:        strHEX[i] = 'C';        i++;    break;
  63   2                      case 13:        strHEX[i] = 'D';        i++;    break;
  64   2                      case 14:        strHEX[i] = 'E';        i++;    break;
  65   2                      case 15:        strHEX[i] = 'F';        i++;    break;
  66   2              }
  67   1              strHEX[i] = '\0';
  68   1              return (strHEX);
  69   1      }       
  70          
  71          BOOL LCD1602_Check_Busy()       //LCD1602忙判断 
  72          { 
  73   1              LCD1602_DataPort = 0xFF; 
  74   1              LCD_RS = 0; //根据规定，RS为低电平，RW为高电平时，可以读状态
  75   1              LCD_RW = 1; 
  76   1              LCD_EN = 0; 
  77   1              _nop_(); 
  78   1              LCD_EN = 1;
  79   1              return (BOOL)(LCD1602_DataPort & 0x80);
  80   1      }
  81          /*
  82          void LCD1602_Clear()
  83          {
  84             LCD1602_Write_Com(0x01);    //显示清屏 
  85             Delay_Ms(5); 
  86          }*/
  87          /*
  88          INT8U LCDE1602_DATAP_ADDR()
  89          {
  90                  LCD1602_DataPort = 0xFF; 
  91                  LCD_RS = 0; //根据规定，RS为低电平，RW为高电平时，可以读状态
  92                  LCD_RW = 1; 
  93                  LCD_EN = 0; 
  94                  _nop_(); 
  95                  LCD_EN = 1;
  96                  return (LCD1602_DataPort & 0x7f);       
  97          } */
  98          
  99          void LCD1602_Write_Com(INT8U com)  //LCD1602写命令
 100          {
 101   1              while(LCD1602_Check_Busy()); //忙则等待
 102   1              LCD_RS = 0; 
 103   1              LCD_RW = 0; 
 104   1              LCD_EN = 1; 
 105   1              LCD1602_DataPort= com; 
 106   1              _nop_(); 
 107   1              LCD_EN = 0;     
 108   1      }
 109          
 110          void LCD1602_Write_Dat(INT8U dat)         //LCD1602写数据
 111          {
 112   1              while(LCD1602_Check_Busy()); //忙则等待
 113   1              LCD_RS = 1;
 114   1              LCD_RW = 0; 
 115   1              LCD_EN = 1;
 116   1              LCD1602_DataPort= dat; 
 117   1              _nop_();
C51 COMPILER V8.08   LCD1602                                                               08/18/2015 10:32:31 PAGE 3   

 118   1              LCD_EN = 0;             
 119   1      }
 120          
 121          
 122          void LCD1602_Write_String(INT8U x,INT8U y,INT8U *s) //LCD1602写字符串
 123          {     
 124   1              if (y == 0) 
 125   1              {     
 126   2                      LCD1602_Write_Com(0x80 + x);     //表示第一行
 127   2              }
 128   1              else 
 129   1              {      
 130   2                      LCD1602_Write_Com(0xC0 + x);      //表示第二行
 131   2              }        
 132   1              while (*s != '\0') 
 133   1              {     
 134   2                      LCD1602_Write_Dat(*s++);         
 135   2              }
 136   1      }
 137          
 138          void LCD1602_Init() //LCD1602初始化
 139          {
 140   1         LCD1602_Write_Com(0x38);    /*显示模式设置*/ 
 141   1         LCD1602_Write_Com(0x06);    /*显示光标移动设置*/
 142   1         LCD1602_Write_Com(0x0C);    /*显示开及光标设置*/
 143   1         LCD1602_Write_Com(0x01);    /*显示清屏*/ 
 144   1         Delay_Ms(5);
 145   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    564    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      3       3
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
