⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msp430x21x1_flashwrite_03.asm

📁 MSP430X11x1 Assembler Examples Code,Composer Essentials Code Examples
💻 ASM
字号:
;*****************************************************************************
;   MSP430x21x1 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.
;   The EEI bit is set for the Flash Erase Cycles. This does allow the TimerA
;   Interrupts to be handled also during the Segment erase time.
;   ACLK = n/a, MCLK = SMCLK = saved DCO 1Mhz
;   //* Set Breakpoint in the Mainloop to avoid Stressing Flash *//
;
;                MSP430F21x1
;             -----------------
;         /|\|              XIN|-
;          | |                 |
;          --|RST          XOUT|-
;            |                 |
;
;
;
;   S. Schauer / A. Dannenberg
;   Texas Instruments Inc.
;   July 2005
;   Built with Code Composer Essentials Version: 1.0
;*****************************************************************************
 .cdecls C,LIST,  "msp430x21x1.h"

value   .equ     R4
;------------------------------------------------------------------------------
            .text                           ; Program Start
;------------------------------------------------------------------------------
RESET       mov.w   #300h,SP                ; Initialize stackpointer
StopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
            mov.b   &CALBC1_1MHZ,&BCSCTL1   ; Set DCO
            mov.b   &CALDCO_1MHZ,&DCOCTL

            clr.b   value                   ; value = value to write to flash
;
SetupP1     bis.b   #001h,&P1DIR            ; P1.0 output
SetupC0     mov.w   #CCIE,&CCTL0            ; CCR0 interrupt enabled
            mov.w   #50000,&CCR0            ;
SetupTA     mov.w   #TASSEL_2+MC_1,&TACTL   ; SMCLK, upmode
;                                            ;						
            eint                            ; interrupts enabled
;				          							
Mainloop    call    #Write_SegC             ; Copy value to segment C
            call    #CopyC2D                ;
            jmp     Mainloop                ; Use this instruction with care
                                            ; as it could destroy the Flash memory
                                            ; if running for a long time

;------------------------------------------------------------------------------
Write_SegC ;Input = value, holds value to write to Seg C, R5 used as working reg.
;------------------------------------------------------------------------------
            mov.w   #01040h,R5              ;
Timing      mov.w   #FWKEY+FSSEL0+FN1,&FCTL2  ; *Timing generator = MCLK/3
Erase_SegC  mov.w   #FWKEY,&FCTL3           ; Lock = 0
            mov.w   #FWKEY+ERASE+EEI,&FCTL1 ; Erase bit = 1, allow interrupts
            mov.w   #0,&01040h              ; Dummy write to SegC to erase
Prog_SegC   mov.w   #FWKEY+WRT,&FCTL1       ; Write bit = 1, block interrupts
            mov.w   #FWKEY,&FCTL3           ; Lock = 0
Prog_L1     mov.b   value,0(R5)             ;
            inc.b   value                   ;
            inc.w   R5                      ;
            cmp.w   #01080h,R5              ;
            jne     Prog_L1                 ;
            mov.w   #FWKEY+LOCK,&FCTL3      ; Lock = 1;
            ret                             ;
                                            ;
;------------------------------------------------------------------------------
CopyC2D    ;Copy Seg C to Seg D, R5 used as working reg.
;------------------------------------------------------------------------------
            mov.w   #FWKEY+FSSEL0+FN1,&FCTL2  ; *Timing generator = MCLK/3
Erase_SegD  mov.w   #FWKEY,&FCTL3           ; Lock = 0
            mov.w   #FWKEY+ERASE+EEI,&FCTL1 ; Erase bit = 1, allow interrupts
            mov.w   #0,&01000h              ; Dummy write to SegD to erase
            mov.w   #01040h,R5              ; R5 = First byte in Seg C
Prog_SegD   mov.w   #FWKEY+WRT,&FCTL1       ; Write bit = 1, block interrupts
            mov.w   #FWKEY,&FCTL3           ; Lock = 0
Prog_L2     mov.b   @R5+,-65(R5)            ; Copy Seg C to Seg D
            cmp.w   #01080h,R5              ;
            jne     Prog_L2                 ;
            mov.w   #FWKEY+LOCK,&FCTL3      ; Lock = 1
            ret

;------------------------------------------------------------------------------
TA0_ISR;    Toggle P1.0
;------------------------------------------------------------------------------
            xor.b   #001h,&P1OUT            ; Toggle P1.0
            reti                            ;		
                                            ;
;------------------------------------------------------------------------------
;           Interrupt Vectors
;------------------------------------------------------------------------------
            .sect ".reset"                  ; MSP430 RESET Vector
            .short  RESET                   ;
            .sect ".int09"                  ; Timer_A0 Vector
            .short  TA0_ISR                 ;
            .end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -