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

📄 test1.lst

📁 TFT彩色液晶屏的SPI接口的驱动程序
💻 LST
字号:
C51 COMPILER V8.02   TEST1                                                                 04/06/2008 15:54:51 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE TEST1
OBJECT MODULE PLACED IN test1.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE test1.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /***************************************************************
   2          * Drscription   : TFT Lcd demo
   3          * Driver                : ILI9320 or compatible
   4          * MCU                   : stc89LE52 
   5          * Voltage               : 3.3V
   6          * Interface             : 16bits parallel interface
   7          *
   8          ***************************************************************
   9          *
  10          * Author                : zjq in ShenZhen 
  11          * Data                  : 04-06-08
  12          * Email                 : Crazyzjq@126.com
  13          * History               : Spi works well,but it's so slow 
  14          ***************************************************************/
  15          
  16          #include "stdio.h"
  17          #include "reg51.h"
  18          
  19          #define DATA_L P2
  20          #define DATA_H P1
  21          
  22          #define _SPI 0
  23          
  24          //for SPI 
  25          #ifdef _SPI
  26          sbit  CS = P1^1;
  27          sbit  DI = P1^4;
  28          sbit  DO = P1^0;
  29          
  30          sbit  CLK = P1^2;
  31          sbit  RST = P1^3;
  32          #else
              //for 16bits
              sbit  CS  = P3^3;
              sbit  RST = P3^5;
              sbit  RS  = P3^4;
              #endif
  38          
  39          /**************************************************************************
  40          *
  41          *   Just for SPI to write a byte to Lcd
  42          *
  43          ***************************************************************************/
  44          #ifdef _SPI
  45          void LCD_WriteByte(unsigned char dat)
  46          {
  47   1              unsigned char i;
  48   1      
  49   1          for(i=0;i<8;i++)
  50   1              {
  51   2                      CLK = 0;
  52   2                  dat<<=1;
  53   2                      DI = CY;
  54   2                      CLK = 1;
  55   2          }
C51 COMPILER V8.02   TEST1                                                                 04/06/2008 15:54:51 PAGE 2   

  56   1      }
  57          #endif
  58          
  59            #define START_BYTE  0x70 
  60            #define SET_INDEX   0x00 
  61            #define READ_STATUS 0x01 
  62            #define WRITE_REG   0x02 
  63            #define READ_REG    0x03 
  64          
  65          
  66          void  LCD_WriteRegIndex(unsigned char index) /* Select GRAM Reg */ 
  67          
  68          {
  69   1              CS = 0;
  70   1          LCD_WriteByte(START_BYTE|SET_INDEX);//for register index
  71   1          LCD_WriteByte(0);    //lower byte first
  72   1          LCD_WriteByte(index);
  73   1              CS = 1;
  74   1      
  75   1      }
  76          
  77          /****************************************************************************
  78          *
  79          *       Write a byte to register index and the parameter to 
  80          *       the register
  81          *
  82          ****************************************************************************/
  83          void LCD_WriteReg(unsigned char index,unsigned int val)
  84          {
  85   1      
  86   1      #ifdef _SPI
  87   1          LCD_WriteRegIndex(index);
  88   1      
  89   1              CS = 0;
  90   1          LCD_WriteByte(START_BYTE|WRITE_REG);
  91   1          LCD_WriteByte(val>>8);
  92   1          LCD_WriteByte(val&0xff);
  93   1          CS = 1;
  94   1      
  95   1      #else
                      CS = 0;
                      RS = 0;
                      DATA_L = index; //low
                      DATA_H = 0;
                      WR = 0;
                      WR = 1;
              
                  RS = 1;
                      DATA_L = (unsigned char)val; //low
                      DATA_H = (unsigned char )(val>>8);
                  WR = 0;
                      WR = 1;
                      CS = 1;
              #endif
 110   1      }
 111          
 112          /****************************************************************************
 113          *
 114          * command for Write data 
 115          *
 116          *****************************************************************************/
 117          void Lcd_Write_Start()
