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

📄 main.lst

📁 用Silabs的C8051F410单片机驱动LCD12864的屏
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   MAIN                                                                  03/09/2008 16:59:57 PAGE 1   


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

line level    source

   1          //-----------------------------------------------------------------------------
   2          // Includes
   3          //-----------------------------------------------------------------------------
   4          
   5          #include <C8051F410.h>                 // SFR declarations
   6          #include <stdio.h>
   7          #include <math.h>
   8          #include <INTRINS.H>
   9          #include <string.h>
  10          
  11          //-----------------------------------------------------------------------------
  12          // 16-bit SFR Definitions for 'F41x
  13          //-----------------------------------------------------------------------------
  14          
  15          sfr16 TMR2RL = 0xCA;                   // Timer2 reload value
  16          sfr16 TMR2 = 0xCC;                     // Timer2 counter
  17          
  18          //-----------------------------------------------------------------------------
  19          // Global CONSTANTS
  20          //-----------------------------------------------------------------------------
  21          #define RTC0CN    0x06                 // RTC address of RTC0CN register
  22          #define RTC0XCN   0x07                 // RTC address of RTC0XCN register
  23          const unsigned char code RTC_Interval[6]= {0x00,0x00,0x01,0x00,0x00,0x00};
  24          
  25          sbit Led_En = P0^5;
  26          sbit Speaker= P0^7;
  27          
  28          sbit P0_0 = P0^0;
  29          sbit P0_1 = P0^1;
  30          sbit P0_2 = P0^2;
  31          sbit P2_0 = P2^0;
  32          sbit P2_1 = P2^1;
  33          
  34          #define  LCD_CS1                    P0_0
  35          #define  LCD_CS2                    P0_1
  36          #define  LCD_ENABLE                     P0_2 
  37          #define  LCD_R_W                        P2_0
  38          #define  LCD_D_I                    P2_1
  39          
  40          
  41          
  42          #define DataPort P1            //LCD Data port
  43          
  44          #define  LCD_OFF                62       //显示器关闭
  45          #define  LCD_ON                 63       //显示器打开
  46          #define  LCD_START_LINE_0       192      //设开始坐标
  47          #define  SET_PAGE               184      //设页数(X坐标)
  48          #define  SET_Y_ADDRESS_0        64       //设X坐标
  49          #define  CLEAR                  0    //设页数(X坐标)
  50          
  51          #define  ENABLE                         1
  52          #define  DISABLE                0
  53          #define  READ                           1
  54          #define  WRITE                          0
  55          #define  COMMAND                        0
