跪求:MSP430如何将一个内存单元中的数据读取至数组中?

2019-03-24 09:41发布

比如我想将内存单元0300-0310中的数据取出,将每一个数据对应赋值给RAM数组,如果用C语言来操作,如何实现?   如果将取出的数据进行相应的操作,将操作后的数据如何赋给0300-0310地址中?   请高手帮忙写一下,谢谢啦 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
6条回答
5xue
2019-03-24 16:03

/*******************************************************************************
函数名称:Flash_Write_Word
功    能:字,写Flash
参    数:addr--写地址
    buf--要写数据的首地址
    len--数据长度
返回值  :无
调用模块:
*******************************************************************************/
void Flash_Write_Word(int *addr, int *buf, int len)
{
    unsigned int cnt;
 
    while(FCTL3 & BUSY);             // 等待空闲
    FCTL3 = FWKEY;                     // 清除 "Lock"
    FCTL1 = FWKEY + ERASE;             // 准备擦除             
    *addr = 0;                         // 擦除,写任意数均可
    FCTL3 = FWKEY + LOCK;              // 置“LOCK”
 
    while(FCTL3 & BUSY);             // 等待Flash空闲
    FCTL3 = FWKEY;                     // 清除“LOCK”标识
    FCTL1 = FWKEY + WRT;               // 准备写                     
    for(cnt=0; cnt<len; cnt++)
    {
        *(addr + cnt) = *(buf + cnt);   // 写数据
    }
    FCTL3 = FWKEY + LOCK;              // Lock           
}

/*******************************************************************************
函数名称:Flash_Read_Word
功    能:字,读Flash
参    数:addr--读地址
    wordbuf--存储读取的数据
    len--数据长度
返回值  :无
调用模块:
*******************************************************************************/
void Flash_Read_Word(int *addr, int *wordbuf, int len)
{
    unsigned int cnt;
   
    while(FCTL3 & BUSY);                 // 等待flash空闲
    for(cnt = 0; cnt < len; cnt++)
    {
        *(wordbuf + cnt) = *(addr + cnt);   // 读数据
    }
    FCTL3 = FWKEY + LOCK;                   // Lock      
}

/*******************************************************************************
函数名称:Flash_Write_Byte
功    能:字节,写Flash
参    数:addr--写地址
    buf--要写数据的首地址
    len--数据长度
返回值  :无
调用模块:
*******************************************************************************/
void Flash_Write_Byte(char *addr, char *buf, int len)
{
    unsigned int cnt;
 
    while(FCTL3 & BUSY);             // 等待空闲
    FCTL3 = FWKEY;                     // 清除 "Lock"
    FCTL1 = FWKEY + ERASE;             // 准备擦除             
    *addr = 0;                         // 擦除,写任意数均可
    FCTL3 = FWKEY + LOCK;              // 置“LOCK”
 
    while(FCTL3 & BUSY);             // 等待Flash空闲
    FCTL3 = FWKEY;                     // 清除“LOCK”标识
    FCTL1 = FWKEY + WRT;               // 准备写                     
    for(cnt=0; cnt<len; cnt++)
    {
        *(addr + cnt) = *(buf + cnt);  // 写数据
    }
    FCTL3 = FWKEY + LOCK;             // Lock           
}

/*******************************************************************************
函数名称:Flash_Read_Byte
功    能:字节,读Flash
参    数:addr--读地址
    wordbuf--存储读取的数据
    len--数据长度
返回值  :无
调用模块:
*******************************************************************************/
void Flash_Read_Byte(char *addr, char *bytebuf, int len)
{
    unsigned int cnt;
   
    while(FCTL3 & BUSY);                 // 等待flash空闲
    for(cnt=0; cnt<len; cnt++)
    {
        *(bytebuf+ cnt) = *(addr + cnt);    // 读数据
    }
    FCTL3 = FWKEY + LOCK;                  // Lock      
}

 

一周热门 更多>

相关问题

    相关文章