www.pudn.com > RC522.zip > interflash.c, change:2015-04-14,size:2177b


#include "interflash.h" 
  
BOOL Change_KEYB(u8 array[]) 
{  
//	u8 bufer[6]; 
	INTERNAL_FlashPageErase(KEY_ADDR); 
	INTERNAL_FlashWriteByte(KEY_ADDR,array[0]); 
	INTERNAL_FlashWriteByte(KEY_ADDR+4,array[1]); 
	INTERNAL_FlashWriteByte(KEY_ADDR+8,array[2]); 
	INTERNAL_FlashWriteByte(KEY_ADDR+12,array[3]); 
	INTERNAL_FlashWriteByte(KEY_ADDR+16,array[4]); 
	INTERNAL_FlashWriteByte(KEY_ADDR+20,array[5]); 
 	 
 	if(INTERNAL_FlashReadByte(KEY_ADDR+3)==array[0]&& 
 		INTERNAL_FlashReadByte(KEY_ADDR+7)==array[1]&& 
 		INTERNAL_FlashReadByte(KEY_ADDR+11)==array[2]&& 
 		INTERNAL_FlashReadByte(KEY_ADDR+15)==array[3]&& 
 		INTERNAL_FlashReadByte(KEY_ADDR+19)==array[4]&& 
 		INTERNAL_FlashReadByte(KEY_ADDR+23)==array[5] 
 	) 
	 
 		return TRUE; 
 	else 
 		return FALSE; 
	 
//		bufer[0]= INTERNAL_FlashReadByte(KEY_ADDR+3) ;  
//		bufer[1]=INTERNAL_FlashReadByte(KEY_ADDR+7) ;  
//		bufer[2]=INTERNAL_FlashReadByte(KEY_ADDR+11) ;  
//		bufer[3]=INTERNAL_FlashReadByte(KEY_ADDR+15);  
//		bufer[4]=INTERNAL_FlashReadByte(KEY_ADDR+19) ;  
//		bufer[5]=INTERNAL_FlashReadByte(KEY_ADDR+23); 
//	  
//   return TRUE; 
} 
 
void GET_KEY(u8 *array,u8 len) 
{ 
	u8 i; 
	for(i=0;i<len;i++) 
	{ 
		*(array+i)= INTERNAL_FlashReadByte(KEY_ADDR+3+4*i) ;  
	} 
} 
void INTERNAL_FlashUnlock(void) 
{ 
	FLASH_Unlock(); 
} 
 
 
void INTERNAL_FlashLock(void) 
{ 
	FLASH_Lock(); 
} 
 
 
 
u8 INTERNAL_FlashReadByte(u32 addr) 
{ 
	u32 *pDat; 
	u8 offset; 
 
	offset = addr%4; 
	pDat = (u32*)(addr-offset); 
	return (((*pDat)>>((3-offset)*8))&0xFF); 
} 
 
 
BOOL INTERNAL_FlashPageErase(u32 addr) 
{ 
	FLASH_Status status; 
 
	INTERNAL_FlashUnlock(); 
	FLASH_ClearFlag(FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR|FLASH_FLAG_EOP); 
	status = FLASH_ErasePage(addr); 
	INTERNAL_FlashLock(); 
	if(status==FLASH_COMPLETE) 
	{ 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
} 
BOOL INTERNAL_FlashWriteByte(u32 addr,u32 byte) 
{ 
	FLASH_Status status; 
	 
	INTERNAL_FlashUnlock(); 
	FLASH_ClearFlag(FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR|FLASH_FLAG_EOP); 
	status = FLASH_ProgramWord(addr,byte); 
	INTERNAL_FlashLock(); 
	if(status==FLASH_COMPLETE) 
	{ 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
}