C51 COMPILER V8.08   MAIN                                                                  03/09/2008 16:59:57 PAGE 2   

  56          #define  DATA                   1 
  57          //-----------------------------------------------------------------------------
  58          
  59          #define SYSCLK        24500000         // SYSCLK frequency in Hz
  60          #define BAUDRATE      115200           // Baud rate of UART in bps
  61          
  62          //-----------------------------------------------------------------------------
  63          void OSC_Init (void);
  64          void PORT_Init (void);
  65          
  66          //-----------------------------------------------------------------------------
  67          /*********************************************************************/
  68          /********************字库***********************************************/
  69          /*********************************************************************/
  70          unsigned char code digit[10][2][16]=
  71          {{{0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00},
  72          {0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x00,0x00}},/*"0",9*/
  73          {{0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
  74          {0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x00,0x00}},/*"1",0*/
  75          {{0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00},
  76          {0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x00,0x00}},/*"2",1*/
  77          {{0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x00,0x00},
  78          {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00}},/*"3",2*/
  79          {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00},
  80          {0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0x00}},/*"4",3*/
  81          {{0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x00,0x00},
  82          {0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00}},/*"5",4*/
  83          {{0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x00,0x00},
  84          {0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00}},/*"6",5*/
  85          {{0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00},
  86          {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},/*"7",6*/
  87          {{0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00},
  88          {0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00}},/*"8",7*/
  89          {{0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00},
  90          {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,0x00,0x00,0x00}}};/*"9",8*/ 
  91          //-----------------------------------------------------------------------------
  92          unsigned char code comma[2][16]=
  93          {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
  94          {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};/*":",0*/
  95          //-----------------------------------------------------------------------------
  96          
  97          unsigned char code space[2][16]=
  98          {{0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00},
  99          {0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00}};     
 100          
 101          //-----------------------------------------------------------------------------
 102          unsigned char code Zhongguo[2][16]=
 103          {
 104          {0x00,0x00,0xFC,0xFC,0x94,0x94,0xF4,0xFE,0xCA,0xCA,0x0A,0x02,0xFE,0xFE,0x00,0x00},
 105          {0x00,0x00,0x1F,0x1F,0x14,0x14,0x17,0x1B,0x0A,0x0B,0x1B,0x3A,0x3F,0x1F,0x00,0x00}/*"国",0*/
 106          };
 107          //-----------------------------------------------------------------------------
 108          unsigned char code Zhongguo12[2][12]=
 109          {
 110          {0x00,0xFF,0xFF,0x25,0x25,0xFD,0xFD,0x65,0xE5,0xA5,0xFF,0xFF},
 111          {0x00,0x0F,0x0F,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x0F,0x0F},/*"国",0*/
 112          };
 113          //-----------------------------------------------------------------------------
 114          unsigned char code Five[2][6]=
 115          {
 116          {0x3C,0x24,0x24,0x24,0xC4,0x00},
 117          {0x01,0x02,0x02,0x02,0x01,0x00}  /*"5",0*/
C51 COMPILER V8.08   MAIN                                                                  03/09/2008 16:59:57 PAGE 3   

 118          };
 119          //-----------------------------------------------------------------------------
 120          unsigned char code Eight[2][8]=
 121          {
 122          {0x00,0x00,0x70,0x78,0xC8,0xC8,0x88,0x00},
 123          {0x00,0x10,0x10,0x30,0x30,0x1F,0x0F,0x00}/*"5",0*/
 124          };
 125          //-----------------------------------------------------------------------------
 126          unsigned char xdata DispRam[8][128];
 127          
 128          
 129          unsigned char gx,gy;
 130          
 131          //-----------------------------------------------------------------------------
 132          void LCD_Delay(unsigned char i)
 133          {
 134   1       while(i--);
 135   1      }
 136          /***************检测忙****************************/
 137          
 138          void Check_LCD_Busyflag(void)
 139          {
 140   1       unsigned char  x;
 141   1       LCD_ENABLE=1;
 142   1       LCD_R_W=1;
 143   1       LCD_D_I=0;     
 144   1        
 145   1       LCD_Delay(10);
 146   1       DataPort=0x00;
 147   1       do 
 148   1       {
 149   2        x=DataPort && 128;
 150   2       } while(x);
 151   1      
 152   1       LCD_ENABLE=0;
 153   1       LCD_Delay(5);
 154   1       LCD_D_I=0;
 155   1       LCD_R_W=0;
 156   1      
 157   1      }
 158          /********************写命令**********************/
 159          void Write_LCD_Command(unsigned command)
 160          {
 161   1       Check_LCD_Busyflag();   
 162   1      
 163   1       LCD_ENABLE=1;
 164   1       LCD_R_W = 0;
 165   1       LCD_D_I = 0;
 166   1      
 167   1       LCD_Delay(10);
 168   1       DataPort=command;
 169   1       LCD_Delay(10);
 170   1       LCD_ENABLE=0;
 171   1       LCD_Delay(5);
 172   1       LCD_D_I=1;
 173   1       LCD_R_W=1;
 174   1       LCD_Delay(10);
 175   1      }
 176          /********************写数据*********************/
 177          void Write_LCD_Data(unsigned LCDdata)
 178          {
 179   1       Check_LCD_Busyflag(); 
C51 COMPILER V8.08   MAIN                                                                  03/09/2008 16:59:57 PAGE 4   

 180   1       LCD_ENABLE=1;
 181   1       LCD_R_W=0;
 182   1       LCD_D_I=1;
 183   1      
 184   1       LCD_Delay(10);
 185   1       DataPort=LCDdata;
 186   1       LCD_Delay(10);
 187   1       LCD_ENABLE=0;
 188   1       LCD_Delay(5);
 189   1       LCD_D_I=0;
 190   1       LCD_R_W=1;
 191   1       LCD_Delay(10);
 192   1      }
 193          /*********************清屏**********************/       
 194          void Clear_LCD()
 195          {
 196   1       int i,j;
 197   1       LCD_CS1=1;
 198   1       LCD_CS2=1;
 199   1       LCD_Delay(5);
 200   1       Write_LCD_Command(LCD_ON);    
 201   1       Write_LCD_Command(LCD_START_LINE_0);
 202   1       for(i=0;i<8;i++)
 203   1       {
 204   2        Write_LCD_Command(SET_PAGE+i); 
 205   2        Write_LCD_Command(SET_Y_ADDRESS_0);    
 206   2        for(j=0;j<64;j++)
 207   2        {
 208   3         Write_LCD_Data(0xff);
 209   3        }
 210   2       }               
 211   1      }
 212          
 213          //-----------------------------------------------------------------------------
 214          
 215          void UpData_LCD(unsigned char Buffer[8][128])
 216          {
 217   1       unsigned char i,j;
 218   1       Write_LCD_Command(LCD_ON);    
 219   1       Write_LCD_Command(LCD_START_LINE_0);
 220   1      
 221   1       LCD_CS1=1;
 222   1       LCD_CS2=0;
 223   1       LCD_Delay(5);
 224   1       for(i=0;i<8;i++)
 225   1       {
 226   2        Write_LCD_Command(SET_PAGE+i); 
 227   2        Write_LCD_Command(SET_Y_ADDRESS_0);    
 228   2        for(j=0;j<64;j++)
 229   2        {
 230   3         Write_LCD_Data(Buffer[i][j]);
 231   3        }
 232   2       }
 233   1       
 234   1       LCD_CS1=0;
 235   1       LCD_CS2=1;
 236   1       LCD_Delay(5);
 237   1      // Write_LCD_Command(LCD_ON);    
 238   1      // Write_LCD_Command(LCD_START_LINE_0);
 239   1       for(i=0;i<8;i++)
 240   1       {
 241   2        Write_LCD_Command(SET_PAGE+i); 
C51 COMPILER V8.08   MAIN                                                                  03/09/2008 16:59:57 PAGE 5   

 242   2        Write_LCD_Command(SET_Y_ADDRESS_0);    
 243   2        for(j=64;j<128;j++)
 244   2        {
 245   3         Write_LCD_Data(Buffer[i][j]);
 246   3        }
 247   2       }                
 248   1      }
 249          
 250          //-----------------------------------------------------------------------------
 251          
 252          void Show_ChineseChar16(unsigned char x,unsigned char y,unsigned char StrAddr[2][16])
 253          {
 254   1       unsigned char i;
 255   1       if((y%8)==0)
 256   1       {
 257   2        for(i=0;i<16;i++)
 258   2        {
 259   3         DispRam[y>>3][x+i]    =StrAddr[0][i];
 260   3         DispRam[(y>>3)+1][x+i]=StrAddr[1][i];  
 261   3        }
 262   2       }
 263   1       else
 264   1       {
 265   2        for(i=0;i<16;i++)
 266   2        {
 267   3         DispRam[y>>3][x+i]    =StrAddr[0][i]<<(y%8)    |(DispRam[y>>3][x+i]    &(0xFF>>(8-(y%8))));

⌨️ 快捷键说明

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