ldaa #$2 ;Set the prescaler (divide by 16) staa TMSK2
ldaa #$80 ;Enable PA7 as output staa PACTL
ldaa #$10 ;Start first ADC conversion - multi mode enable staa ADCTL
ldd #$0100 ;Load the capture register std TOC1
cli ;Enable interupts
loop: wai bra loop
;OC1 interrupt service oc1f: ldaa #$10 ;Start another ADC conversion staa ADCTL
ldaa ADR1 ;Read the pot position from ADC channel 1 staa PORTB ;Display it
suba #127 ;0x7F is zero reference.
bne oc1f_ne ;Jump if values not same
;Set Both outputs low. Motor is stationary clrb stab PORTA ;Both OC1 and OC2 outputs low stab TCTL1 ;TOC2 mode is disabled bra done
;Non-zero drive - decide if +ve or -ve:
oc1f_ne bcs oc1f_cs
ositive result - motor spins clockwise:
ldab #$40 ort A drives this value: stab  ORTA clrb ;Release TOC2 latch - Port A acquires value, above. stab TCTL1 ldab #$40 ;TOC 2 output toggles on OC2 event; motor drive stops. stab TCTL1 bra done
;Negative result - motor spins anti-clockwise:
oc1f_cs ldab #$80 ort A drives this value: stab  ORTA clrb ;Release TOC2 latch - Port A acquires value, above. stab TCTL1 ldab #$40 ;TOC 2 output toggles on OC2 event; motor drive stops. stab TCTL1 nega ;Invert result -> 0xFF -> 0x01 etc.
;Now set up TOC2 to trigger at a time forward of TOC1. This means
;that themotor will be powered for the number of ticks in ACCA * 256.
done: tab ;TOC 2 is set to trigger after this no of cycles. clra rolb rola rolb rola rolb rola rolb rola rolb rola addd TOC1 std TOC2
ldd #$1000 addd TOC1 std TOC1
ldaa #$80 ;Clear the TOC 1 interrupt staa TFLG1 rti