C51 COMPILER V9.54   EEPROM                                                                12/03/2024 14:58:46 PAGE 1   


C51 COMPILER V9.54, COMPILATION OF MODULE EEPROM
OBJECT MODULE PLACED IN .\Objects\eeprom.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE public\eeprom.c OPTIMIZE(8,SPEED) BROWSE INCDIR(.\public) DEBUG OBJECTEX
                    -TEND PRINT(.\Listings\eeprom.lst) OBJECT(.\Objects\eeprom.obj)

line level    source

   1          #include "eeprom.h"
   2          
   3          
   4          uint8_t code emenu1[]="Please input command:\r\n";
   5          uint8_t code emenu2[]="command:0xa5(write),0xaa(read)\r\n";
   6          uint8_t code emenu3[]="format(hex)：command,address,data\r\n";
   7          
   8          
   9          void EEPROM_Wirte(uint8_t addr,uint8_t wdat)
  10          {
  11   1              FSHADRH = 0xF0; //EEPROM 起始地址为0xF000
  12   1              FSHADRL = addr;
  13   1              FSHDATL = wdat;
  14   1              EA = 0;
  15   1              FSHCON = 0xA5;  //启动FLASH编程操作
  16   1              while(FSHCON & 0x01);
  17   1              while(FSHCON & 0x02);
  18   1              EA = 1;
  19   1      }
  20          uint8_t EEPROM_Read(uint8_t addr)
  21          {
  22   1              uint8_t temp;
  23   1              uint8_t code *temp1;
  24   1              temp1 = 0xF000 + addr; //EEPROM 起始地址为0xF000
  25   1              temp = *temp1;
  26   1              return temp;
  27   1      }
  28          
  29          void receive1(uint8_t *rc,uint8_t count)
  30          {
  31   1              while(count--)
  32   1              {
  33   2                      while(~SCON & 0x01);
  34   2                      SCON ^= 0x01;
  35   2                      *rc = SBUF;
  36   2                      rc++;
  37   2              }
  38   1      }
  39          
  40          /*
  41          串口以(命令，地址，数据)格式发送3个字节；如果收到写命令(0xA5)，
  42          会在相应的地址写入数据；如果收到读命令(0xAA)，会通过串口发出
  43          相应地址的数据
  44          通信数据使用hex格式
  45          eg:串口收到 0xa5 0x10 0x47，表示在0x10地址写0x47
  46          eg:串口收到 0xaa 0x10 0xxx，表示读取0x10地址的数据
  47          */
  48          
  49          void EEPROM_Test(void)
  50          {
  51   1              uint8_t rc[3];
  52   1              uint8_t temp;
  53   1              
  54   1              /***********add flash clk div**************/
C51 COMPILER V9.54   EEPROM                                                                12/03/2024 14:58:46 PAGE 2   

  55   1              temp = SYSCON & 0xC0;
  56   1              switch(temp)
  57   1              {
  58   2                      case 0x80: //2Mhz
  59   2                              FSDIV = 0x04;   // FLASH 编程时钟分频到 200KHz,分频比fsys/(2*(FSDIV+1))
  60   2                              break;
  61   2                      case 0x40: //1Mhz
  62   2                              FSDIV = 0x02;   // FLASH 编程时钟分频到 200KHz,分频比fsys/(2*(FSDIV+1))
  63   2                              break;
  64   2                      case 0xC0: //4Mhz
  65   2                              FSDIV = 0x09;   // FLASH 编程时钟分频到 200KHz,分频比fsys/(2*(FSDIV+1))
  66   2                              break;
  67   2                      default:
  68   2                              break;                          
  69   2              }
  70   1              /***********************/
  71   1              Uart_Init();
  72   1              sendString(emenu1);
  73   1              sendString(emenu2);
  74   1              sendString(emenu3);
  75   1      
  76   1              while(1)
  77   1              {
  78   2                      receive1(rc,3);
  79   2                      if(rc[0] == 0xA5 && rc[1] < 0x80)
  80   2                      {
  81   3                              EEPROM_Wirte(rc[1],rc[2]);
  82   3                      }
  83   2                      if(rc[0] == 0xAA && rc[1] < 0x80)
  84   2                      {
  85   3                              sendChar(EEPROM_Read(rc[1]));
  86   3                      }
  87   2                      
  88   2              }
  89   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    181    ----
   CONSTANT SIZE    =     93    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       3
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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