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

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-25 12:32
Flash_ptr = (char*)FlashWrite;      是不是这句话把程序拷到了ram里面,拷到ram里面,这个程序是怎么运行的啊

RAM_ptr = (char*)0x0300; 然后跳转到ram0x300地址区执行代码啊
seasky208
2楼-- · 2019-03-25 17:14
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
  }
}
循环拷贝,一直到end,
主函数里的
asm("CALL #300h");                      // Execute FlashWrite from RAM
跳转到0X300
flywith
3楼-- · 2019-03-25 20:16
 精彩回答 2  元偷偷看……

一周热门 更多>

相关问题

    相关文章