Reputation: 1
Use the MSP430 seven-segment daughter board (available in the IEEE office) to implement a hexadecimal up-down counter on a single digit of the seven-segment display. The counter should start at 0x0, count up to 0xF, count down to 0x0, and repeat indefinitely. The counter should update every 500ms. Engineering Constraints Your implementation must: • Make use of the timerperipherals. • Utilize a lookup table for the seven-segment values.
I am using the MSP-EXP430FR6989 on an empty assembly only project in TI Code Composer Studio. Here is the code I have.
;-------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;
;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file
;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
ENIO clr PM5CTL0
;-------------------------------------------------------------------------------
; Main loop here
;-------------------------------------------------------------------------------
; Hexadecimal Up-Down Counter for MSP430FR6989 with Seven-Segment Display
; Define registers
COUNTER .equ R4 ; Counter variable
; Define constants
DELAY .equ 50000 ; Delay for debouncing
INCREMENT .equ 1 ; Increment value for counter
; Seven-segment display patterns for hex digits
SEGMENTS .word 0x3F00, 0x0600, 0x5B00, 0x4F00, 0x6600, 0x6D00, 0x7D00, 0x0700, 0x7F00, 0x6F00
.sect ".text"
.bss COUNTER ; Reserve memory for counter variable
.text
nop
start: mov #0xA55A, SR ; Disable watchdog
nop
; Configure GPIO for Seven-Segment Display
mov #0xFF00, &P2DIR ; Set P2.0 to P2.7 as output (assuming the seven-segment display is connected to P1.0 to P1.7)
mov #0x0006, &P1OUT ; Initialize P1.5 to turn off the seven-segment display
; Initialize counter
mov #0, COUNTER ; Clear counter
mainLoop: ; Display counter value on Seven-Segment Display
; Check for button press (assuming button connected to P1.3)
bit.b #0x04, &P1IN ; Check P1.3 (Button)
jz noButtonPress ; If button not pressed, skip increment/decrement
; Debounce delay
mov #DELAY, R5
delayLoop: dec R5
jnz delayLoop
; Check button again after delay for debouncing
bit.b #0x04, &P1IN
jz noButtonPress
; Button pressed, increment or decrement counter
bit.b #0x06, &P1IN ; Check P1.5 (Assuming connected to another button)
jz decrementCounter
inc COUNTER ; Increment counter
jmp updateDisplay
decrementCounter:
dec COUNTER ; Decrement counter
updateDisplay:
; Update Seven-Segment Display based on the counter value
mov COUNTER, R6 ; Load counter value into R6
and #0x0F, R6 ; Mask higher bits to ensure a single digit
; Use R6 as an index to fetch the corresponding seven-segment pattern
mov.w SEGMENTS(R6), R7 ; Fetch the pattern
; Output the pattern to P2.0 to P2.7
mov R7, &P2OUT
noButtonPress:
jmp mainLoop ; Continue looping
nop
.end
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
The code I wrote is inside the "Main loop here" section, and everything else comes with the empty assembly only project. Whenever I run the program, I get the following errors: "../main.asm", ERROR! at line 40: [E0005] Operand missing .bss COUNTER ; Reserve memory for counter variable
"../main.asm", ERROR! at EOF: [E0300] The following symbols are undefined: __STACK_END I will attach a picture of the daughter board schematic and pin connections to the MSP430. Daughter board schematic Pin connections
Upvotes: 0
Views: 143