打印

懂MSP430的帮下忙 谢谢

[复制链接]
1771|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jzhjt29|  楼主 | 2011-11-25 14:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 21小跑堂 于 2011-11-25 15:49 编辑

本人刚学MSP430碰到几个问题:(C语言编程)1,看门狗停止时用WDTCTL=WDTPW+WDTHOLD 可看门狗控制寄存器里根本没有WDTPW和WDTHOLD啊(虽然有hold);那为什么可以有这个关键字呢?2,假如我要把345这个数据写到Flash的0xc000H单元和RAM的0x0300H,请问他们分别怎么写??(请用C)

相关帖子

沙发
cat3902982| | 2011-11-25 14:57 | 只看该作者
第一个问题 你可以到你的头文件里去看 ,最好是结合你的头文件和你的USERGUIDE 一起看。

使用特权

评论回复
板凳
cat3902982| | 2011-11-25 14:58 | 只看该作者
第二个问题 你可以去官网搜索下你对应的型号的MCU的官方例程

使用特权

评论回复
地板
tianm| | 2011-11-26 09:02 | 只看该作者
楼上说的很对 TI的网站上有很多资料可供学习 特别是器件手册一定要看明白

使用特权

评论回复
5
TI_MCU| | 2011-11-28 09:32 | 只看该作者
写到RAM里很简单,定义一个指针直接读写就好了:

int *a = (int *)0x0300H;
*a = 345;
写到Flash是个相对复杂的问题,要允许Flash的写入考虑到Flash的写入时间,同时还要考虑到Flash是否已经擦除等等,下面的代码来自TI写Flash的示例,楼主可以参考一下

/***********************************************************************/
/* flash_idle.c 2000-06-20 */
/* */
/* Flash erase and program functions */
/* */
/* Below functions using the direct Flash programming algorithm. */
/* After starting a flash write or erase cycle, the CPU will wait */
/* until the flash is read-accessable again, so no program must be */
/* copied into RAM. However, during flash programming, the CPU is */
/* in ”idle” mode. */
/* */
/* Note: Since all interrupt vectors are unavailable during flash */
/* programming, all interrupts must be disabled. */
/* */
/* Anton Muehlhofer Texas Instruments Incorporated */
/***********************************************************************/
#define _CPU_ 5 /* 5=MSP430F1121, 6=MSP430F149 device */
#include <std_def.h> /* ports */
#include ”flash_prog.h” /* function prototypes */
/***********************************************************************/
/* Flash_wb */
/* programs 1 byte (8 bit) into the flash memory */
/***********************************************************************/
void Flash_wb( char *Data_ptr, char byte )
{
FCTL3 = 0x0A500; /* Lock = 0 */
FCTL1 = 0x0A540; /* WRT = 1 */
*Data_ptr=byte; /* program Flash word */
FCTL1 = 0x0A500; /* WRT = 0 */
FCTL3 = 0x0A510; /* Lock = 1 */
}
/***********************************************************************/
/* Flash_ww */
/* programs 1 word (16 bits) into the flash memory */
/***********************************************************************/
void Flash_ww( int *Data_ptr, int word )
{
FCTL3 = 0x0A500; /* Lock = 0 */
FCTL1 = 0x0A540; /* WRT = 1 */
*Data_ptr=word; /* program Flash word */
FCTL1 = 0x0A500; /* WRT = 0 */
FCTL3 = 0x0A510; /* Lock = 1 */
}
/***********************************************************************/
/* Flash_clr */
/* erases 1 Segment of flash memory */
/***********************************************************************/
void Flash_clr( int *Data_ptr )
{
FCTL3 = 0x0A500; /* Lock = 0 */
FCTL1 = 0x0A502; /* ERASE = 1 */
*Data_ptr=0; /* erase Flash segment */
FCTL1 = 0x0A500; /* ERASE = 0 */
FCTL3 = 0x0A510; /* Lock = 1 */
}

使用特权

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

本版积分规则

16

主题

140

帖子

0

粉丝