Tool/software: TI C/C++ Compiler
Dear All,
I need a comparator example code written in assembly. MCU is msp430fr2111.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
Dear All,
I need a comparator example code written in assembly. MCU is msp430fr2111.
Hi Clemens,
I wrote it with reference to this example code by assembly,but it can't be used.Can you help me to correct it?
SetREF mov.b #PMMPW_H,&PMMCTL0_H ; Unlock the PMM registers
bis.w #INTREFEN,&PMMCTL2 ; Enable internal reference
PollREF bit.w #REFGENRDY,&PMMCTL2 ; Poll till internal reference settles
jz PollREF
mov.w #CPPSEL0+CPNSEL1+CPNSEL2+CPPEN+CPNEN, &CPCTL0
; Select C1 as input for V+ terminal
; Select DAC as input for V- terminal
; Enable eCOMP input
bis.w #CPIIE + CPIE, &CPCTL1
bis.w #CPDACREFS + CPDACEN, &CPDACCTL
bis.w #0x2b, &CPDACDATA
bis.w #CPEN, &CPCTL1
sleep
clr.w &CPINT
nop
bis.w #LPM3 + GIE, SR
nop
jmp sleep
ecomp_interrupt_service_function ;Comparative interrupt function
;============================================
add.w &CPIV, PC
reti
jmp wf1_interrupt_pending
jmp wf2_interrupt_pending
wf1_interrupt_pending
bis.b #BIT2, &P1DIR
bic.b #BIT0, &P2DIR ; Comparator output off
bic.b #BIT2, &P1DIR
bis.w #CPIE, &CPCTL1 ; Close comparative interrupt
bic.w #LPM3 + GIE, 0(SP) ; Modify stack areas (wake up)
reti
wf2_interrupt_pending
bis.b #BIT2, &P1DIR
bic.b #BIT0, &P2DIR ; Comparator output off
bic.b #BIT2, &P1DIR
bis.w #CPIE, &CPCTL1 ; Close comparative interrupt
bic.w #LPM3 + GIE, 0(SP) ; Modify stack areas (wake up)
reti
;-------------------------------------------------------------------------------
COMMON INTVEC ; Interrupt Vectors
;-------------------------------------------------------------------------------
ORG RESET_VECTOR ; POR, ext. Reset
DW RESET
ORG PORT1_VECTOR ; external interruption
DW port1_interrupt_service_function
ORG ECOMP0_VECTOR ; Comparator interrupt
DW ecomp_interrupt_service_function
What exactly do you mean with "it can't be used"?
(I do not have this MCU.)
(Please use the "Insert Code" function to insert code so that it is formatted properly.)
Hello Clemens,
I mean this program doesn't do what I want.Could you please help me check if there are any mistakes
SetREF mov.b #PMMPW_H,&PMMCTL0_H ; Unlock the PMM registers bis.w #INTREFEN,&PMMCTL2 ; Enable internal reference PollREF bit.w #REFGENRDY,&PMMCTL2 ; Poll till internal reference settles jz PollREF mov.w #CPPSEL0+CPNSEL1+CPNSEL2+CPPEN+CPNEN, &CPCTL0 ; Select C1 as input for V+ terminal ; Select DAC as input for V- terminal ; Enable eCOMP input bis.w #CPIIE + CPIE, &CPCTL1 bis.w #CPDACREFS + CPDACEN, &CPDACCTL bis.w #0x2b, &CPDACDATA bis.w #CPEN, &CPCTL1 sleep clr.w &CPINT nop bis.w #LPM3 + GIE, SR nop jmp sleep ecomp_interrupt_service_function ;Comparative interrupt function ;============================================ add.w &CPIV, PC reti jmp wf1_interrupt_pending jmp wf2_interrupt_pending wf1_interrupt_pending bis.b #BIT2, &P1DIR bic.b #BIT0, &P2DIR ; Comparator output off bic.b #BIT2, &P1DIR bis.w #CPIE, &CPCTL1 ; Close comparative interrupt bic.w #LPM3 + GIE, 0(SP) ; Modify stack areas (wake up) reti wf2_interrupt_pending bis.b #BIT2, &P1DIR bic.b #BIT0, &P2DIR ; Comparator output off bic.b #BIT2, &P1DIR bis.w #CPIE, &CPCTL1 ; Close comparative interrupt bic.w #LPM3 + GIE, 0(SP) ; Modify stack areas (wake up) reti ;------------------------------------------------------------------------------- COMMON INTVEC ; Interrupt Vectors ;------------------------------------------------------------------------------- ORG RESET_VECTOR ; POR, ext. Reset DW RESET ORG PORT1_VECTOR ; external interruption DW port1_interrupt_service_function ORG ECOMP0_VECTOR ; Comparator interrupt DW ecomp_interrupt_service_function
**Attention** This is a public forum