C51 COMPILER V8.02   TEST1                                                                 04/06/2008 15:54:51 PAGE 3   

 118          {
 119   1      #ifdef _SPI
 120   1            LCD_WriteRegIndex(0x22); /* Select GRAM Reg */ 
 121   1            CS = 0; 
 122   1            LCD_WriteByte(START_BYTE|WRITE_REG);
 123   1      #else
                  CS = 0;
                      RS = 0;
                      DATA_L = 0x22;
                      DATA_H = 0x00;
                  WR = 0;
                      WR = 1;
                      RS = 1;
              #endif
 132   1      }
 133          
 134          /****************************************************************************
 135          *
 136          *  Write one word to Lcd 
 137          *
 138          *****************************************************************************/
 139          void LCD_WriteData(unsigned int val)
 140          {
 141   1      
 142   1      #ifdef _SPI
 143   1      //  Lcd_Write_Start();
 144   1          LCD_WriteByte(val>>8);
 145   1          LCD_WriteByte(val&0xff);
 146   1      #else
                      DATA_L = (unsigned char)val;
                      DATA_H = (unsigned char)(val>>8);
              
                      WR = 0;
                      WR = 1;
              #endif
 153   1      }
 154          
 155          void Lcd_Write_End()
 156          {
 157   1              CS = 1;
 158   1      }
 159          
 160          
 161          void delay(unsigned int n)
 162          {
 163   1              unsigned int i;
 164   1      
 165   1              for(i=0;i<n;i++);
 166   1      }
 167          
 168          void Lcd_Init()
 169          {
 170   1              RST = 0;
 171   1              delay(2000);
 172   1          RST = 1;
 173   1              delay(2000);
 174   1      
 175   1              LCD_WriteReg(0xe5, 0x8000); /* Set the internal vcore voltage */ 
 176   1              LCD_WriteReg(0x00, 0x0001); /* Start internal OSC. */ 
 177   1              LCD_WriteReg(0x01, 0x0100); /* set SS and SM bit */ 
 178   1              LCD_WriteReg(0x02, 0x0700); /* set 1 line inversion */ 
 179   1              LCD_WriteReg(0x03, 0x1230);  /* set GRAM write direction */ 
C51 COMPILER V8.02   TEST1                                                                 04/06/2008 15:54:51 PAGE 4   

 180   1      
 181   1              LCD_WriteReg(0x04, 0x0000); /* Resize register */ 
 182   1              LCD_WriteReg(0x08, 0x0202); /* set the back porch and front porch */ 
 183   1              LCD_WriteReg(0x09, 0x0000); /* set non-display area refresh cycle ISC[3:0] */ 
 184   1              LCD_WriteReg(0x10, 0x0000); /* FMARK function */ 
 185   1        
 186   1              LCD_WriteReg(0x0c, 0x0000); /* RGB interface setting */ 
 187   1              LCD_WriteReg(0x0d, 0x0000); /* Frame marker Position */ 
 188   1              LCD_WriteReg(0x0f, 0x0000); /* RGB interface polarity */ 
 189   1      
 190   1      /* Adjust the Gamma Curve ----------------------------------------------------*/ 
 191   1              LCD_WriteReg(0x50, 0x0000);
 192   1              LCD_WriteReg(0x51, 0x00ef);
 193   1              LCD_WriteReg(0x52, 0x0000);
 194   1              LCD_WriteReg(0x53, 0x013f);
 195   1              LCD_WriteReg(0x60, 0x2700);
 196   1              LCD_WriteReg(0x61, 0x0001);
 197   1              LCD_WriteReg(0x6a, 0x0000);
 198   1      
 199   1      /* Set GRAM area -------------------------------------------------------------*/ 
 200   1              LCD_WriteReg(0x80, 0x0000);/* Horizontal GRAM Start Address */
 201   1              LCD_WriteReg(0x81, 0x0000);/* Horizontal GRAM End Address */ 
 202   1              LCD_WriteReg(0x82, 0x0000);/* Vertical GRAM Start Address */
 203   1              LCD_WriteReg(0x83, 0x0000);/* Vertical GRAM End Address */ 
 204   1      
 205   1      /* Power On sequence ---------------------------------------------------------*/ 
 206   1              LCD_WriteReg(0x10, 0x17b0);
 207   1              LCD_WriteReg(0x11, 0x0004);
 208   1              delay(50);
 209   1              LCD_WriteReg(0x12, 0x013e);
 210   1              delay(50);
 211   1              LCD_WriteReg(0x13, 0x1f00);/* Frame marker Position */
 212   1              LCD_WriteReg(0x29, 0x000f);
 213   1              delay(50);
 214   1      
 215   1              LCD_WriteReg(0x32, 0x0000); /* GRAM horizontal Address */ 
 216   1          LCD_WriteReg(0x33, 0x0000); /* GRAM Vertical Address */ 
 217   1      
 218   1          LCD_WriteReg(0x07, 0x0173); /* 262K color and display ON */ 
 219   1      
 220   1      }
 221          
 222          void Lcd_test()
 223          {
 224   1              unsigned int i,j;
 225   1              Lcd_Write_Start();
 226   1              for(i=0;i<320;i++)
 227   1                      for(j=0;j<240;j++)
 228   1                      {
 229   2                              if(i>279)LCD_WriteData(0x0000);
 230   2                              else if(i>239)LCD_WriteData(0x001f);
 231   2                              else if(i>199)LCD_WriteData(0x07e0);
 232   2                              else if(i>159)LCD_WriteData(0x07ff);
 233   2                              else if(i>119)LCD_WriteData(0xf800);
 234   2                              else if(i>79)LCD_WriteData(0xf81f);
 235   2                              else if(i>39)LCD_WriteData(0xffe0);
 236   2                              else LCD_WriteData(0xffff);
 237   2                      }
 238   1              Lcd_Write_End();
 239   1      }
 240          
 241          
C51 COMPILER V8.02   TEST1                                                                 04/06/2008 15:54:51 PAGE 5   

 242          void main()
 243          {
 244   1              Lcd_Init();
 245   1              Lcd_test();
 246   1              while(1);
 247   1      }


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