C8051F 内部Flash读写
来源:互联网 发布:知乎你懂的网站 编辑:程序博客网 时间:2024/05/14 14:46
#include "Head.h"
//-----------------------------------------------------------------------------
// FLASH_ByteWrite
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters :
// 1) FLADDR addr - address of the byte to write to
// valid range is 0x0000 to 0xFBFF for 64K Flash devices
// valid range is 0x0000 to 0x7FFF for 32K Flash devices
// 2) U8 byte - byte to write to Flash.
//
// This routine writes <byte> to the linear FLASH address <addr>.
//-----------------------------------------------------------------------------
U8 Flash_data[30];
void FLASH_ByteWrite (FLADDR addr, U8 byte)
{
bit EA_SAVE = EA; // Preserve EA
U8 xdata * data pwrite; // FLASH write pointer
U8 SFRPAGE_save = SFRPAGE;
SFRPAGE = ACTIVE_PAGE;
EA = 0; // Disable interrupts
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
RSTSRC = 0x02; // Enable VDD monitor as a reset source
pwrite = (U8 xdata *) addr;
FLKEY = 0xA5; // Key Sequence 1
FLKEY = 0xF1; // Key Sequence 2
PSCTL |= 0x01; // PSWE = 1 which enables writes
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
RSTSRC = 0x02; // Enable VDD monitor as a reset source
*pwrite = byte; // Write the byte
PSCTL &= ~0x01; // PSWE = 0 which disable writes
EA = EA_SAVE; // Restore interrupts
SFRPAGE = SFRPAGE_save;
}
//-----------------------------------------------------------------------------
// FLASH_ByteRead
//-----------------------------------------------------------------------------
//
// Return Value :
// U8 - byte read from Flash
// Parameters :
// 1) FLADDR addr - address of the byte to read to
// valid range is 0x0000 to 0xFBFF for 64K Flash devices
// valid range is 0x0000 to 0x7FFF for 32K Flash devices
//
// This routine reads a <byte> from the linear FLASH address <addr>.
//-----------------------------------------------------------------------------
U8 FLASH_ByteRead (FLADDR addr)
{
bit EA_SAVE = EA; // Preserve EA
U8 code * data pread; // FLASH read pointer
U8 byte;
EA = 0; // Disable interrupts
pread = (U8 code *) addr;
byte = *pread; // Read the byte
EA = EA_SAVE; // Restore interrupts
return byte;
}
//-----------------------------------------------------------------------------
// FLASH_PageErase
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters :
// 1) FLADDR addr - address of any byte in the page to erase
// valid range is 0x0000 to 0xF9FF for 64K Flash devices
// valid range is 0x0000 to 0x7DFF for 32K Flash devices
//
// This routine erases the FLASH page containing the linear FLASH address
// <addr>. Note that the page of Flash containing the Lock Byte cannot be
// erased from application code.
//-----------------------------------------------------------------------------
void FLASH_PageErase (FLADDR addr)
{
bit EA_SAVE = EA; // Preserve EA
U8 xdata * data pwrite; // FLASH write pointer
U8 SFRPAGE_save = SFRPAGE;
SFRPAGE = ACTIVE_PAGE;
EA = 0; // Disable interrupts
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
RSTSRC = 0x02; // Enable VDD monitor as a reset source
pwrite = (U8 xdata *) addr;
FLKEY = 0xA5; // Key Sequence 1
FLKEY = 0xF1; // Key Sequence 2
PSCTL |= 0x03; // PSWE = 1; PSEE = 1
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
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
SFRPAGE = SFRPAGE_save;
}
void FLASH_ReadData(U8 *buffer,U8 length)
{
U8 i;
for(i = 0; i < length ; i++){
buffer[i] = FLASH_ByteRead (start_address + i);
}
}
void FLASH_WriteData(U8 *buffer,U8 length)
{
U8 i;
for(i = 0; i < length; i ++){
FLASH_PageErase(start_address + i);
}
for(i = 0; i < length; i ++){
FLASH_ByteWrite (start_address + i, buffer[i]);
}
}
void Flash_data_init()
{
U8 i;
for(i = 0; i < 30; i++){
Flash_data[i] = 0x00;
}
}
//-----------------------------------------------------------------------------
// FLASH_ByteWrite
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters :
// 1) FLADDR addr - address of the byte to write to
// valid range is 0x0000 to 0xFBFF for 64K Flash devices
// valid range is 0x0000 to 0x7FFF for 32K Flash devices
// 2) U8 byte - byte to write to Flash.
//
// This routine writes <byte> to the linear FLASH address <addr>.
//-----------------------------------------------------------------------------
U8 Flash_data[30];
void FLASH_ByteWrite (FLADDR addr, U8 byte)
{
bit EA_SAVE = EA; // Preserve EA
U8 xdata * data pwrite; // FLASH write pointer
U8 SFRPAGE_save = SFRPAGE;
SFRPAGE = ACTIVE_PAGE;
EA = 0; // Disable interrupts
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
RSTSRC = 0x02; // Enable VDD monitor as a reset source
pwrite = (U8 xdata *) addr;
FLKEY = 0xA5; // Key Sequence 1
FLKEY = 0xF1; // Key Sequence 2
PSCTL |= 0x01; // PSWE = 1 which enables writes
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
RSTSRC = 0x02; // Enable VDD monitor as a reset source
*pwrite = byte; // Write the byte
PSCTL &= ~0x01; // PSWE = 0 which disable writes
EA = EA_SAVE; // Restore interrupts
SFRPAGE = SFRPAGE_save;
}
//-----------------------------------------------------------------------------
// FLASH_ByteRead
//-----------------------------------------------------------------------------
//
// Return Value :
// U8 - byte read from Flash
// Parameters :
// 1) FLADDR addr - address of the byte to read to
// valid range is 0x0000 to 0xFBFF for 64K Flash devices
// valid range is 0x0000 to 0x7FFF for 32K Flash devices
//
// This routine reads a <byte> from the linear FLASH address <addr>.
//-----------------------------------------------------------------------------
U8 FLASH_ByteRead (FLADDR addr)
{
bit EA_SAVE = EA; // Preserve EA
U8 code * data pread; // FLASH read pointer
U8 byte;
EA = 0; // Disable interrupts
pread = (U8 code *) addr;
byte = *pread; // Read the byte
EA = EA_SAVE; // Restore interrupts
return byte;
}
//-----------------------------------------------------------------------------
// FLASH_PageErase
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters :
// 1) FLADDR addr - address of any byte in the page to erase
// valid range is 0x0000 to 0xF9FF for 64K Flash devices
// valid range is 0x0000 to 0x7DFF for 32K Flash devices
//
// This routine erases the FLASH page containing the linear FLASH address
// <addr>. Note that the page of Flash containing the Lock Byte cannot be
// erased from application code.
//-----------------------------------------------------------------------------
void FLASH_PageErase (FLADDR addr)
{
bit EA_SAVE = EA; // Preserve EA
U8 xdata * data pwrite; // FLASH write pointer
U8 SFRPAGE_save = SFRPAGE;
SFRPAGE = ACTIVE_PAGE;
EA = 0; // Disable interrupts
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
RSTSRC = 0x02; // Enable VDD monitor as a reset source
pwrite = (U8 xdata *) addr;
FLKEY = 0xA5; // Key Sequence 1
FLKEY = 0xF1; // Key Sequence 2
PSCTL |= 0x03; // PSWE = 1; PSEE = 1
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
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
SFRPAGE = SFRPAGE_save;
}
void FLASH_ReadData(U8 *buffer,U8 length)
{
U8 i;
for(i = 0; i < length ; i++){
buffer[i] = FLASH_ByteRead (start_address + i);
}
}
void FLASH_WriteData(U8 *buffer,U8 length)
{
U8 i;
for(i = 0; i < length; i ++){
FLASH_PageErase(start_address + i);
}
for(i = 0; i < length; i ++){
FLASH_ByteWrite (start_address + i, buffer[i]);
}
}
void Flash_data_init()
{
U8 i;
for(i = 0; i < 30; i++){
Flash_data[i] = 0x00;
}
}
1 0
- C8051F 内部Flash读写
- C8051F的读写芯片FLASH的注意事项
- stm32 读写内部Flash
- STM32读写内部Flash
- STM32 读写内部Flash
- STM32内部flash读写
- C8051F外部存储器读写
- STR710的内部Flash读写
- STM32内部FLASH读写-通用
- 读写STM32内部flash读写代码
- 读写STM32内部flash读写代码
- 读写STM32内部flash读写代码
- 读写STM32内部flash读写代码
- STM32F10X读写内部FLASH的完整工程
- STM32 对内部FLASH读写接口函数
- STM32 对内部FLASH读写接口函数
- STM32 对内部FLASH读写接口函数
- STM32F103系列内部Flash读写程序
- win32汇编显示一个窗口
- core data support undo manager
- c++学习笔记(14.函数模板)
- linux基础(ubuntu)
- JSP简单介绍
- C8051F 内部Flash读写
- Net读取Excel 返回DataTable
- C8051F外部存储器读写
- ios开发(二十二)坐标的错乱
- C8051 ADC控制
- 深入研究字节对齐问题 .
- 高效网站开发缓存技术应用——网页输出缓存(Ⅱ)
- 青蛙的约会 (数论)
- 配置AD9512