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

📄 1602.lst

📁 单片机 单片机基本功能 单片机基本功能实现
💻 LST
字号:
C51 COMPILER V6.12  1602                                                                   05/09/2007 20:05:04 PAGE 1   


C51 COMPILER V6.12, COMPILATION OF MODULE 1602
OBJECT MODULE PLACED IN .\1602.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\1602.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include <at89x51.h>
   2          #define uchar unsigned char
   3          #define uint unsigned int
   4          #define busy 0x80
   5          sbit RS=P3^7;
   6          sbit RW=P3^6;
   7          sbit E=P3^5;
   8          sfr lcd_data=0xa0;
   9          void cls(void);
  10          void uart_init();
  11          void send_string(uchar *str);
  12          void send_byte(uchar da);
  13          void initlcd();
  14          void write_data(uchar x);
  15          void write_instruction(uchar x);
  16          void write_string(uchar x,uchar *p);
  17          void delay(uint i);
  18          uchar code string_to_pc[]="字符型LCD1602和传口测试程序,请输入单个字母或数字发给我!";
  19          uchar code sring_to_lcd[]="LCM 1602,I LOVE";
  20          
  21          void main()
  22          {
  23   1         uart_init();//初始化传口
  24   1         send_string(string_to_pc);//发送字符串
  25   1         send_byte(0x0d);//计算机换行
  26   1         send_byte(0x0a);
  27   1         initlcd();
  28   1         write_string(0x80,sring_to_lcd);
  29   1         while(1);
  30   1      }
  31          /************************************初始化串口******************************/
  32          void uart_init()
  33          {
  34   1          TMOD=0x20;
  35   1      	TH1=0XFD;
  36   1      	TL1=0XFD;
  37   1      	PCON=0X00;
  38   1      	TR1=1;
  39   1      	SCON=0X50;
  40   1      	IE=0x90;
  41   1      
  42   1      }
  43          /************************************发送一串字符*****************************/
  44          void send_string(uchar *str)
  45           {
  46   1           uchar i;
  47   1      	 i=0;
  48   1      	 while(*(str+i)!='\0')
  49   1      	 {
  50   2      	   send_byte(*(str+i));
  51   2      	   i++;
  52   2      	 }
  53   1       }
  54          /************************************发送单个字符******************************/
  55          void send_byte(uchar da)
C51 COMPILER V6.12  1602                                                                   05/09/2007 20:05:04 PAGE 2   

  56          {
  57   1         
  58   1         EA=0;
  59   1         SBUF=da;
  60   1         while(!TI)
  61   1          TI=0;
  62   1      	EA=1;
  63   1       }
  64          
  65          /************************************初始化LCD******************************/
  66          void initlcd()
  67          {
  68   1        write_instruction(0x01);
  69   1        delay(20);
  70   1        write_instruction(0x38);
  71   1        delay(20);
  72   1        write_instruction(0x0f);
  73   1        delay(20);
  74   1        write_instruction(0x06);
  75   1        delay(20);
  76   1      
  77   1      }
  78          /************************************写命令******************************/
  79          void write_instruction(uchar x)
  80          {
  81   1         delay(1000);
  82   1         E=0;
  83   1         RW=0;
  84   1         RS=0;
  85   1         lcd_data=x;
  86   1         E=1;
  87   1         delay(20);
  88   1         E=0;
  89   1      
  90   1      
  91   1      }
  92          
  93          
  94          
  95          /*void check_busy(void)
  96          {
  97             lcd=0xff;
  98             E=0;
  99             RW=1;
 100             RS=0;
 101             E=1;
 102             delay(100);
 103             while(lcd&busy);
 104             E=0;
 105          
 106          }
 107          */
 108          /************************************延时子程序*****************************/
 109          void delay(uint i)
 110          {
 111   1        while(i--);
 112   1      
 113   1      }
 114          
 115          /************************************写数据到LCD中******************************/
 116          
 117          void write_data(uchar x)
C51 COMPILER V6.12  1602                                                                   05/09/2007 20:05:04 PAGE 3   

 118          {
 119   1         delay(1000);
 120   1         E=0;
 121   1         RW=0;
 122   1         RS=1;
 123   1         E=1;
 124   1         lcd_data=x;
 125   1         E=0;
 126   1      }
 127          
 128          /************************************LCD清屏******************************/
 129          void cls(void)
 130          {
 131   1        write_instruction(0x01);
 132   1      }
 133          /************************************写字符串******************************/
 134          void write_string(uchar x,uchar *p)
 135          {
 136   1         write_instruction(x);
 137   1         while(*p!=0x00)
 138   1         {
 139   2           write_data(*p);
 140   2      	 p++;
 141   2      	 x++;
 142   2      	 if(x==0x8f)
 143   2      	 {
 144   3      	 write_instruction(0xc0);
 145   3      	 }
 146   2         }
 147   1      }
 148          
 149          /************************************串口中断******************************/
 150          uart()interrupt 4
 151          {
 152   1        uchar temp;
 153   1        uchar count;
 154   1        EA=0;
 155   1        if(RI)
 156   1        {
 157   2           RI=0;
 158   2      	 temp=SBUF;
 159   2      	 if(count==0)
 160   2      	 {
 161   3      	   cls();
 162   3      	   send_byte(0x0d);//计算机换行
 163   3      	   send_byte(0x0a);
 164   3      
 165   3      	 }
 166   2      	 write_data(temp);//写数据到LCD
 167   2      
 168   2      	 send_byte(temp);//发送回电脑
 169   2      	 count++;
 170   2      	 if(count==0x10)//满一屏
 171   2      	 {
 172   3      	    write_instruction(0xc0);//LCD地址切换到第而行
 173   3      		send_byte(0x0d);//换行
 174   3      	    send_byte(0x0a);
 175   3      	 }
 176   2      	 if(count==0x20)
 177   2      	 {
 178   3      	    count=0;
 179   3      	 }
C51 COMPILER V6.12  1602                                                                   05/09/2007 20:05:04 PAGE 4   

 180   2        }
 181   1      	EA=1;
 182   1        
 183   1      }
 184          
 185          
 186          
 187          
 188          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    378    ----
   CONSTANT SIZE    =     73    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      11
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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