c8051f410单片机的Flash读写程序

来源:本站
导读:目前正在解读《c8051f410单片机的Flash读写程序》的相关信息,《c8051f410单片机的Flash读写程序》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《c8051f410单片机的Flash读写程序》的详细说明。
简介:这是个C文件,打加可以看看

//============================================================================

//该程序执行片内FLASH的读写操作,将0-9十个数写入到起始地址为0X1000的FLASH空间中.

//-----------------------------------------------------------------------------

// Includes

//-----------------------------------------------------------------------------

#include <c8051f410.h> // Header file for SiLabs c8051f320

// Header file for USB_API.lib

//-----------------------------------------------------------------------------

// 16-bit SFR Definitions for 'F32x

//-----------------------------------------------------------------------------

sfr16 DP = 0x82; // data pointer

sfr16 TMR2RL = 0xca; // Timer2 reload value

sfr16 TMR2 = 0xcc; // Timer2 counter

sfr16 TMR3 = 0x94; // Timer3 counter

sfr16 TMR3RL = 0x92; // Timer3 reload value

sfr16 PCA0CP0 = 0xfb; // PCA0 Module 0 Capture/Compare

sfr16 PCA0CP1 = 0xe9; // PCA0 Module 1 Capture/Compare

sfr16 PCA0CP2 = 0xeb; // PCA0 Module 2 Capture/Compare

sfr16 PCA0CP3 = 0xed; // PCA0 Module 3 Capture/Compare

sfr16 PCA0CP4 = 0xfd; // PCA0 Module 4 Capture/Compare

sfr16 PCA0 = 0xf9; // PCA0 counter

//-----------------------------------------------------------------------------

// MAIN Routine

//-----------------------------------------------------------------------------

void main (void)

{

unsigned char xdata *pwrite; // pointer to FLASH used for writes

// NOTE: this pointer must be located

// in <data> or <idata> space!

unsigned char code *pread; // pointer to FLASH used for reads

char EA_save; // saves the current state of the

// interrupt enable bit.

// test string

unsigned char code test_string[] = "012345678901111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333344444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555666666666666666666666666666666666666666666666666666666666666666666666666677777777777777777777777777777777777777777777777777777777777777777777777777777777777777778888888888888888888888888888888888888888888888888888888888888888888888888899999999999999999999999999999999999999999999!";

PCA0MD &= ~0x40;//禁止看门狗定时器

OSCICN = 0x86;//时钟分24.5M的2分频12.25M

// Disable Watchdog timer

RSTSRC |= 0x02; // enable the VDD monitor

// Disable Watchdog timer // WDTE = 0 (clear watchdog timer

// enable)

// erase the FLASH page at 0x1000

EA_save = EA;

EA = 0; // disable interrupts (precautionary)

// initialize write/erase pointer

pwrite = (unsigned char xdata *) 0x1000;

PSCTL = 0x03; // MOVX writes erase FLASH page

FLKEY = 0xA5; // FLASH lock and key sequence 1

FLKEY = 0xF1; // FLASH lock and key sequence 2

*pwrite = 0; // initiate page erase

PSCTL = 0; // MOVX writes target XRAM

EA = EA_save; // re-enable interrupts

// copy a string to FLASH memory at address 0x1000

// initialize FLASH read pointer

pread = (unsigned char code *) test_string;

EA_save = EA;

EA = 0; // disable interrupts (precautionary)

pwrite = 0x1000; // initialize FLASH write pointer

PSCTL = 0x01; // MOVX writes target FLASH memory

while (*pread != '') // copy until NULL is detected

{

FLKEY=0xA5;//FLASHlockandkeysequence1

FLKEY=0xF1;//FLASHlockandkeysequence2

*pwrite=*pread;//copybyte

pread++;//advancepointers

pwrite++;

}

FLKEY = 0xA5; // FLASH lock and key sequence 1

FLKEY = 0xF1; // FLASH lock and key sequence 2

*pwrite = ''; // NULL-terminate string

PSCTL = 0x00; // MOVX writes target XRAM

EA = EA_save; // re-enable interrupts

while (1)

{ // spin forever

}

}

提醒:《c8051f410单片机的Flash读写程序》最后刷新时间 2024-03-14 01:14:14,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《c8051f410单片机的Flash读写程序》该内容的真实性请自行鉴别。