S3F84I9 EMBEDDED FLASH MEMORY自读写操作示例/********************************************************************
| Flash 操作模块函数 | 函数功能: 往某一个flash单元写单个byte数据 | 函数输入参数:写操作的目标flash地址,和写入的数据 | 函数输出参数:无 | $Revision: 0.0 $ | $Id: Full_Flash.c 0.0 2007/05/10 Weiningning OK $ ********************************************************************/ #include "ioS3C84i9_v.h" #include "intrinsics.h" #include "Constant.h" #define Uchar unsigned char #define Uint unsigned int void FLASH_WRITE(Uint addr,Uchar data) //对同一地址的写操作必须先做擦除操作 { Uchar temp; FlashDt = data; FlashAddr = addr; temp = addr; if (temp<0x80) { addr -= temp; } else { temp -= 0x80; addr -= temp; } FMUSR = 0xa5; //使能用户模式(使能flash操作) FMSECL = addr; //7f80H为欲进行写操作扇区的第一个地址 FMSECH = addr >>8; do //若擦除不成功则重新擦除 { FMCON = 0xa1; __no_operation(); __no_operation(); while(FMCON & 1==1); //等待本次擦除完成后再继续操作 } while (FMCON & 0x4 == 0x4); //write the specific data to the specific address FMCON = 0x50; //定义操作类型为 写 asm("PUSH R0"); asm("PUSH R2"); asm("PUSH R3"); asm("LDW RR2,FlashAddr"); // 必须是全局变量 asm("LD R0, FlashDt"); // 必须是全局变量 asm("LDC @RR2,R0"); asm("POP R0"); asm("POP R2"); asm("POP R3"); __no_operation(); FMUSR = 0; //关闭用户模式 |
ic168@zh-ic.COM
Development Tools:B6078S@163.com
Site suggestions:zh-ic@163.com
|
|||||||||