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

📄 loader_f02x.lst

📁 C8051F单片机在系统编程和在应用编程实例
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   LOADER_F02X                                                           09/07/2007 14:28:22 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE LOADER_F02X
OBJECT MODULE PLACED IN loader_F02x.OBJ
COMPILER INVOKED BY: E:\Keil\C51\BIN\C51.EXE loader_F02x.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // loader_F02x.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2002 Cygnal Integrated Products, Inc.
   5          // 交互选择性固件刷新程序,针对BTF020开发板做了程序改动;针对一些keil c语言函数做了注释说明
   6          // AUTH: 钟磊
   7          // DATE: 04 sep 07
   8          //
   9          // This program shows an example 'selective code loader' using the 'F02x. It 
  10          // designates the FLASH page at 0x1000 for the code loaded through the UART. 
  11          // 
  12          // Control Function:
  13          //
  14          // The system is controlled via the hardware UART, operating at a baud rate
  15          // determined by the constant <BAUDRATE>, using Timer1 overflows as the baud
  16          // rate source.
  17          //
  18          // Received File Type:
  19          //
  20          // This example receives Intel HEX files which are OMF51 (linker output files)
  21          // passed through the OH51 utility in the 'CYGNAL\IDEfiles\C51\Bin' folder. 
  22          // 
  23          // Note: Because this program writes to FLASH, the MONEN pin should be tied 
  24          //       high.
  25          //
  26          // Target: C8051F02x
  27          // Tool chain: KEIL C51 6.03 / KEIL EVAL C51
  28          //
  29          
  30          //-----------------------------------------------------------------------------
  31          // Includes
  32          //-----------------------------------------------------------------------------
  33          #include <c8051f020.h>                 // SFR declarations
  34          #include <stdio.h>                     // printf() and getchar()
  35          #include <ctype.h>                     // tolower() and toint()
  36          
  37          //-----------------------------------------------------------------------------
  38          // 16-bit SFR Definitions for 'F02x
  39          //-----------------------------------------------------------------------------
  40          sfr16 DP       = 0x82;                 // data pointer
  41          sfr16 TMR3RL   = 0x92;                 // Timer3 reload value
  42          sfr16 TMR3     = 0x94;                 // Timer3 counter
  43          sfr16 ADC0     = 0xbe;                 // ADC0 data
  44          sfr16 ADC0GT   = 0xc4;                 // ADC0 greater than window
  45          sfr16 ADC0LT   = 0xc6;                 // ADC0 less than window
  46          sfr16 RCAP2    = 0xca;                 // Timer2 capture/reload
  47          sfr16 T2       = 0xcc;                 // Timer2
  48          sfr16 RCAP4    = 0xe4;                 // Timer4 capture/reload
  49          sfr16 T4       = 0xf4;                 // Timer4
  50          sfr16 DAC0     = 0xd2;                 // DAC0 data
  51          sfr16 DAC1     = 0xd5;                 // DAC1 data
  52          
  53          //-----------------------------------------------------------------------------
  54          // Global CONSTANTS
  55          //-----------------------------------------------------------------------------
