//-----------------------------------------------------------------------------
// C8051_F340_FlashPrimitives.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program contains several useful utilities for writing and updating
// FLASH memory.
//
// FID: 34X000024
// Target: C8051F34x
// Tool chain: Keil C51 8.00 / Keil EVAL C51
// Command Line: None
//
// Release 1.0
// -Initial Revision (GP)
// -30 JAN 2006
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "C8051_F340_FlashPrimitives.h"
#include <c8051F340.h>
//-----------------------------------------------------------------------------
// Structures, Unions, Enumerations, and Type Definitions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------
// FLASH read/write/erase routines
void FLASH_ByteWrite (FLADDR addr, char byte);
unsigned char FLASH_ByteRead (FLADDR addr);
void FLASH_PageErase (FLADDR addr);
//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// FLASH Routines
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// FLASH_ByteWrite
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters :
// 1) FLADDR addr - target address to write to
// range is 0 to (FLASH_TEMP-1)
// 2) char byte - byte to write
//
// This routine writes <byte> to the linear FLASH address <addr>.
//
//-----------------------------------------------------------------------------
void FLASH_ByteWrite (FLADDR addr, char 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;
FLKEY = 0xA5; // Key Sequence 1
FLKEY = 0xF1; // Key Sequence 2
PSCTL |= 0x01; // PSWE = 1
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_ByteRead
//-----------------------------------------------------------------------------
//
// Return Value :
// 1) unsigned char - byte that was read from Flash
// Parameters :
// 1) FLADDR addr - target address to write to
// range is 0 to (FLASH_TEMP-1)
//
// This routine reads a <byte> from the linear FLASH address <addr>.
//
//-----------------------------------------------------------------------------
unsigned char FLASH_ByteRead (FLADDR addr)
{
bit EA_SAVE = EA; // Preserve EA
char code * data pread; // FLASH read pointer
unsigned char byte;
EA = 0; // Disable interrupts
pread = (char code *) addr;
byte = *pread; // Read the byte
EA = EA_SAVE; // Restore interrupts
return byte;
}
//-----------------------------------------------------------------------------
// FLASH_PageErase
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters :
// 1) FLADDR addr - target address to write to
// range is 0 to (FLASH_TEMP-1)
//
// This routine erases the FLASH page containing the linear FLASH address
// <addr>.
//
//-----------------------------------------------------------------------------
void FLASH_PageErase (FLADDR addr)
{
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;
FLKEY = 0xA5; // Key Sequence 1
FLKEY = 0xF1; // Key Sequence 2
PSCTL |= 0x03; // PSWE = 1; PSEE = 1
VDM0CN = 0x80; // Enable VDD monitor
RSTSRC = 0x02; // Enable VDD monitor as a reset source
*pwrite = 0; // Initiate page erase
PSCTL &= ~0x03; // PSWE = 0; PSEE = 0
EA = EA_SAVE; // Restore interrupts
}
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
C8051F330 340 内部flash读写功能代码 在项目中已经过验证 亲测可用

C8051F330 340 已经过验证 可用,描述里是调用函数,使用的时候应当注意地址位,f330和f340的flash地址,以及地址写保护方面留意一下。确保存储的地址是正确的即可使用。
可以根据实际使用需求更换形参,即可轻松拓展。


玄壹
- 粉丝: 2
最新资源
- 路径规划领域中跳点搜索算法及其改进版本的技术解析与应用
- DSP驱动的数字电源系统:基于C2000主控的300W Buck-Boost双向变换器设计方案与实现
- COMSOL光学模拟:高斯光束通过偏振棱镜与反射面后的光强质心偏移研究 (07月28日)
- 工业自动化中WINCC系统的水电气能源报表自动化管理及应用
- 格子玻尔兹曼LBM D3Q19方法在多孔介质渗流场求解与可视化的应用研究 · D3Q19 完整版
- 基于Simulink的永磁同步电机滑模观测器无位置传感器控制仿真模型研究
- 基于Matlab的指纹识别系统设计:从特征提取到GUI实现
- VB工业自动化项目:27轴混合驱动与精准喷胶系统的实现及应用
- 电力系统仿真中变压器励磁涌流的Python建模与分析 Python
- PLC1200与Factory IO联机仿真的模拟工厂设计及其实现方法 · PLC编程
- 永磁同步电机PMSM负载状态估计与MATLABSimulink仿真模型研究
- 永磁同步电机PMSM的5+7次谐波注入与死区补偿技术:降低转矩脉动及电压补偿的PPT与Simulink模型说明
- Comsol燃料电池模型:等温和不等温仿真的研究与应用
- 永磁同步电机全速域无位置传感器控制的仿真研究:采用高频注入改进滑膜控制方法及PMSM矢量控制仿真 高频注入 高级版
- 基于灰狼优化算法的光伏MPPT控制策略:局部遮阴环境下的阴影动态与应对措施
- 离线DP动态规划节能速度规划与Carsim联合仿真验证:电动汽车高效能解决方案 - 动态规划