国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品

MSP430 Flash編程程序

發(fā)布時(shí)間:2008-10-22 21:55    發(fā)布者:MSP430
關(guān)鍵詞: Flash , MSP430
//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;
本文地址:http://m.qingdxww.cn/thread-2865-1-1.html     【打印本頁】

本站部分文章為轉(zhuǎn)載或網(wǎng)友發(fā)布,目的在于傳遞和分享信息,并不代表本網(wǎng)贊同其觀點(diǎn)和對其真實(shí)性負(fù)責(zé);文章版權(quán)歸原作者及原出處所有,如涉及作品內(nèi)容、版權(quán)和其它問題,我們將根據(jù)著作權(quán)人的要求,第一時(shí)間更正或刪除。
您需要登錄后才可以發(fā)表評論 登錄 | 立即注冊

廠商推薦

  • Microchip視頻專區(qū)
  • 使用SAM-IoT Wx v2開發(fā)板演示AWS IoT Core應(yīng)用程序
  • 使用Harmony3加速TCP/IP應(yīng)用的開發(fā)培訓(xùn)教程
  • 集成高級模擬外設(shè)的PIC18F-Q71家族介紹培訓(xùn)教程
  • 探索PIC16F13145 MCU系列——快速概覽
  • 貿(mào)澤電子(Mouser)專區(qū)

相關(guān)在線工具

相關(guān)視頻

關(guān)于我們  -  服務(wù)條款  -  使用指南  -  站點(diǎn)地圖  -  友情鏈接  -  聯(lián)系我們
電子工程網(wǎng) © 版權(quán)所有   京ICP備16069177號 | 京公網(wǎng)安備11010502021702
快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 国产欧美另类久久精品91 | 幸福宝app丝瓜下软件大全 | 日韩天堂视频 | 香蕉视频在线免费 | 亚洲精品欧美精品中文字幕 | 久热香蕉在线爽青青 | 青青草国产免费久久久91 | 日日狠狠久久偷偷四色综合免费 | 996久久国产精品线观看导航 | 国产精品v欧美精品v日韩精品 | 四虎影音 | 一级片免费网站 | 色吧五月婷婷 | 国产一区二区三区不卡在线观看 | 青青青久热国产精品视频 | 亚洲免费网 | 亚洲免费观看网站 | 男女激情视频国产免费观看 | 一级一级特黄女人精品毛片 | 色婷婷导航 | 亚洲精品永久免费 | 欧美日韩一区二区综合在线视频 | 日韩一本在线 | 国产原创视频在线 | 亚洲欧美日本国产 | 四虎影院毛片 | 欧美亚洲欧美日韩中文二区 | 美国大片免费看在线观看 | 久久99热精品这里久久精品 | 国产网站91| 亚欧免费视频 | 亚洲一区在线视频观看 | 九九九精品午夜在线观看 | 91精品啪在线观看国产91九色 | 日产乱码卡1卡2卡三卡四在线 | 国产欧美日韩另类 | 成人欧美日韩视频一区 | 香蕉视频亚洲一级 | 激情影院成人区免费观看视频 | 五月亭亭免费高清在线 | 免费5xx |