打印
[51单片机]

c8051f410Flash运用

[复制链接]
1275|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wazibu|  楼主 | 2013-12-3 14:46 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
沙发
ayb_ice| | 2013-12-3 15:02 | 只看该作者
什么叫“用过”

使用特权

评论回复
板凳
wape271| | 2013-12-3 17:24 | 只看该作者
/*
数据存储空间从地址0x0000到0x08ff;
扇区是512字节,擦除操作是整扇区擦除,所以Flash_Erase(0x0000)的擦除范围是0x0000到0x0200;
值得注意的是Flash_Erase(0x01ff)的擦除范围也是0x0000到0x0200;

*/
#include "c8051f410.h"
void Flash_Write(unsigned char source,unsigned int address);
unsigned char Flash_Read(unsigned int addr);
void Flash_Erase(unsigned int address);

int i,j;
unsigned char result;
main()
{
OSCICN = 0x87;
PCA0MD &= ~0x40;  
XBR0= 0x01;                  
    XBR1= 0x40;   

//Flash_Erase(0x410);
//Flash_Write(11,0x410);
result=Flash_Read(0x410);
i=0;
}

void Flash_Write(unsigned char source,unsigned int address)
{
    unsigned char EA_save;   // saves the current interrupt state
    unsigned char xdata * data pwrite;

    EA_save = EA;
    EA = 0;                  // disable interrupts

    pwrite = (unsigned char xdata *) address;

    FLKEY = 0xA5;            // FLASH lock and key sequence 1
    FLKEY = 0xF1;            // FLASH lock and key sequence 2
    PSCTL = 0x01;            // Sets PSWE bit, Clears PSEE bit

    *pwrite = source;      // Move the data to C8051F326 flash

    PSCTL &= ~0x01;          // Clear PSWE so MOVX target XRAM

    EA = EA_save;            // re-enable interrupts
}

void Flash_Erase(unsigned int address)
{
   unsigned char EA_save;   // saves the current interrupt state
    unsigned char xdata * data pwrite;

    EA_save = EA;
    EA = 0;                  // disable interrupts

    pwrite = (unsigned char xdata *) address;

    FLKEY = 0xA5;            // FLASH lock and key sequence 1
    FLKEY = 0xF1;            // FLASH lock and key sequence 2
    PSCTL = 0x03;           // Sets PSWE bit, Sets PSEE bit

    *pwrite = 0xff;        //擦除整个扇区

    PSCTL &= ~0x03;          // Clear PSWE and PSEE so MOVX target XRAM

    EA = EA_save;            // re-enable interrupts

}

unsigned char Flash_Read(unsigned int addr)
{
    unsigned char EA_save,Tmp_data;   // saves the current interrupt state
    unsigned char code * data pread;

    EA_save = EA;
    EA = 0;                  // disable interrupts

pread = (unsigned char code *) addr;

    Tmp_data = *pread;        //读指定flash地址数据

    EA = EA_save;            // re-enable interrupts

return Tmp_data;
}


使用特权

评论回复
地板
airwill| | 2013-12-3 17:47 | 只看该作者
从 GOOGLE 搜一下, 就能找到一些了, 也到官网去找找.

使用特权

评论回复
5
ayb_ice| | 2013-12-4 08:17 | 只看该作者
官方例程一大把

未命名.PNG (18.76 KB )

未命名.PNG

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