C51 COMPILER V7.50   LOADER_F02X                                                           09/07/2007 14:28:22 PAGE 2   

  56          #define TRUE         1
  57          #define FALSE        0
  58          
  59          #define SYSCLK       22118400          // SYSCLK frequency in Hz
  60          #define BAUDRATE     115200           // Baud rate of UART in bps
  61          
  62          sbit LED = P2^4;                       // LED='1' means ON
  63          sbit SW2 = P2^0;                       // SW2='0' 表示按键按下
  64          
  65          //-----------------------------------------------------------------------------
  66          // Reserved Memory Space
  67          //-----------------------------------------------------------------------------
  68          
  69          char reserved_memory_bank[2] _at_ 0x08;// This memory bank is used by the
  70                                                 // functions that will be loaded 
  71                                                 // through the UART.
  72                                                 // The memory bank location and size
  73                                                 // are based on values from the M51 map
  74                                                 // file generated when the loaded code
  75                                                 // is linked.
  76                                                                                     //保留数据区的大小有待刷程序所使用的数据区
  77                                                                                     //大小决定,可以查看M51文件得到
  78          
  79          //-----------------------------------------------------------------------------
  80          // Function PROTOTYPES
  81          //-----------------------------------------------------------------------------
  82          
  83          void main (void);
  84          
  85          // Support Subroutines
  86          void print_menu(void);
  87          void erase_flash_page(void);
  88          void receive_code(void);
  89          unsigned char hex2char();
  90          
  91          // Initialization Subroutines
  92          void SYSCLK_Init (void);
  93          void PORT_Init (void);
  94          void UART0_Init (void);
  95          
  96          //-----------------------------------------------------------------------------
  97          // Global VARIABLES
  98          //-----------------------------------------------------------------------------
  99          
 100          #define input_str_len 4                // buffer to hold characters entered               
 101          char input_str[input_str_len];         // at the command prompt
 102          
 103          void (*f)();                           // function pointer declaration
 104          
 105          bit code_erased = FALSE;               // flag used to indicate that the FLASH
 106                                                 // erase operation is complete
 107          bit f_valid = FALSE;                   // flag to indicate that the FLASH 
 108                                                 // programming operation is complete
 109                                                                                     // 标志先置零
 110          
 111          //-----------------------------------------------------------------------------
 112          // MAIN Routine
 113          //-----------------------------------------------------------------------------
 114          
 115          void main (void) 
 116          {
 117   1      
C51 COMPILER V7.50   LOADER_F02X                                                           09/07/2007 14:28:22 PAGE 3   

 118   1         WDTCN = 0xde;                       // disable watchdog timer
 119   1         WDTCN = 0xad;
 120   1      
 121   1         PORT_Init ();                       // initialize crossbar and GPIO
 122   1         SYSCLK_Init ();                     // initialize oscillator
 123   1         UART0_Init ();                      // initialize UART0
 124   1         
 125   1         print_menu();                       // print the command menu
 126   1      
 127   1         while (1){
 128   2               
 129   2            printf("\nEnter a command >");
 130   2            gets(input_str, input_str_len);  //gets()读取的字符串,其长度没有限制,编程
 131   2                                                 //者要保证字符数组有足够大的空间,存放输入的字符串。
 132   2      
 133   2            
 134   2            switch ( input_str[0] ){
 135   3            
 136   3               case '1': erase_flash_page();   
 137   3                         printf("\nFlash page 0x1000 has been erased.\n");
 138   3                         break;
 139   3      
 140   3               case '2': printf("\nReady to receive HEX file...\n");
 141   3                         receive_code();
 142   3                         break;
 143   3      
 144   3               case '3': if(f_valid){
 145   4                           f = (void code *) 0x1000;
 146   4                           f();
 147   4                           printf("\nFinished\n");
 148   4                         } else {
 149   4                           printf("\n*** No function exists at 0x1000.\n");
 150   4                         }
 151   3                         break; 
 152   3      
 153   3               case '?': print_menu(); 
 154   3                         break;    
 155   3      
 156   3               default:  printf("\n*** Unknown Command.\n");
 157   3                         break;
 158   3            }   
 159   2      
 160   2         } // end while
 161   1      
 162   1      } // end main
 163          
 164          //-----------------------------------------------------------------------------
 165          // Support Subroutines
 166          //-----------------------------------------------------------------------------
 167          //-----------------------------------------------------------------------------
 168          // print_menu
 169          //-----------------------------------------------------------------------------
 170          //
 171          // This routine uses prints the command menu to the UART.
 172          //
 173          void print_menu(void)
 174          {
 175   1         printf("\nC8051F020 in application programming\n");
 176   1         printf("--------------------------------------\n");
 177   1         printf("1. Erase the flash page at 0x1000\n");
 178   1         printf("2. Receive HEX file\n");
 179   1         printf("3. Execute the function at 0x1000\n");
C51 COMPILER V7.50   LOADER_F02X                                                           09/07/2007 14:28:22 PAGE 4   

 180   1         printf("?. Print Command List\n");
 181   1      }
 182          
 183          //-----------------------------------------------------------------------------
 184          // hex2char
 185          //-----------------------------------------------------------------------------
 186          //
 187          // This routine converts a two byte ascii representation of a char to an
 188          // 8-bit variable;
 189          //
 190          unsigned char hex2char()
 191          {
 192   1         
 193   1         unsigned char retval;
 194   1         char byteH, byteL;
 195   1         
 196   1         // get a two-byte ASCII representation of a char from the UART
 197   1         byteH = _getkey();          //等待一个字符(使用_getkey函数)  
 198   1                                     //函数_getkey和putchar使用片内串口来完成串行I/O
 199   1         byteL = _getkey();          //这些子程序包含在C51库中,每个函数的源文件位于\C51\LIB目录下
 200   1         
 201   1         // convert to a single 8 bit result
 202   1         retval = (char) toint(byteH) * 16;       //toint可重入转换一个十六进制数为一个十进制数
 203   1      
 204   1         retval += (char) toint(byteL);
 205   1         return retval;
 206   1      }
 207          
 208          //-----------------------------------------------------------------------------
 209          // erase_flash_page
 210          //-----------------------------------------------------------------------------

⌨️ 快捷键说明

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