[DemoCode下载] 计算掉电時储存512字节数据所需时间和电容值

[复制链接]
1764|21
 楼主| dongnanxibei 发表于 2019-5-12 22:59 | 显示全部楼层
  1. #include "Mini51Series.h"
  2. #define PAGE_SIZE 128
  3. uint32_t i, u32DFBADR, u32Data[PAGE_SIZE];
  4. void SYS_Init(void)
  5. {
  6. /* Unlock protected registers */
  7. SYS_UnlockReg();
  8. P01 = 1; // Set init state to high
  9. GPIO_SetMode(P0, BIT1, GPIO_PMD_OUTPUT); // Set to output mode
  10. /* Enable FMC ISP function */
  11. FMC_Open();
  12. /* Enable BOD function and setting Brown-out voltage level*/
  13. SYS_EnableBOD(SYS_BODCR_BOD_INTERRUPT_EN, SYS_BODCR_BOD_VL_4_4V);
  14. NVIC_EnableIRQ(BOD_IRQn); // Enable BOD interrupt
  15. /* Lock protected registers */
  16. SYS_LockReg();
  17. }
  18. void BOD_IRQHandler(void)
  19. {
  20. P01 = 0; // Set P0.1 state to low.
  21. SYS->BODCTL |= SYS_BODCR_BOD_INTF_Msk; // Clear BOD interrupt flag.
  22. // Disable BOD to avoid into BOD interrupt again.
  23. SYS_DisableBOD();
  24. NVIC_DisableIRQ(BOD_IRQn); // Disable BOD interrupt
  25. // Write test pattern to fill the whole page
  26. for(i = 0; i < PAGE_SIZE; i++)
  27. {
  28. FMC_Write(u32DFBADR + (i*4), u32Data[i]);
  29. }
  30. P01 = 1; // Set P0.1 state to high.
  31. }
 楼主| dongnanxibei 发表于 2019-5-12 22:59 | 显示全部楼层
  1. int main(void)
  2. {
  3. /* Before use this sample code, we need to set data flash for
  4. erasing and writing test pattern */
  5. /* Init System, set GPIO mode and enable BOD function*/
  6. SYS_Init();
  7. /* Fill test pattern */
  8. for(i = 0; i < PAGE_SIZE; i++)
  9. {
  10. u32Data[i] = i;
  11. }
  12. // Unlock protected registers for flash erase and program.
  13. SYS_UnlockReg();
  14. // Read data flash base address.
  15. u32DFBADR = FMC_ReadDataFlashBaseAddr();
  16. /* Erase one page data flash before write test pattern*/
  17. FMC_Erase(u32DFBADR);
  18. while (1);
  19. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 在线客服 返回列表 返回顶部