不明白这个程序是怎么运行的?

2019-03-24 15:08发布


#include <msp430x16x.h> // Global variables
char value = 0;                             // 8-bit value to write to segment A
char* Flash_ptr;                            // Flash pointer
char* RAM_ptr;                              // RAM pointer
char* END_ptr;                              // End of FlashWrite routine // Function prototypes
void FlashWrite();
void CopyRoutine();
void End_of_FlashWrite(); void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer   _DINT();                                  // Diable Interrupts
  CopyRoutine();                            // Copy FlashWrite routine to RAM
  _EINT();                                  // Enable Interrupts   while(1)                                  // Repeat forever
  {
    Flash_ptr = (char *) 0x1000;            // Initialize Flash pointer
    FCTL2 = FWKEY + FSSEL1 + FN0;           // MCLK/2 for Flash Timing Generator
    FCTL1 = FWKEY + ERASE;                  // Set Erase bit
    FCTL3 = FWKEY;                          // Clear Lock bit     *Flash_ptr = 0;                         // Dummy write to erase Flash segment
    while(!(FCTL3 & WAIT));                 // WAIT until Flash is ready
    asm("CALL #300h");                      // Execute FlashWrite from RAM
                                            // Inline Assembly
    value++;                                // Increment value
    _NOP();                                 // SET BREAKPOINT HERE
  }
} void CopyRoutine()
{
  Flash_ptr = (char*)FlashWrite;            // Set pointer to FlashWrite routine
  RAM_ptr = (char*)0x0300;                  // Set pointer to RAM
  END_ptr = (char*)End_of_FlashWrite;       // Set pointer to End_of_FlashWrite   while(END_ptr != Flash_ptr)               // Check for end of FlashWrite
  {
    *RAM_ptr = *Flash_ptr;                  // Copy word to RAM
    Flash_ptr++;                            // Increment Flash pointer
    RAM_ptr++;                              // Increment RAM pointer
  }
} void FlashWrite()
{
  volatile int i;                           // Use as write counter
  Flash_ptr = (char*)0x1000;                // Initialize Flash pointer
  while(FCTL3 & BUSY);                      // Check Flash BUSY bit
  FCTL1 = FWKEY + BLKWRT + WRT;             // Enable block-write operation
  for(i = 0; i < 64; i++)
  {
    *Flash_ptr = value;                     // Write value to flash
    Flash_ptr++;                            // Double-increment Flash pointer
    while(!(FCTL3 & WAIT));                 // WAIT until Flash is ready
  }
  FCTL1 = FWKEY;                            // Clear BLKWRT & WRT bits
  while(FCTL3 & BUSY);                      // Check Flash BUSY bit
  FCTL3 = FWKEY + LOCK;                     // Reset LOCK bit
  return;                                   // Exits routine
} void End_of_FlashWrite(){}                  // Marks end of FlashWrite
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
9条回答
flywith
1楼-- · 2019-03-24 23:53
void CopyRoutine()
这个函数里面的
Flash_ptr = (char*)FlashWrite;            // Set pointer to FlashWrite routine
  RAM_ptr = (char*)0x0300;                  // Set pointer to RAM
  END_ptr = (char*)End_of_FlashWrite;       // Set pointer to End_of_FlashWrite

这三句话怎么解释啊
flywith
2楼-- · 2019-03-25 02:28
< :TI_MSP430_内容页_SA7 --> 然后程序进去直接执行了CopyRoutine();    将数据//Copy FlashWrite routine to RAM。但是什么时候把ram中的数据拷回到了flash当中去的啊
flywith
3楼-- · 2019-03-25 04:21
 精彩回答 2  元偷偷看……
kingheimer
4楼-- · 2019-03-25 06:11
把Flash_ptr指针指向FlashWrite,就是给指针赋值,指向FlashWrite的空间,应该是做为Flash擦除的地址。下面两个同理。Flash操作看这个文章不错http://bbs.eeworld.com.cn/thread-314284-1-1.html
kingheimer
5楼-- · 2019-03-25 10:43
这是程序跳转,跳到0x300这个地址接着开始执行以后的程序
seasky208
6楼-- · 2019-03-25 10:59
 精彩回答 2  元偷偷看……

一周热门 更多>

相关问题

    相关文章