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

📄 f330_flashp.#3

📁 f330与mfrc522 通信 构成读卡器 上传源码和原理图。
💻 #3
字号:
//-----------------------------------------------------------------------------
// F330_FlashPrimitives.c
//-----------------------------------------------------------------------------
// Copyright 2004 Silicon Laboratories, Inc.
// This program contains several useful utilities for writing and updating
// FLASH memory.
// AUTH: BW & GP
// DATE: 21 JUL 04
// Target: C8051F33x
// Tool chain: KEIL C51 7.06
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "F330_FlashP.h"
#include <c8051F330.h>
//-----------------------------------------------------------------------------
// Structures, Unions, Enumerations, and Type Definitions
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------

//************************************************************
// FLASH Routines
//************************************************************
// FLASH_Read:This routine copies <numbytes> from 
//the linear FLASH address <src> to <dest>.
//************************************************************
char * FLASH_Read (char *dest, FLADDR src, UCHAR numbytes)
{
   FLADDR i;

   for (i = 0; i < numbytes; i++) 
   {
      *dest++ = FLASH_ByteRead (src+i);
   }
   return dest;
}
//************************************************************
// FLASH_ByteRead:
//This routine reads a <byte> from the linear FLASH address <addr>.
//************************************************************
UCHAR FLASH_ByteRead (FLADDR addr)
{           
   char code * data pread;     // FLASH read pointer
   UCHAR byte;

   pread = (char code *)addr;
   byte = *pread;             // read the byte
   return byte;
}
//************************************************************
// FLASH_Write:This routine copies <numbytes> from <src> to
//************************************************************
void FLASH_Write (FLADDR dest, UCHAR *src, UCHAR numbytes)
{
   char xdata * data pwrite;  // FLASH write pointer
   UCHAR i;
   bit   EA_SAVE;

   pwrite = (char xdata *)dest;
   FLASH_PageErase (pwrite);

   EA_SAVE = EA;          // preserve EA
   i = 0;
   EA = 0;                    // disable interrupts
   // change clock speed to slow, then restore later
   VDM0CN = 0x80;                 // enable VDD monitor
   RSTSRC = 0x02;                 // enable VDD monitor as a reset source
   pwrite = (char xdata *) dest;

   PSCTL |= 0x01;                 // PSWE = 1

   for (i =0; i < numbytes; i++) 
     {
        FLKEY  = 0xA5;                 // Key Sequence 1
        FLKEY  = 0xF1;                 // Key Sequence 2
        pwrite =*src++;
      }
   PSCTL &= ~0x01;                // PSWE = 0
   EA = EA_SAVE;                  // restore interrupts
}

//************************************************************
// FLASH_ByteWrite:This routine writes <byte> to the linear FLASH address <addr>.
//To do:optimize to skip 0xFF bytes
//************************************************************
void FLASH_ByteWrite (FLADDR addr, UCHAR byte)
{
   bit EA_SAVE = EA;          // preserve EA
   char xdata * data pwrite;  // FLASH write pointer

   EA = 0;                    // disable interrupts
   // change clock speed to slow, then restore later
   VDM0CN = 0x80;                 // enable VDD monitor
   RSTSRC = 0x02;                 // enable VDD monitor as a reset source
   pwrite = (char xdata *) addr;

   PSCTL |= 0x01;                 // PSWE = 1
   FLKEY  = 0xA5;                 // Key Sequence 1
   FLKEY  = 0xF1;                 // Key Sequence 2
   
//   VDM0CN = 0x80;               // enable VDD monitor
//   RSTSRC = 0x02;               // enable VDD monitor as a reset source
   *pwrite = byte;                // write the byte
   PSCTL &= ~0x01;                // PSWE = 0
   EA = EA_SAVE;                  // restore interrupts
}
//************************************************************
// FLASH_PageErase:This routine erases the FLASH page containing 
//the linear FLASH address <addr>
//************************************************************
void FLASH_PageErase (FLADDR addr)
{  
   char xdata * data pwrite;     // FLASH write pointer
   bit EA_SAVE = EA;             // preserve EA

   EA = 0;                       // disable interrupts
   // change clock speed to slow, then restore later
   pwrite = (char xdata *) addr;

   PSCTL |= 0x03;                // PSWE = 1; PSEE = 1
   FLKEY  = 0xA5;                // Key Sequence 1
   FLKEY  = 0xF1;                // Key Sequence 2

   *pwrite = 0;                  // initiate page erase

   PSCTL &= ~0x03;               // PSWE = 0; PSEE = 0

   EA = EA_SAVE;                 // restore interrupts
}
//************************************************************

⌨️ 快捷键说明

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