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

📄 lcd_io.lst

📁 ST公司的upsd34XX评估板固定源程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   LCD_IO                                                                10/10/2004 20:51:47 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE LCD_IO
OBJECT MODULE PLACED IN lcd_io.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lcd_io.c LARGE BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          // A collection of I/O functions for WSi eval boards which include
   2          // LED's, LCD, UART. 
   3          // Mark Rootz 3/30/98 */
   4          // debugged for eval boards T. Wilkerson 7-9/98
   5          //
   6          // Modified by William Chin for uPSD3234 from ST Microelectronics
   7          // on June 14, 2002
   8          // collection of LCD functions only
   9          //
  10          // Revision History
  11          //
  12          //      7/22/02 (JAM) - Added LCD buffer for mirroring LCD data to PC app.
  13          
  14          //-- Includes ----------------------------------------------------------------
  15          
  16          #include "general.h"
  17          #include "upsd.h"                               // SFRs
  18          #include "upsd_xreg.h"                  // extended registers in uPSD
  19          
  20          #include "lcd_io.h"
  21          #include "timer_func.h"
  22          #include "app_intr.h"
  23          
  24          //-- Variables ---------------------------------------------------------------
  25          
  26          extern DISPLAY LCD_reg;
  27          
  28          static idata uchar Cursor_LCD;
  29          
  30          // User design CG data
  31          static uchar code cg_data[] = {
  32          
  33                          0x1F,   //14% 
  34                          0x11,
  35                          0x11,
  36                          0x11,
  37                          0x11,
  38                          0x11,
  39                          0x11,
  40                          0x1F,
  41          
  42                          0x1F,   //28%
  43                          0x11,   
  44                          0x11,   
  45                          0x11,   
  46                          0x11,   
  47                          0x11,   
  48                          0x1F,   
  49                          0x1F,   
  50          
  51                          0x1F,   //43%
  52                          0x11,   
  53                          0x11,   
  54                          0x11,   
  55                          0x11,   
C51 COMPILER V7.06   LCD_IO                                                                10/10/2004 20:51:47 PAGE 2   

  56                          0x1F,   
  57                          0x1F,   
  58                          0x1F,   
  59          
  60                          0x1F,   //57%
  61                          0x11,   
  62                          0x11,   
  63                          0x11,   
  64                          0x1F,   
  65                          0x1F,   
  66                          0x1F,   
  67                          0x1F,   
  68          
  69                          0x1F,   //71%
  70                          0x11,   
  71                          0x11,   
  72                          0x1F,   
  73                          0x1F,   
  74                          0x1F,   
  75                          0x1F,   
  76                          0x1F,   
  77          
  78                          0x1F,   //86%
  79                          0x11,
  80                          0x1F,
  81                          0x1F,
  82                          0x1F,
  83                          0x1F,
  84                          0x1F,
  85                          0x1F,
  86                          
  87                          0x1F,   //100%
  88                          0x1F,   
  89                          0x1F,   
  90                          0x1F,   
  91                          0x1F,   
  92                          0x1F,   
  93                          0x1F,   
  94                          0x1F,   
  95          
  96                          -1
  97          };
  98          
  99          char        LCD_buffer[LCD_BUFFER_SIZE + 1]; // LCD mirror buffer
 100          static char LCD_index;                       // Cursor pos in LCD_buffer
 101          
 102          //-- Prototypes----------------------------------------------------------------
 103          
 104          static void SetUserCG(uchar *); // initialize user character pattern
 105          static void BusyCheck(void);    // wait until BF is cleared
 106          static char htoa_lo(uchar);             // converts low nibble of unsigned byte
 107          static char htoa_hi(uchar);             // converts hi nibble of unsigned byte
 108          
 109          
 110          //-- Functions ----------------------------------------------------------------
 111          
 112          void initLCD(void)              // initialize LCD module per specs   
 113          {
 114   1          int i;
 115   1      
 116   1              delay_ms(15);
 117   1              LCD_reg.LCD_CMD_WR = 0x30;
C51 COMPILER V7.06   LCD_IO                                                                10/10/2004 20:51:47 PAGE 3   

 118   1              delay_ms(4);            
 119   1              LCD_reg.LCD_CMD_WR = 0x30;
 120   1              delay_ms(1);            
 121   1              LCD_reg.LCD_CMD_WR = 0x30;
 122   1              delay_ms(1);            
 123   1      
 124   1              LCD_reg.LCD_CMD_WR = 0x38;      // 8 bits, 2 lines, 5 x 7 font   
 125   1              delay_ms(4);                            // delay 4 ms   
 126   1              BusyCheck();
 127   1              LCD_reg.LCD_CMD_WR = 0x0C;      //Display on, Cursor off, Non-Blink
 128   1              BusyCheck();
 129   1              LCD_reg.LCD_CMD_WR = 0x01;      //Clear display
 130   1              BusyCheck();
 131   1              LCD_reg.LCD_CMD_WR = 0x02;      //Cursor home
 132   1              BusyCheck();
 133   1              LCD_reg.LCD_CMD_WR = 0x06;      //Cursor inc, no shift/cursor move
 134   1                      
 135   1              SetUserCG(&cg_data);            //set user desfined character
 136   1      
 137   1              Cursor_LCD = DD_ADDR;           //Display from 1st row, 1st column
 138   1              BusyCheck();
 139   1              LCD_reg.LCD_CMD_WR = Cursor_LCD;
 140   1      
 141   1          // Initialize mirror buffer
 142   1      
 143   1          for (i = 0; i < LCD_BUFFER_SIZE; i++)
 144   1          {
 145   2              LCD_buffer[i] = ' ';
 146   2          }
 147   1      
 148   1          LCD_buffer[LCD_BUFFER_SIZE] = 0;
 149   1          LCD_index = 0;    
 150   1      }
 151          
 152          
 153          static void SetUserCG(uchar *data_ptr)  // initialize user character pattern
 154                  {
 155   1              BusyCheck();
 156   1              LCD_reg.LCD_CMD_WR = CG_ADDR | (8*1);           //from character code 1
 157   1      
 158   1              while (*data_ptr != -1) {
 159   2                      BusyCheck();
 160   2                      LCD_reg.LCD_RAM_WR = *data_ptr++;
 161   2                      }               
 162   1              }
 163          
 164          static void BusyCheck(void)                     // wait until BF is cleared
 165                  {
 166   1              while (LCD_reg.LCD_CMD_RD & BF_BIT);
 167   1              }
 168          
 169          /*
 170          void setXY_LCD (uchar row, uchar col) {
 171                  Cursor_LCD = (DD_ADDR | ((row & 0x01) << 6)) + (col & LCD_LINE_LENGTH);
 172                  BusyCheck();
 173                  LCD_reg.LCD_CMD_WR = Cursor_LCD;
 174          }
 175          
 176          void putch_LCD(uchar ch) {
 177                  BusyCheck();
 178                  LCD_reg.LCD_RAM_WR = ch;
 179          }
C51 COMPILER V7.06   LCD_IO                                                                10/10/2004 20:51:47 PAGE 4   

 180          */
 181          
 182          void printfLCD(uchar *chr_ptr, ...)
 183          {
 184   1          uchar *var_ptr=&chr_ptr+1;
 185   1          uchar var;
 186   1      
 187   1          while (*chr_ptr != NULL) 
 188   1          {
 189   2              BusyCheck();
 190   2                      
 191   2              if (*chr_ptr == '\r')
 192   2              {
 193   3                  // Return to position 0 at current line
 194   3                              chr_ptr++;
 195   3                  Cursor_LCD &= 0xC0;
 196   3                  LCD_reg.LCD_CMD_WR = Cursor_LCD;
 197   3                  LCD_index -= LCD_index % LCD_LINE_SIZE;
 198   3                      }
 199   2                      else if (*chr_ptr == '\n') 
 200   2              {
 201   3                              chr_ptr++;
 202   3                              Cursor_LCD ^= 0x40;                             //goto next line
 203   3                              Cursor_LCD &= 0xC0;                             //return to position 0
 204   3                              LCD_reg.LCD_CMD_WR = Cursor_LCD;
 205   3                  if (LCD_index < (LCD_BUFFER_SIZE - LCD_LINE_SIZE))
 206   3                  {
 207   4                      LCD_index += LCD_LINE_SIZE;
 208   4                  }
 209   3                      }
 210   2                      else if (*chr_ptr == '%') 
 211   2              {
 212   3                              chr_ptr++;
 213   3                              if (*chr_ptr == 'd')
 214   3                  {
 215   4                      // Display 1 digit decimal 0-9                          
 216   4                      chr_ptr++;
 217   4                      var = *var_ptr++;
 218   4                      LCD_reg.LCD_RAM_WR = LCD_buffer[LCD_index++] = (var & 0x0F)+'0';
 219   4                      if (LCD_index >= LCD_BUFFER_SIZE)
 220   4                      {

⌨️ 快捷键说明

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