单片机 MSP430G2553 FLASH 操作

痴心易碎 提交于 2020-02-28 04:50:17
//FLASH操作 写入
void write_SegC(char value[], char lenChar)
{
    char *Flash_ptr;                          // Flash pointer
    char i;

    Flash_ptr = (char *) 0x1040;              // Initialize Flash pointer
    FCTL1 = FWKEY + ERASE;                    // Set Erase bit
    FCTL3 = FWKEY;                            // Clear Lock bit
    *Flash_ptr = 0;                           // Dummy write to erase Flash segment

    FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation

    for (i = 0; i < lenChar; i++)
    {
        *Flash_ptr++ = value[i];                   // Write value to flash
    }

    FCTL1 = FWKEY;                            // Clear WRT bit
    FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}
//FLASH操作 读取
void read_SegC(char value[], char lenChar)
{
    char *Flash_ptrC;                         // Segment C pointer
    char i;

    Flash_ptrC = (char *) 0x1040;             // Initialize Flash segment C pointer
    FCTL1 = FWKEY + ERASE;                    // Set Erase bit
    FCTL3 = FWKEY;                            // Clear Lock bit

    FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation

    for (i = 0; i < lenChar; i++)
    {
        value[i] = *Flash_ptrC++;          // copy value
    }

    FCTL1 = FWKEY;                            // Clear WRT bit
    FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!