历史上的今天
今天是:2025年01月21日(星期二)
2021年01月21日 | MSP430 Flash编程程序
2021-01-21 来源:eefocus
//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_writeWord
Parameter : *dst : address within the FLASH page
value : BYTE that has to be written to FLASH
Date : 22.11.2002
Description : this function writes a word 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_writeWord(WORD *dst, WORD 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 word
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++;
}
}
/*************************************************************************************************
Function : flash_changeInfo
Parameter : *container : pointer to updated copy of data in RAM
*pointer : original pointer to variable that has to be updated
value : new value for variable
Date : 11.09.2002 / 26.11.2002
Description : chages a word in the info flash 0 data (in RAM)
*************************************************************************************************/
void flash_changeInfo(BYTE* containerBase, BYTE *pointer, BYTE value)
{
// pointer points into flash page to variable that is supposed to be changed
// subtract flash page offset (0x1000) and add scratch pad offset
pointer = (BYTE*)(((WORD)(pointer) & 0x7F) + (WORD)(containerBase));
*pointer = value;
}
/*************************************************************************************************
Function : flash_update
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 : erases the flash page and writes the values from the RAM save area to flash
(!!! works only in INFO flash !!!)
*************************************************************************************************/
void flash_updateInfo(BYTE *container, BYTE *flashPageBase)
{
// assumes prior saving and changing of flash data
BYTE i;
flashPageBase = (BYTE*)((WORD)(flashPageBase) & 0xFF80); // wrap around for flash page base address
_DINT();
flash_eraseFLASH(flashPageBase);
for(i=0;i<128;i++)
{
flash_writeByte(flashPageBase++,*(container++));
}
_EINT();
}
/*flash.h文件
+-------------------------------------------------------------------------------+
: copyright (c) Jean Randhahn :
+-------------------------------------------------------------------------------+
: Project : CANeye - Uni Rostock :
: Compiler : IAR workbench GUI 2.31E / target descriptor v1.26A/WIN :
+-------------------------------------------------------------------------------+
: :
: class : flash :
: File name : flash.h :
: Target hardware : MSP430F148/9 :
: :
: File Editor : J. Randhahn :
: Created : 06.08.2002 :
: :
: Description : :
: :
: :
: :
: :
+-------------------------------------------------------------------------------+
: :
: Modification history: :
: :
: :
+-------------------------------------------------------------------------------+
*/
#ifndef __FLASH_H__
#define __FLASH_H__
#ifdef __FLASH__
/*::::::::::::::::::::::::: START OF LOCAL PART ::::::::::::::::::::::::::::::::*/
/*----------------------- LOCAL INCLUDES ---------------------------------------*/
#include
#include "type.h"
/*----------------------- LOCAL DEFINITIONS ------------------------------------*/
/*----------------------- LOCAL FUNCTION DECLARATIONS --------------------------*/
void flash_eraseFLASH(BYTE *seg);
void flash_writeWord(WORD *dst, WORD value);
void flash_writeByte(BYTE *dst, BYTE value);
void flash_saveInfoFlash(BYTE *container, BYTE *flashPage);
void flash_changeInfo(BYTE* containerBase, BYTE *pointer, BYTE value);
void flash_updateInfo(BYTE *container, BYTE *flashPageBase);
/*----------------------- LOCAL CONSTANTS AND VARIABLES ------------------------*/
/*----------------------- PUBLIC VARIABLES WITH INITIALISATION -----------------*/
/*::::::::::::::::::::::::: END OF LOCAL PART ::::::::::::::::::::::::::::::::::*/
#else
/*----------------------- PUBLIC VARIBALES INITIALIZED LOCALLY -----------------*/
#endif
/*-------------------- PUBLIC DEFINITIONS --------------------------------------*/
/*-------------------- PUBLIC CONSTANTS AND VARIABLES --------------------------*/
/*-------------------- PUBLIC FUNCTION DECLARATIONS ----------------------------*/
extern void flash_eraseFLASH(BYTE *seg);
extern void flash_writeWord(WORD *dst, WORD value);
extern void flash_writeByte(BYTE *dst, BYTE value);
extern void flash_saveInfoFlash(BYTE *container, BYTE *flashPage);
extern void flash_changeInfo(BYTE* containerBase, BYTE *pointer, BYTE value);
extern void flash_updateInfo(BYTE *container, BYTE *flashPageBase);
#endif
//type.h文件
/* START type definitions for convinience with microcontrollers ****************************/
typedef unsigned char BYTE; /* 8 bits */
typedef unsigned short WORD; /* 16 bits */
typedef unsigned long LONGWORD; /* 32 bits */
/* for dividing a WORD into two BYTEs */
typedef union _WORD_BYTE
{ WORD w;
BYTE b[2];
} WORD_BYTE;
史海拾趣
|
步进电机是 1 种将数字脉冲信号转换成机械角位移或线位移的数模转换元件.研究了 1 种基于 PWM 的连续多倍细分控制的步进电机驱动方法 ,该方法可有效地提高位置控制精度.… 查看全部问答> |
|
路由器问题: 1、什么时候使用多路由协议? 当两种不同的路由协议要交换路由信息时,就要用到多路由协议。当然,路由再分配也可以交换路由信息。下列情况不必使用多路由协议: 从老版本的内部网关协议( Interio ...… 查看全部问答> |
|
在瑞士,人们对一种不需要外来热源就可以加热煮熟食物的锅颇感兴趣。它的热量全靠外壳和内层之间储存的硅和二氧化锰进行化学反应来产生。可以不用借火或是电就能煮熟食物了,多方便啊,出去野餐的时候它的方便就更不用说了!… 查看全部问答> |
|
世界上一些伟在的发明创造是怎么来的,有人给总结了一下大至有以下几点 1、偶然发现法 一些发明或许就是偶然的发现,如果不去思考,偶然的发现就会滑过去,什么结果也没有,现实生活中的所有现象都有它的道理,偶然出现的事物也有它的道理 ...… 查看全部问答> |
|
上位机windows微型热敏打印机驱动,遇到打印条码问题,打印文档,图形正常,打印条码的时候,如果条码在文档前部,可以,出现在文档中部,就异常了。有说是底部图形引擎的问题的,有感兴趣的兄弟帮忙分析下最好。要是您在北京,天津地区,我登门求 ...… 查看全部问答> |
|
SetMode(TRUE) SetProcPermissions(0xFFFFFFFF); CINFO **SystemAPISets= (CINFO **)KData.aInfo[KINX_APISETS]; HANDLE H=LoadKernelLibrary(L\"test.dll\"); 为什么H总是 0 ? 谢谢… 查看全部问答> |
|
怎样把这样的结果显示出来。简化,就256放进了A,B,(高)B=00000001,(低)A=00000001。把256这三个数显示出来… 查看全部问答> |




