头文件自己搞吧,不贴了,写Flash时候记得先要擦除。
代码如下
/*02 ================================================================================03 File Name : Flash.c04 Description : C8051F330 Flash操作单元06 Version : V1.011 ================================================================================ */13 14 #include <c8051f330.h>15 #include "Flash.h"16 17 unsignedcharFlash_ReadByte(unsignedintaddr)18 {19 return*(unsignedcharcode*)addr;20 }21 22 voidFlash_ReadBytes(unsignedintaddr,unsignedchar*buff,unsignedintsize)23 {24 unsignedinti;25 unsignedcharcode*x;26 x= (unsignedcharcode*)addr;27 for (i=0;i<size;i++)28 {29 buff[i]=*x;30 x++;31 }32 }33 34 voidFlash_Erase(unsignedintaddr)35 {36 unsignedcharxdata*x;37 x= (unsignedcharxdata*)addr;38 PSCTL=0x03;39 FLKEY=0xA5;40 FLKEY=0xF1;41 *x=0;42 PSCTL=0x00;43 }44 45 voidFlash_WriteByte(unsignedintaddr,unsignedchar b)46 {47 unsignedcharxdata*x;48 x= (unsignedcharxdata*)addr;49 PSCTL=0x01;50 FLKEY=0xA5;51 FLKEY=0xF1; 52 *x= b;53 PSCTL=0x00;54 }55 56 voidFlash_WriteBytes(unsignedintaddr,unsignedchar*buff,unsignedintsize)57 {58 unsignedcharxdata*x;59 unsignedinti;60 x= (unsignedcharxdata*)addr;61 PSCTL=0x01;62 for (i=0;i<size;i++)63 {64 FLKEY=0xA5;65 FLKEY=0xF1;66 *x=buff[i];67 x++;68 }69 PSCTL=0x00;