C8051F330 Flash访问单元
2011-06-27 11:20
头文件自己搞吧,不贴了,写Flash时候记得先要擦除。 代码如下 01 /* 02 ================================================================================03 File Name : Flash.c 04 Description : C8051F330 Flash操作单元 05 Date : 2011-6-26 06 Version : V1.0 07 Author : pathletboy, pathletboy@gmail.com 08 Target device : any 09 Compiler : any 10 Note : 转载时务必保留此信息,否则无权以任何形式传播本文件 11 ================================================================================ 12 */ 13 14 #include <c8051f330.h> 15 #include "Flash.h" 16 17 unsigned char Flash_ReadByte( unsigned int addr) 18 { 19 return *( unsigned char code *) addr; 20 } 21 22 void Flash_ReadBytes( unsigned int addr , unsigned char * buff , unsigned int size) 23 { 24 unsigned int i; 25 unsigned char code * x; 26 x = ( unsigned char code *) addr; 27 for ( i = 0; i < size; i ++) 28 { 29 buff [ i ] = * x; 30 x ++; 31 } 32 } 33 34 void Flash_Erase( unsigned int addr) 35 { 36 unsigned char xdata * x; 37 x = ( unsigned char xdata *) addr; 38 PSCTL = 0x03; 39 FLKEY = 0xA5; 40 FLKEY = 0xF1; 41 * x = 0; 42 PSCTL = 0x00; 43 } 44 45 void Flash_WriteByte( unsigned int addr , unsigned char b) 46 { 47 unsigned char xdata * x; 48 x = ( unsigned char xdata *) addr; 49 PSCTL = 0x01; 50 FLKEY = 0xA5; 51 FLKEY = 0xF1; 52 * x = b; 53 PSCTL = 0x00; 54 } 55 56 void Flash_WriteBytes( unsigned int addr , unsigned char * buff , unsigned int size) 57 { 58 unsigned char xdata * x; 59 unsigned int i; 60 x = ( unsigned char xdata *) 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; |