- /**********************************************************************
- *
- * 实验名称:FLASH操作
- * 实验平台:NV32开发板
- * 板载芯片:NV32F101FL64E
- * 实验效果:使用FLASH模拟EEPROM,实现字节的编程
- *
- ************************************************************************/
- #include "common.h"
- #include "rtc.h"
- #include "flash.h"
- #include "sysinit.h"
- #include "eeprom.h"
- int main (void);
- /********************************************************************/
- int main (void)
- {
- char ch;
- uint32_t i;
- uint8_t u8DataBuff[512];
- sysinit();
- printf("\nRunning the Flash_demo project.\n");
- LED0_Init();
- LED2_Init();
- Flash_Init();
- /*对FLASH第60个扇区进行擦-读-写 */
-
- /* 擦除第60个扇区*/
- Flash_EraseSector(60*FLASH_SECTOR_SIZE);
-
- for(i=0;i<512;i++)
- {
- u8DataBuff[i] = (uint8_t)i;
- }
-
- /*向擦除的扇区写入数据*/
- Flash_Program(60*FLASH_SECTOR_SIZE,&u8DataBuff[0],512 );
-
- for( i=0;i<512/16;i++ )
- {
- for(ch =0;ch<16;ch++)
- {
- printf("0x%x,",*((uint8_t *)(i*16+ch+60*FLASH_SECTOR_SIZE)));
- }
- printf("\n");
- }
- /*********************************************************************************
- *
- * EEPROM 使用范例
- * EEPROM 第一次使用前,可以先erase,这样可以提高写的效率
- * 一次只能写一个双字,如果写byte,可以先处理一下然后写
- * 小于10byte,单独调用EEPROM_Write 效率可能更高,EERPOM_Writeup4byte建议在写比较长数据时使用
- *
- **********************************************************************************/
- EEPROM_Erase(0x00);
- EEPROM_Erase(0x200); //建议在最开始进行erase 初始化,提高效率
-
- for(i=0;i<256;i++)
- {
- EEPROM_Write(4*i,1024-4*i);
- }
-
- //任意位置再写一个
- EEPROM_Write(24,0x55aa);
- EEPROM_Write(68,0xaa55);
- EEPROM_Write(128,0x3fec);
- EEPROM_Write(156,0xccbb);
- EEPROM_Write(256,0xbbcc);
- EEPROM_Write(264,0xccdd);
- EEPROM_Write(300,0x3fff);
- EEPROM_Write(512,0x5f5f);
- EEPROM_Write(900,0x9f9f);
-
- for(i=0;i<256;i++)
- {
- printf("adr:%d =0x%x \n",4*i,EEPROM_Read(4*i));
- }
- //批量写
- printf("/***************************批量测试**************************/ \n");
-
- //跨界的写,1-2个sector的写
- EERPOM_Writeup4byte(340,u8DataBuff,512);
- //byte写,byte读取
- printf("/***************************byte写测试**************************/ \n");
- EEPROM_WriteByte(132,0x13);
- printf("adr :132 =0x%x \n",EEPROM_Read(132));
- EEPROM_WriteByte(132,0x14);
- printf("adr :132 =0x%x \n",EEPROM_Read(132));
- EEPROM_WriteByte(132,0x12);
- printf("adr :132 =0x%x \n",EEPROM_ReadByte(132));
- EEPROM_WriteByte(132,0x15);
- printf("adr :132 =0x%x \n",EEPROM_ReadByte(132));
-
- while(1)
- {
- }
- }
|