打印

MSP430 Flash编程程序(转)

[复制链接]
852|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
foreverly|  楼主 | 2010-12-10 15:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
//flash.c文件
#define  __FLASH__
#define  __HW_v_2_1__
#include "flash.h"
/*************************************************************************************************
*     This section contains all FLASH memory relevant functions:                                 *
*       writeByte                                                                                *
*       writeWord                                                                                *
*       eraseFLASH                                                                               *
*       saveInfoFlash                                                                            *
*       changeInfo                                                                               *
*       updateInfo                                                                               *
*                                                                                                *
*************************************************************************************************/
/*************************************************************************************************
Function :        flash_writeFLASH
Parameter :       *dst  :  address within the FLASH page
                  value :  BYTE that has to be written to FLASH
Date :            08.09.2001 / 17.11.2002 / 22.11.2002
Description :     this function writes a byte to an address in FLASH memory
                  warning: in FLASH only zeros can be written. if a bit value needs to be set to
                  one from zero, the whole page has to be erased, thus setting all bits to one.
                  then the value can be written correctly. this function does not perform the
                  necessary FLASH page erase.
*************************************************************************************************/
void flash_writeByte(BYTE *dst, BYTE value)
{
  FCTL2 = FWKEY | FSSEL0 | 20;        //clock source is MCLK, divisor is 20
  do
  {
    _NOP();
  } while(FCTL3 & 0x0001);            // wait for BUSY to reset
  FCTL3 = FWKEY;                      // reset the LOCK bit to enable program/erase
  FCTL1 = FWKEY | WRT;                // set WRT for single acces


*dst = value;                       // do the write as a byte

return;
}

**
Function :        flash_eraseFLASH
Parameter :       *seg  :  any address within the FLASH page that is to be erased
Date :            08.09.2001 / 19.11.2002
Description :     this function erases a FLASH page
*************************************************************************************************/
void flash_eraseFLASH(BYTE *seg)
{
  FCTL2 = FWKEY | FSSEL0 | 20;        //clock source is MCLK, divisor is 20
  do
  {
    _NOP();
  } while(FCTL3 & 0x0001);            // wait for BUSY to reset
  FCTL3 = FWKEY;                      // reset the LOCK bit to enable program/erase
  FCTL1 = FWKEY | ERASE;              // set single segment erase function


*seg = 0xFF;                        // do a dummy write to start erase

FCTL3 = FWKEY | LOCK;               // lock the flash again

return;
}


/*************************************************************************************************
Function :        flash_saveInfoFlash
Parameter :       *container : pointer to updated copy of data in RAM
                  *flashPageBase : pointer to start of destination flash segment
Date :            11.09.2002 / 26.11.2002
Description :     saves info flash page 0 to RAM (!!! works only for INFO flash access !!!)
*************************************************************************************************/
void flash_saveInfoFlash(BYTE *container, BYTE *flashPageBase)
{
  BYTE i;


flashPageBase = (BYTE*)((WORD)(flashPageBase) & 0xFF80);   // wrap around for flash page base address

for(i=0;i<128;i++)
  {
    container = *flashPage++;
  }
}





相关帖子

沙发
maoyanketi| | 2010-12-11 11:55 | 只看该作者
这个ti上都能下到的,不过还是谢谢啦

使用特权

评论回复
板凳
-自己人| | 2010-12-11 16:13 | 只看该作者
好资料,受益匪浅!

使用特权

评论回复
地板
ty新气象| | 2010-12-12 21:09 | 只看该作者
这还有呢?再来。

使用特权

评论回复
5
爱在2012| | 2010-12-12 21:17 | 只看该作者
very good,thanks

使用特权

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

本版积分规则

0

主题

486

帖子

1

粉丝