: code ( "name" -- ) : postpone [ ; : end-code ( -- ) ] postpone ; ; \xas MCU: MSP430FR2355 \xas 1 equ SW_BIT \ P2.0 mask, asm-only 0 variable press-count \ debounced presses since last shift-start : print-press ( -- ) cr press-count @ . ; \ called from the asm ISR \ ===== io-init in assembler ===== code io-init SW_BIT # P2OUT & .b bis \ pull-up direction (OUT before REN) SW_BIT # P2REN & .b bis \ enable pull resistor end-code io-init code shift-isr R08 R08 add \ shift left 1 (= ADD R08,R08) SW_BIT # P2IN & .b bit \ Z=1 if line low (pressed) 0<>? if, #1 R08 bis then, \ if released, OR 1 into low bit $E000 # R08 bis \ saturate top 3 bits $F000 # R08 cmp =? if, #1 x[ press-count ] & add \ press-count++ x[ ' print-press ] # call \ live print then, end-code \ ===== Start / stop in assembler ===== code shift-start #0 R08 mov \ init register-resident state #0 x[ press-count ] & mov \ zero counter x[ ' shift-isr ] # x[ irq-timerc0 ] & mov \ install handler $2D0 # TA2CTL & mov \ SMCLK + /8 + up mode $176F # TA2CCR0 & mov \ 24 MHz / 8 = 3 MHz, / 500 Hz = 2 ms tick (=5999) $10 # TA2CCTL0 & mov \ enable CCIE eint \ set GIE end-code code shift-stop #0 TA2CCTL0 & mov \ disable CCIE #0 TA2CTL & mov \ stop timer end-code