Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;-------------------------------------------------------------------------------
- ; 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
- ;-------------------------------------------------------------------------------
- ; Main loop here
- ;-------------------------------------------------------------------------------
- ;ports are set as input on start so we don't need to set port 2 for hexes
- init BIS.B #0FFh,&P3DIR ;set port 3 as output
- CLR.B &P3OUT
- CLR R9
- CLR R5
- MOV.B #00Ah, &P1IE ;set port 1 as interrupt + input
- MOV.B #00Ah, &P1IES
- ;R5 - state of the counter
- ;R6 - button state
- ;R7 - loop counter
- ;R8 - flag that two buttons were pressed at the same time on load (so ignore clk later)
- main
- CLR.B &P1IFG
- BIS #GIE+CPUOFF+SCG1+SCG0, SR
- MOV.B #00Ah, &P1IE ;enable interrupts
- mainloop
- MOV.B &P1IN, R6
- BIT.B #08h, R6 ;check if the load button was clicked
- JZ load
- CMP #01h, R8
- MOV.B #0, R8 ;reset the flag
- JZ main ;there was a load but it's not anymore, so go to sleep
- BIT.B #02h, R6 ;just in case test if clock was pressed
- JNZ main ;not zero - not pressed
- jittersetup
- MOV.W #007FFh, R7 ;set the loop counter
- BIS #GIE, SR ;enable interrupts
- jitterloop
- DEC.W R7 ;2 cycles
- MOV.B &P1IN, R6 ;3 cycles
- BIT #08h, R6 ;2 cycles
- JZ load ;2 cycles
- BIT #02h, R6 ;test the clock input - we know "on" is "0" 2 cycles
- JNZ main ;if it was 1, go to sleep 2 cycles
- CMP.W #0, R7 ;if we got to 2 cycles
- JNZ jitterloop ;2 cycles
- decrease
- BIC #GIE, SR ;disable interrupts
- BIT.B #01h, R8 ;check if the load button was clicked in the meanwhile
- JNZ load ;otherwise, clock was clicked
- DEC.B R5 ;decrease, set out and go to sleep
- MOV.B R5, &P3OUT
- JMP main
- load
- MOV.B &P2IN, R5 ;move the values set by the user
- MOV.B R5, &P3OUT
- CLR R8
- OR #0F5h, R6
- CMP #0F5h, R6
- JNZ mainloop
- is_two
- MOV.B #1, R8 ;flag that there was a load
- JMP mainloop ;load is enabled by value, not edge, so check it again
- PORT1_ISR
- MOV.B &P1IN, R6 ;set the button state to the register
- CLR.B &P1IFG ;clear the interrupt flags
- BIC #GIE+CPUOFF+SCG1+SCG0, 0(SP) ;wake up the cpu
- RETI
- ;-------------------------------------------------------------------------------
- ; Stack Pointer definition
- ;-------------------------------------------------------------------------------
- .global __STACK_END
- .sect .stack
- ;-------------------------------------------------------------------------------
- ; Interrupt Vectors
- ;-------------------------------------------------------------------------------
- .sect ".reset" ; MSP430 RESET Vector
- .short RESET
- .sect ".int04"
- .short PORT1_ISR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement