【技术分享】C8051F330 Flash访问单元
0赞
发表于 1/9/2014 1:14:06 PM
阅读(2470)
最近写的一个小程序,贡献给大家参考
C8051F330 Flash访问单元
2011-06-27 11:20
头文件自己搞吧,不贴了,写Flash时候记得先要擦除。 代码如下 /* 02 ================================================================================ 03 File Name : Flash.c 04 Description : C8051F330 Flash操作单元 06 Version : V1.0 11 ================================================================================ */ 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;
|