⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text1.lst

📁 51单片接在LCD1602汉字显示的c语言写的驱动程序。
💻 LST
字号:
C51 COMPILER V7.09   TEXT1                                                                 09/02/2008 11:50:14 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE TEXT1
OBJECT MODULE PLACED IN Text1.OBJ
COMPILER INVOKED BY: R:\electronic\keilc51\C51\BIN\C51.EXE Text1.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg51.h>
   2          /*unsigned char table1[]={0x03,0x07,0x0f,0x1f,0x1f,0x1f,0x1f,0x1f, 
   3                                     0x18,0x1E,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f, 
   4                                     0x07,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f, 
   5                                     0x10,0x18,0x1c,0x1E,0x1E,0x1E,0x1E,0x1E, 
   6                                     0x0f,0x07,0x03,0x01,0x00,0x00,0x00,0x00, 
   7                                     0x1f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x01, 
   8                                     0x1f,0x1f,0x1f,0x1f,0x1f,0x1c,0x18,0x00, 
   9                                     0x1c,0x18,0x10,0x00,0x00,0x00,0x00,0x00};//心图案 */
  10          unsigned char table1[]={0x08,0x0F,0x12,0x0F,0x0A,0x1F,0x02,0x02,        //"年"代码=00H 
  11                                                              0x0F,0x09,0x0F,0x09,0x0F,0x09,0x11,0x00,            //"月"代码=01H
  12                                                                  0x1F,0x11,0x11,0x1F,0x11,0x11,0x1F,0x00,        //"日"代码=02H
  13                                                                  0x11,0x0A,0x04,0x1F,0x04,0x1F,0x04,0x00,        //"$"代码=03H
  14                                                                  0x0E,0x00,0x1F,0x0A,0x0A,0x0A,0x13,0x00,        //"元"代码=04H
  15                                                                  0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00,        //"℃"代码=05H
  16                                                                  0x04,0x0A,0x15,0x04,0x04,0x04,0x04,0x00,        //"↑"代码=06H
  17                                                                  0x17,0x15,0x15,0x15,0x15,0x15,0x17,0x00};       //字符℃ 
  18          unsigned char table[]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00};
  19          
  20          #define     CLEARSCREEN     LCD_write_command(0x01)
  21          
  22          /**************定义接口************************/
  23          
  24          #define     LCDIO      P1 
  25          sbit LCD1602_RS=P3^4;     
  26          sbit LCD1602_RW=P3^5;    
  27          sbit LCD1602_EN=P3^6;   
  28          
  29          /**************定义函数************************/ 
  30          void LCD_write_command(unsigned char command);//写入指令函数 
  31          void LCD_write_dat(unsigned char dat);//写入数据函数 
  32          void LCD_set_xy( unsigned char x, unsigned char y );//设置显示位置函数 
  33          void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat);//显示一个字符函数 
  34          void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s);//显示字符串函数 
  35          void LCD_init(void);//初始化函数 
  36          void delay_nms(unsigned int n);//延时函数 
  37          /********************************************/
  38          
  39          /************初始化函数****************/ 
  40          void LCD_init(void) 
  41          {  
  42   1      CLEARSCREEN;//clear screen  
  43   1      LCD_write_command(0x38);//set 8 bit data transmission mode  
  44   1      LCD_write_command(0x0c);//open display (enable lcd display) 
  45   1      LCD_write_command(0x80);//set lcd first display address  
  46   1      CLEARSCREEN;//clear screen 
  47   1      } 
  48          /****************************************************/
  49          
  50          /**************写指令函数********************************/   
  51          void LCD_write_command(unsigned char command) 
  52          { 
  53   1            LCDIO=command; 
  54   1            LCD1602_RS=0;    
  55   1            LCD1602_RW=0; 
C51 COMPILER V7.09   TEXT1                                                                 09/02/2008 11:50:14 PAGE 2   

  56   1            LCD1602_EN=0; 
  57   1            LCD1602_EN=1; 
  58   1            delay_nms(10); 
  59   1      } 
  60          /***************************************************/ 
  61          /****************写数据函数************************/ 
  62          void LCD_write_dat(unsigned char dat) 
  63          { 
  64   1      LCDIO=dat; 
  65   1      LCD1602_RS=1; 
  66   1      LCD1602_RW=0; 
  67   1      LCD1602_EN=0; 
  68   1      delay_nms(1); 
  69   1      LCD1602_EN=1; 
  70   1      } 
  71          /****************************************************/
  72          
  73          /***************设置显示位置**************************/ 
  74          void LCD_set_xy( unsigned char x, unsigned char y ) 
  75          { 
  76   1      unsigned char address; 
  77   1      if (y == 1)  
  78   1           address = 0x80 + x; 
  79   1      else  
  80   1              address =0xc0+ x; 
  81   1      LCD_write_command(address);  
  82   1      } 
  83          /***************************************************/
  84          
  85          /****************显示一个字符**********************/ 
  86          void LCD_dsp_char( unsigned char x,unsigned char y,unsigned char dat) 
  87          { 
*** WARNING C235 IN LINE 87 OF TEXT1.C: parameter 1: different types
  88   1      LCD_set_xy( x, y );  
  89   1      LCD_write_dat(dat); 
  90   1      } 
  91          /**********************************************/
  92          
  93          /***************显示字符串函数***************/ 
  94          void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s) 
  95          { 
  96   1             LCD_set_xy( X, Y );  
  97   1             while (*s)   
  98   1             { 
  99   2               LCD_write_dat(*s);    
 100   2               s ++; 
 101   2             } 
 102   1      } 
 103          /***********************************************/
 104          
 105          /********** 延时**********************/ 
 106          void delay_nms(unsigned int n)       
 107          { 
 108   1             unsigned int i=0,j=0; 
 109   1             for (i=n;i>0;i--) 
 110   1             for (j=0;j<10;j++);   
 111   1      } 
 112          /**************************************/
 113          
 114          /***********主函数**************/ 
 115          void main(void) 
 116          { 
C51 COMPILER V7.09   TEXT1                                                                 09/02/2008 11:50:14 PAGE 3   

 117   1              unsigned char i,j,k,tmp; 
 118   1              LCD_init(); 
 119   1              delay_nms(100); 
 120   1              tmp=0x40;//设置CGRAM地址的格式字   CGRAM地址格式很复杂  01 000 000  01是固定的  左起第一个000是代码的大小
             -,最后的000是个偏移量(存储每个代码数据的偏移量)
 121   1              k=0; 
 122   1              for(j=0;j<8;j++) { 
 123   2              for(i=0;i<8;i++) {  
 124   3                 LCD_write_command(tmp+i); // 设置自定义字符的 CGRAM 地址   
 125   3                 delay_nms(2); 
 126   3                 LCD_write_dat(table1[k]); // 向CGRAM写入自定义字符表的数据 
 127   3                 k++; 
 128   3                 delay_nms(2); 
 129   3               } 
 130   2              tmp=tmp+8; //写完00H的8个数据后,转入写01H的8个数据  
 131   2            } 
 132   1           LCD_dsp_string(1,1,"LCD TEST        ");//
 133   1           LCD_dsp_string(1,2,"SUCCESSFUL      ");//
 134   1           for (i=0;i<4;i++) 
 135   1             { 
 136   2               LCD_dsp_char( 12+i,1,i);//在第一行第12列位置显示心图案的上半部 
 137   2               delay_nms(1); 
 138   2             } 
 139   1           for (i=4;i<8;i++) 
 140   1             { 
 141   2               LCD_dsp_char( 12+i-4,2,i);//在第二行第12列位置显示心图案的下半部 
 142   2               delay_nms(1); 
 143   2             } 
 144   1      
 145   1              
 146   1              for(i=0;i<30;i++){
 147   2                      delay_nms(1000);
 148   2              }
 149   1              CLEARSCREEN;
 150   1              LCD_dsp_string(0,1,"XIONGJIALE");
 151   1              LCD_dsp_string(5,2,"ICEXIONG");
 152   1          while (1); 
 153   1      } 
 154          /********************************************************************/
 155          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    369    ----
   CONSTANT SIZE    =     54    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     72       9
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -