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

📄 lcd_4.lst

📁 基于msc单片机仿真机的仿真程序
💻 LST
字号:
C51 COMPILER V7.07   LCD_4                                                                 09/16/2006 15:22:37 PAGE 1   


C51 COMPILER V7.07, COMPILATION OF MODULE LCD_4
OBJECT MODULE PLACED IN LCD_4.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE LCD_4.C BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*
   2           *      LCD interface example
   3           *      Uses routines from delay.c
   4           *      This code will interface to a standard LCD controller
   5           *      like the Hitachi HD44780. It uses it in 4 or 8 bit mode
   6           *      
   7           */
   8          
   9          #include"reg51.h"
  10          #include"lcd.h"
  11          #include"delay.h"
  12           
  13          
  14          static bit fourbit;             // four or eight bit mode?
  15          
  16          #ifdef CHECKBUSY
              
              unsigned char lcd_read_cmd_nowait(void)
              {
                      unsigned char c, readc;
              
                      //LCD_DATA_TRIS  =  INPUT_DATA;
              
                      LCD_RW = 1; // Read LCD
                      //asm("nop"); // short propagation delay
                      //asm("nop"); // short propagation delay
              
                      if (fourbit)
                      {
                              LCD_STROBE_READ(readc); // Read high nibble
                              // Move 4 bits to high nibble while zeroing low nibble
                              c = ( ( readc << 4 ) & 0xF0 ); 
                              LCD_STROBE_READ(readc); // Read low nibble
                              c |= ( readc & 0x0F ); // Or in 4 more bits to low nibble
                      }
                      else
                      {
                              LCD_STROBE_READ(readc); 
                              c = readc;
                      }
                      LCD_RW = 0; // Return to default mode of writing LCD
                      //LCD_DATA_TRIS  = OUTPUT_DATA; // Return to default mode of writing LCD
              
                      return(c);
              }
              
              void lcd_check_busy(void) // Return when the LCD is no longer busy, or we've waiting long enough!
              {
                      // To avoid hanging forever in event there's a bad or 
                      // missing LCD on hardware.  Will just run SLOW, but still run.
                      unsigned int retry; 
                      unsigned char c;
              
                      for (retry=1000; retry-- > 0; ) {
                              c = lcd_read_cmd_nowait();
C51 COMPILER V7.07   LCD_4                                                                 09/16/2006 15:22:37 PAGE 2   

                              if (0==(c&0x80)) break; // Check busy bit.  If zero, no longer busy
                      }
              }
              
              #endif
  61          
  62          /* send a command to the LCD */
  63          void lcd_cmd(unsigned char c)
  64          {
  65   1              //LCD_WAIT; // may check LCD busy flag, or just delay a little, depending on lcd.h
  66   1      
  67   1              if (fourbit)
  68   1              {
  69   2                      LCD_DATA = ( ( c >> 4 ) & 0x0F );
  70   2                      LCD_STROBE();
  71   2                      LCD_DATA = ( c & 0x0F );
  72   2                      LCD_STROBE();
  73   2              }
  74   1              else
  75   1              {
  76   2                      LCD_DATA = c;
  77   2                      LCD_STROBE();
  78   2              }
  79   1      }
  80          
  81          /* send data to the LCD */
  82          void lcd_data(unsigned char c)
  83          {
  84   1              LCD_WAIT; // may check LCD busy flag, or just delay a little, depending on lcd.h
  85   1      
  86   1              LCD_DATA = 0;
  87   1              LCD_RS = 1;
  88   1              if (fourbit)
  89   1              {
  90   2                      LCD_DATA |= ( ( c >> 4 ) & 0x0F );      
  91   2                      LCD_STROBE();
  92   2                      LCD_DATA &= 0xF0;
  93   2                      LCD_DATA |= ( c & 0x0F ); 
  94   2                      LCD_STROBE();
  95   2              }
  96   1              else
  97   1              {
  98   2                      LCD_DATA = c;
  99   2                      LCD_STROBE();
 100   2              }
 101   1              LCD_RS = 0;
 102   1      }
 103          
 104          /* write a string of chars to the LCD */
 105          void lcd_puts(const char * s)
 106          {
 107   1              while(*s)
 108   1              lcd_data(*s++);
 109   1      }
 110          
 111          /* initialize the LCD */
 112          void lcd_init(unsigned char mode)
 113          {
 114   1              char init_value;
 115   1      
 116   1              fourbit         = 0;
 117   1              if (mode == FOURBIT_MODE){
C51 COMPILER V7.07   LCD_4                                                                 09/16/2006 15:22:37 PAGE 3   

 118   2                      fourbit = 1;
 119   2                      init_value = 0x3;
 120   2              }else{
 121   2                      init_value = 0x3F;
 122   2              }
 123   1              LCD_RS = 0;
 124   1              LCD_EN = 0;
 125   1              LCD_RW = 0;
 126   1              //LCD_RS_TRIS    = OUTPUT_PIN;
 127   1              //LCD_EN_TRIS    = OUTPUT_PIN;
 128   1              //LCD_RW_TRIS    = OUTPUT_PIN;
 129   1              //LCD_DATA_TRIS  = OUTPUT_DATA;
 130   1              delay(15000);
 131   1              LCD_DATA         = init_value;
 132   1              LCD_STROBE();
 133   1              delay(5000);
 134   1              LCD_DATA         = init_value;
 135   1              LCD_STROBE();
 136   1              delay(200);
 137   1              LCD_DATA         = init_value;
 138   1              LCD_STROBE();
 139   1              
 140   1              if (fourbit){
 141   2                      LCD_WAIT; //may check LCD busy flag, or just delay a little, depending on lcd.h
 142   2                      LCD_DATA = 0x2; // Set 4-bit mode
 143   2                      LCD_STROBE();
 144   2                      lcd_cmd(0x28); // Function Set
 145   2              }else{
 146   2                      lcd_cmd(0x38);
 147   2              }
 148   1              lcd_cmd(0x0f); //Display On, Cursor On, Cursor Blink
 149   1              lcd_clear(); //Display Clear
 150   1              lcd_cmd(0x6); //Entry Mode
 151   1              lcd_home();
 152   1              lcd_puts("                ");
 153   1              lcd_home2();
 154   1              lcd_puts("                ");
 155   1              //lcd_goto(0); //Initialize DDRAM address to zero
 156   1      }
 157          
 158          void main(void)
 159          {
 160   1          lcd_init(0);         //0x0:四位;0x1:八位
 161   1          while(1)
 162   1             {
 163   2              lcd_home2();
 164   2              lcd_puts("Learning to......");
 165   2              lcd_home();     // select line 2
 166   2              lcd_puts(" Welcome to RYG ");
 167   2              delay(5000);
 168   2              lcd_home2();
 169   2              lcd_puts("1234567890......");
 170   2              lcd_home();     // select line 2
 171   2              lcd_puts("0988abcdefg....");    
 172   2              delay(5000);
 173   2             }        
 174   1      }
 175          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    388    ----
C51 COMPILER V7.07   LCD_4                                                                 09/16/2006 15:22:37 PAGE 4   

   CONSTANT SIZE    =     85    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       9
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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