完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
想实现这么一个功能:经过按键调整后的数值储存起来,断电后重启要能记忆住。根据数据手册的要求做了几次试验都没能成功,看哪位高手指点一下。先谢谢各位了。芯片是C8051F310.
|
|
相关推荐
1个回答
|
|
//-----------------------------------------------------------------------------
// Includes //----------------------------------------------------------------------------- #include "c8051F410.h" #include "F410_FlashPrimitives.h" #include //#include "F410_FlashPrimitives.h" #include //----------------------------------------------------------------------------- // Function Prototypes //----------------------------------------------------------------------------- void FLASH_ByteWrite (FLADDR addr, char byte); unsigned char FLASH_ByteRead (FLADDR addr); void FLASH_PageErase (FLADDR addr); //----------------------------------------------------------------------------- // FLASH_ByteWrite //----------------------------------------------------------------------------- // // Return Value : None // Parameters : // 1) FLADDR addr - address of the byte to write to // valid range is from 0x0000 to 0x7DFE for 32K devices // valid range is from 0x0000 to 0x3FFE for 16K devices // 2) char byte - byte to write to Flash. // // This routine writes //----------------------------------------------------------------------------- void FLASH_ByteWrite (FLADDR addr, char byte) { bit EA_SAVE = EA; // Preserve EA char xdata * data pwrite; // FLASH write pointer EA = 0; // Disable interrupts VDM0CN = 0xA0; // Enable VDD monitor and high threshold RSTSRC = 0x02; // Enable VDD monitor as a reset source pwrite = (char xdata *) addr; FLKEY = 0xA5; // Key Sequence 1 FLKEY = 0xF1; // Key Sequence 2 PSCTL |= 0x01; // PSWE = 1 which enables writes VDM0CN = 0xA0; // Enable VDD monitor and high threshold RSTSRC = 0x02; // Enable VDD monitor as a reset source // XBYTE[addr]=byte; *pwrite = byte; // Write the byte PSCTL &= ~0x01; // PSWE = 0 which disable writes EA = EA_SAVE; // Restore interrupts } //----------------------------------------------------------------------------- // FLASH_ByteRead //----------------------------------------------------------------------------- // // Return Value : // unsigned char - byte read from Flash // Parameters : // 1) FLADDR addr - address of the byte to read to // valid range is from 0x0000 to 0x7DFE for 32K devices // valid range is from 0x0000 to 0x3FFE for 16K devices // // This routine reads a //----------------------------------------------------------------------------- unsigned char FLASH_ByteRead (unsigned int addr) { bit EA_SAVE = EA; // Preserve EA UCHAR code * data pread; // FLASH read pointer unsigned char byte; EA = 0; // Disable interrupts pread = (char code *) addr; byte = *pread; // Read the byte EA = EA_SAVE; // Restore interrupts return byte; } //----------------------------------------------------------------------------- // FLASH_PageErase //----------------------------------------------------------------------------- // // Return Value : None // Parameters : // 1) FLADDR addr - address of any byte in the page to erase // valid range is from 0x0000 to 0x7BFF for 32K devices // valid range is from 0x0000 to 0x3DFF for 16K devices // // This routine erases the FLASH page containing the linear FLASH address // // erased if the Lock Byte is set. // //----------------------------------------------------------------------------- void FLASH_PageErase (FLADDR addr) { bit EA_SAVE = EA; // Preserve EA char xdata * data pwrite; // FLASH write pointer EA = 0; // PCA0MD &= ~(1<<6); // Disable interrupts VDM0CN = 0xA0; // Enable VDD monitor and high threshold RSTSRC = 0x02; // Enable VDD monitor as a reset source pwrite = (char xdata *) addr; FLKEY = 0xA5; // Key Sequence 1 FLKEY = 0xF1; // Key Sequence 2 PSCTL = 0x03; // PSWE = 1; PSEE = 1 VDM0CN = 0xA0; // Enable VDD monitor and high threshold RSTSRC = 0x02; // Enable VDD monitor as a reset source *pwrite = 0; // Initiate page erase PSCTL &= ~0x03; // PSWE = 0; PSEE = 0 EA = EA_SAVE; // Restore interrupts } //----------------------------------------------------------------------------- // End Of File //----------------------------------------------------------------------------- |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
【RA-Eco-RA2E1-48PIN-V1.0开发板试用】简介、环境搭建、工程测试
177 浏览 0 评论
312 浏览 0 评论
imx6ull裸机编程,使用宏定义无法驱动,使用指针就可以驱动
691 浏览 1 评论
《DNK210使用指南 -CanMV版 V1.0》第三十二章 音频FFT实验
384 浏览 0 评论
飞凌嵌入式ElfBoard EL 1板卡-i2c与从设备通讯编程示例之i2c-tools工具使用
1284 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11620 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-6 03:20 , Processed in 0.910010 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号