Question
Can someone help me with my code? It needs to print the hello world from MSP430 if the user types print in the terminal. It
Can someone help me with my code? It needs to print the hello world from MSP430 if the user types print in the terminal. It will only print if the user types print in that order. Not pprint or priint.I feel like it should work, but it is not,
;------------------------------------------------------------------------------- ; MSP430 Assembler Code Template for use with TI Code Composer Studio ;****************************************************************************** .cdecls C,LIST,"msp430g2553.h" ; Include device header file ;------------------------------------------------------------------------------- .bss TAFLAG,1 ; TA SW FLG
.text ; Assemble into program memory .retain ; Override ELF conditional linking ; and retain current section .retainrefs ; Additionally 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 ;------------------------------------------------------------------------------- ; Setup P1.2 as TXD and P1.1 as RXD; see data sheet port schematic and UG ;------------------------------------------------------------------------------- SetupP1 bis.b #6h,&P1SEL ; P1.2/P1.1 = USART0 TXD/RXD bis.b #6h,&P1SEL2 ; P1.2/P1.1 = USART0 TXD/RXD ;------------------------------------------------------------------------------- ; Setup USI in UART mode, minimal configuration, point to point ;------------------------------------------------------------------------------- SetupUART0 clr.b &UCA0CTL0 ; default values - see UG clr.b &UCA0CTL1 ; default values - see UG bis.b #UCSSEL1 + UCSSEL0,&UCA0CTL1 ; UCLK = SMCLK ~1 MHz clr.b &UCA0STAT ; default values - see UG ;bis.b #UCLISTEN,&UCA0STAT ; loopback - used for debugging only ;------------------------------------------------------------------------------- ; For a baud rate of 9600,the pre-scaler value is ; = (UCAxBR0 + UCAxBR1 256) = 104 in decimal - integer part - see UG ;------------------------------------------------------------------------------- mov.b #073h,&UCA0BR0 ; Baud Rate = ?
mov.b #000h,&UCA0BR1 ; UCBRx = ? ;------------------------------------------------------------------------------- ; Modulation Control Register - fractional part - see UG ;------------------------------------------------------------------------------- mov.b #002h,&UCA0MCTL ; UCBRFx = 0, UCBRSx = 1, UCOS16 = 0
mov.b #0x00, r6; ;------------------------------------------------------------------------------- ; SW reset of the USI state machine ;------------------------------------------------------------------------------- bic.b #UCSWRST,&UCA0CTL1 ; **Initialize USI state machine** bis.b #UCA0RXIE,&IE2 ; Enable USART0 RX interrupt bis.b #GIE,SR ; General Interrupts Enabled ;------------------------------------------------------------------------------- ; After the state machine is reset, the TXD line seems to oscillate a few times ; It is therefore safer to check if the machine is in a state in which it is ; ready to transmit the next byte. I learned it the hard way ;-( ;------------------------------------------------------------------------------- TX2 bit.b #UCA0TXIFG,&IFG2 ; USI TX buffer ready? jz TX2 ; Jump if TX buffer not ready mov.b #0x55,&UCA0TXBUF ; TX charac. eq. to #0x55 in ASCII
; Setup TimerA to generate an interrupt a few times per second mov #TASSEL1+ID1+ID0+TACLR,&TACTL; SMCLK, /8, STOP mode, clear bic #TAIFG, &TACTL mov #0xFFFF,&TACCR0 ; Load count-up-to value mov #CCIE,&TACCTL0 ; compare, enable compare interrupt
clr.b &TAFLAG ; Clear TA SW flag
;------------------------------------------------------------------------------- ; Main loop from here ;------------------------------------------------------------------------------- Mainloop eint ; Enable general interrupts clrz ; Clear Z clr.b &TAFLAG ; Clear TA SW FLAG bis #MC_1,&TACTL ; Start counter in UP MODE ChkTAFlag tst.b &TAFLAG ; Check to see if TA_ISR was jz ChkTAFlag ; executed ;dint ; Disable general interrupts ;bic #MC_1+MC_0,&TACTL ; Stop counter ;call #MyStrCpy ; nop ; jmp Mainloop ;
;----------------------------------------------------------------------- ; Copy source string starting in R14 to output buffer ; No checks for overlap , space in destination , unterminated source ... MyStrCpy: clr R13 ; will count 13 characters of the string mov.w #SourceStr,R14 ; Load address of source
TXT_1 bit.b #UCA0TXIFG, &IFG2 ; jz TXT_1 ; mov.b #0x0A,&UCA0TXBUF ; TX -> RXed character
TXT_2 bit.b #UCA0TXIFG, &IFG2 ; jz TXT_2 ; mov.b #0x0D,&UCA0TXBUF ; TX -> RXed character
TXT_5 bit.b #UCA0TXIFG, &IFG2 ; jz TXT_5 ;
CopyTest:
mov.b @R14+,&UCA0TXBUF ; [2 words , 5 cycles] copy src -> dst ;wait for buffer empty
TXempty: BIT.B #UCA0TXIFG, &IFG2 ; USCI_A0 Transmit Interrupt? jz TXempty inc R13 cmp.b #25,R13 ; [2 words , 4 cycles] test source ;for string thingsy
jne CopyTest ; [1 word , 2 cycles] continue if not \0 ; ret ; Yes: return to caller
TXT_3 bit.b #UCA0TXIFG, &IFG2 ; jz TXT_3 ; mov.b #0x0A,&UCA0TXBUF ; TX -> RXed character
TXT_4 bit.b #UCA0TXIFG, &IFG2 ; jz TXT_4 ; mov.b #0x0D,&UCA0TXBUF ; TX -> RXed character ret;
;------------------------------------------------------------------------------ ; Echo back RXed character, confirm TX buffer is ready first ;------------------------------------------------------------------------------ USART0RX_ISR: nop ; TX1 bit.b #UCA0TXIFG,&IFG2 ; USI TX buffer ready? jz TX1 ; Jump if TX buffer not ready ;------------------------------------------------------------------------------- ; The order of execution of the two instruction sequence above and the one ; below could be switched. ;------------------------------------------------------------------------------- mov.b &UCA0RXBUF,r10 ; Move received byte in r10 ;------------------------------------------------------------------------------- ;---------------------added for functionality----------------------------------- ;looper nop ;
cmp.b #0x01, r6; //if p input already jeq r_jump; cmp.b #0x02, r6;//if pr input already jeq i_jump; cmp.b #0x03, r6;//if pri input already jeq n_jump; cmp.b #0x04, r6;//if prin input already jeq t_jump; ; cmp.b 0x05, r6;//if print input already ; jeq happy;
p_jump nop ; cmp.b #0x50,r10 ;p jne reset ; mov.b #0x01, r6 ; r6 = 01 jmp happy ;
r_jump nop ; cmp.b #0x50, r10 ; jeq happy ; cmp.b #0x52,r10 ;r jne reset ; add.b #0x01, r6 ; r6 = 02 jmp happy ;
i_jump nop ; cmp.b #0x49,r10 ;i jne reset ; add.b #0x01, r6 ; r6 = 03 jmp happy ;
n_jump nop ; cmp.b #0x4E,r10 ;n jne reset ; add.b #0x01, r6 ; r6 = 04 jmp happy ;
t_jump nop ; cmp.b #0x54,r10 ;t jne reset ; mov.b #0x00, r6 ; ; r6 = 05
add.b #0x20, r10 ; add 0x20 to change upper -> lower case mov.b r10,&UCA0TXBUF ; TX -> RXed character
dint ; Disable general interrupts bic #MC_1+MC_0,&TACTL ; Stop counter call #MyStrCpy ;
reti;
reset nop; mov.b #0x00, r6;
;------------------------------------------------------------------------------- ; For demonstration purposes, it is assumed that the remote terminal sends ; numbers which are eual to the upper case letter. By adding the value 0x20 to ; it, the echoed number represents the same, but lower case letter. ;------------------------------------------------------------------------------- ;quinns reset is here
happy add.b #0x20, r10 ; add 0x20 to change upper -> lower case mov.b r10,&UCA0TXBUF ; TX -> RXed character ;mov.b #0x00, r10 ;
reti ;
TA_ISR: nop ; bic.w #CCIFG, &TACCTL0 ; clear interrupt flag mov.b #0x01, &TAFLAG ; Set the TA SW flag reti
; Segment for constant data in ROM SourceStr: ; string constant, stored between 0xC000 and 0xFFFF .string "hello world, from MSP430 " ; "" should cause a '\0' to be appended ;------------------------------------------------------------------------------
;------------------------------------------------------------------------------- ; Stack Pointer definition ;------------------------------------------------------------------------------- .global __STACK_END .sect .stack ;-----------------------------------------------------------------------
;------------------------------------------------------------------------------- ; Interrupt Vectors - see device specific header file ;------------------------------------------------------------------------------- .sect ".reset" ; RESET Vector .short RESET .end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started