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

📄 1602.lst

📁 lcd1602的四位数据线用法
💻 LST
字号:
C51 COMPILER V8.02   1602                                                                  03/14/2009 10:38:56 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE 1602
OBJECT MODULE PLACED IN 1602.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 1602.c OPTIMIZE(0,SPEED) BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<REG51.h>
   2          #include<ABSACC.H>
   3          #include <intrins.h>
   4          #include"1602.h"
   5          
   6          void inst_lcd(void)
   7          {
   8   1      LCD_E=0;
   9   1      LCD_RS=0;
  10   1      
  11   1      //LCD_RW=0 ; //已经接地,恒为0//
  12   1      /////////////////////////
  13   1      //三次显示模式设置
  14   1      com_h(0x30,10);
  15   1      com_h(0x30,10);
  16   1      com_h(0x30,10);
  17   1      com_h(0x20,10); //4总线模式
  18   1      
  19   1      delay_lcd(100);//延时5ms//
  20   1      
  21   1      com_f(0x28);            //4总线模式,双行显示
  22   1      
  23   1      
  24   1      delay_lcd(100);//延时5ms//
  25   1      com_f(0x01);             //清屏
  26   1      delay_lcd(50);//延时5ms//
  27   1      
  28   1      com_f(0x02);             //光标复位
  29   1      delay_lcd(50);//延时5ms//
  30   1      
  31   1      com_f(0x0C);               //开显示
  32   1      delay_lcd(50);//延时5ms//
  33   1              
  34   1      
  35   1      com_f(0x06);                     //文字不动,光标右移
  36   1      delay_lcd(50);//延时5ms//
  37   1      
  38   1      com_f(0x40);                     //文字不动,光标右移
  39   1      delay_lcd(50);//延时5ms// 
  40   1      
  41   1      
  42   1      }
  43          
  44          void disp(unsigned char x,unsigned char y,unsigned char dec)
  45          {
  46   1       unsigned char ge,shi;
  47   1       shi=dec/10;
  48   1       ge=dec%10;
  49   1       shi|=0x30;
  50   1       ge|=0x30;
  51   1       dispchar(x,y,shi);
  52   1       dispchar(x+1,y,ge);
  53   1      }
  54          
  55          
C51 COMPILER V8.02   1602                                                                  03/14/2009 10:38:56 PAGE 2   

  56          void disp_bcd(unsigned char x,unsigned char y,unsigned char bcd)
  57          {
  58   1       unsigned char ge,shi;
  59   1       ge=(bcd&0x0f);
  60   1       shi=(bcd>>4);
  61   1       shi|=0x30;
  62   1       ge|=0x30;
  63   1       dispchar(x,y,shi);
  64   1       dispchar(x+1,y,ge);
  65   1      }
  66          
  67          
  68          
  69          void dispchar(unsigned char x,unsigned char y,unsigned char ddat)
  70          {
  71   1       y&=0x01;
  72   1       x&=0x0f;
  73   1       if(y) x|=0x40;
  74   1       x|=0x80;
  75   1       com_f(x);
  76   1       dat(ddat);
  77   1      }
  78          
  79          void com_f(unsigned char ch_temp)
  80          {
  81   1      
  82   1      unsigned char tt,te;
  83   1      LCD_RS=0;
  84   1      delay_lcd(5);
  85   1      te=P1&0x0f;
  86   1      tt=ch_temp&0xf0;
  87   1      //tt=tt>>2;
  88   1      P1=te|tt;
  89   1      _nop_();
  90   1      _nop_();
  91   1      LCD_E=1;
  92   1      _nop_();
  93   1      _nop_();
  94   1      LCD_E=0;
  95   1      //写入高4位//
  96   1      
  97   1      te=P1&0x0f;
  98   1      tt=ch_temp&0x0f;
  99   1      tt=tt<<4;
 100   1      P1=te|tt;
 101   1      _nop_();
 102   1      _nop_();
 103   1      LCD_E=1;
 104   1      _nop_();
 105   1      _nop_();
 106   1      LCD_E=0;
 107   1      //低4位//
 108   1      delay_lcd(5);
 109   1      }
 110          
 111          
 112          void dat(unsigned char dat_temp)
 113          {
 114   1      
 115   1      unsigned char tt,te;
 116   1      LCD_RS=1;
 117   1      delay_lcd(5);
C51 COMPILER V8.02   1602                                                                  03/14/2009 10:38:56 PAGE 3   

 118   1      te=P1&0x0f;
 119   1      tt=dat_temp&0xf0;
 120   1      //tt=(tt>>2);
 121   1      P1=te|tt;
 122   1      _nop_();
 123   1      _nop_();
 124   1      LCD_E=1;
 125   1      _nop_();
 126   1      _nop_();
 127   1      LCD_E=0;
 128   1      //写入高4位//
 129   1      delay_lcd(5);
 130   1      te=P1&0x0f;
 131   1      tt=dat_temp&0x0f;
 132   1      tt=tt<<4;
 133   1      P1=te|tt;
 134   1      _nop_();
 135   1      _nop_();
 136   1      LCD_E=1;
 137   1      _nop_();
 138   1      _nop_();
 139   1      LCD_E=0;
 140   1      //低4位//
 141   1      }
 142          
 143          void com_h(unsigned char temp,unsigned char time)
 144          {
 145   1      unsigned char te;
 146   1      LCD_RS=0;
 147   1      te=P1&0x0f;
 148   1      temp&=0xf0;
 149   1      //temp=temp>>2;
 150   1      P1=te|temp;
 151   1      delay_lcd(time);
 152   1      LCD_E=1;
 153   1      _nop_();
 154   1      _nop_();
 155   1      LCD_E=0;
 156   1      }
 157          
 158          void delay_lcd(unsigned char time)
 159          {
 160   1        unsigned char i,j;
 161   1       for (i=0;i<time;i++)
 162   1       { 
 163   2         j=100;
 164   2         while(j--);
 165   2       }
 166   1       
 167   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    435    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     25    ----
   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 + -