Launchpad msp430 Flash探索
发布时间:2020-12-15 06:21:20 所属栏目:百科 来源:网络整理
导读://****************************************************************************** // ?MSP430G2xx1 Demo - Flash In-System Programming,Copy SegC to SegD // // ?Description: This program first erases flash seg C,then it increments all // ?valu
//******************************************************************************
// ?MSP430G2xx1 Demo - Flash In-System Programming,Copy SegC to SegD // // ?Description: This program first erases flash seg C,then it increments all // ?values in seg C,then it erases seg D,then copies seg C to seg D. // ?Assumed MCLK 771kHz - 1428kHz. // ?//* Set Breakpoint on NOP in the Mainloop to avoid Stressing Flash *// // // ? ? ? ? ? ? ? MSP430G2xx1 // ? ? ? ? ? ?----------------- // ? ? ? ?/|| ? ? ? ? ? ? ?XIN|- // ? ? ? ? | | ? ? ? ? ? ? ? ? | // ? ? ? ? --|RST ? ? ? ? ?XOUT|- // ? ? ? ? ? | ? ? ? ? ? ? ? ? | // // ?D. Dang // ?Texas Instruments Inc. // ?October 2010 // ?Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10 //****************************************************************************** #include <msp430g2231.h> char ?value; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// 8-bit value to write to segment A // Function prototypes void write_SegC (char value); void copy_C2D (void); void main(void) { ? WDTCTL = WDTPW + WDTHOLD; ? ? ? ? ? ? ? ? // 关闭看门狗 // ?if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? // ?{ ? // ? ?while(1); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // If calibration constants erased ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // do not load,trap CPU!! // ?}? ? BCSCTL1 = CALBC1_1MHZ; ? ? ? ? ? ? ? ? ? ?// Set DCO to 1MHz ? DCOCTL = CALDCO_1MHZ; ? FCTL2 = FWKEY + FSSEL0 + FN1; ? ? ? ? ? ? // MCLK/3 for Flash Timing Generator ? value = 1; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// initialize value ? while(1) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Repeat forever ? { ? ? write_SegC(value++); ? ? ? ? ? ? ? ? ? ?// Write segment C,increment value ? ? copy_C2D(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Copy segment C to D ? ? _NOP(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // SET BREAKPOINT HERE ? } } void write_SegC (char value) { ? char *Flash_ptr; ? ? ? ? ? ? ? ? ? ? ? ? ?// Flash pointer ? unsigned int i; ? Flash_ptr = (char *) 0x1040; ? ? ? ? ? ? ?// Initialize Flash pointer ? FCTL1 = FWKEY + ERASE; ? ? ? ? ? ? ? ? ? ?// Set Erase bit ? FCTL3 = FWKEY; ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Clear Lock bit ? *Flash_ptr = 0; ? ? ? ? ? ? ? ? ? ? ? ? ? // Dummy write to erase Flash segment ? FCTL1 = FWKEY + WRT; ? ? ? ? ? ? ? ? ? ? ?// Set WRT bit for write operation ? for (i=0; i<64; i++) ? { ? ? *Flash_ptr++ = value; ? ? ? ? ? ? ? ? ? // Write value to flash ? } ? FCTL1 = FWKEY; ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Clear WRT bit ? FCTL3 = FWKEY + LOCK; ? ? ? ? ? ? ? ? ? ? // Set LOCK bit } void copy_C2D (void) { ? char *Flash_ptrC; ? ? ? ? ? ? ? ? ? ? ? ? // Segment C pointer ? char *Flash_ptrD; ? ? ? ? ? ? ? ? ? ? ? ? // Segment D pointer ? unsigned int i; ? Flash_ptrC = (char *) 0x1040; ? ? ? ? ? ? // Initialize Flash segment C pointer ? Flash_ptrD = (char *) 0x1000; ? ? ? ? ? ? // Initialize Flash segment D pointer ? FCTL1 = FWKEY + ERASE; ? ? ? ? ? ? ? ? ? ?// Set Erase bit ? FCTL3 = FWKEY; ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Clear Lock bit ? *Flash_ptrD = 0; ? ? ? ? ? ? ? ? ? ? ? ? ?// Dummy write to erase Flash segment D ? FCTL1 = FWKEY + WRT; ? ? ? ? ? ? ? ? ? ? ?// Set WRT bit for write operation ? for (i=0; i<64; i++) ? { ? ? *Flash_ptrD++ = *Flash_ptrC++; ? ? ? ? ?// copy value segment C to segment D ? } ? FCTL1 = FWKEY; ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Clear WRT bit ? FCTL3 = FWKEY + LOCK; ? ? ? ? ? ? ? ? ? ? // Set LOCK bit } 本次实验用的是我从官网上下载下来的例程,一直感觉Flash是个很虚无缥缈的东西,这次终于下定决心好好研究一下,但是调试完这个程序才发现自己还是没有真正的明白,不知道哪里的数据可以擦除,找这方面的资料也不是很多,不过还是鼓励自己继续下去 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |