;----------------------------------------------------------------------------------------------------------
; Program for Motorola 68HC12
; Drives the stepper motor at a rate determined by the switch setting.
;
;--------------------------------------------------------------------
XDEF main
DDRH: EQU $25 ;Declaring location of Data Direction Reg. H
PORTH: EQU $24 ;Declaring location of Port H
DDRJ: EQU $29 ;Declaring location of Data Direction Reg. J
PORTJ: EQU $28 ;Declaring location of Port J
PORTG: EQU $31 ;Declaring location of Port G
DDRG: EQU $33 ;Declaring location of Data Direction Reg. G
;*********************************
TFLG2: EQU $008F ; Timer Interrupt Flag 2
TSCR: EQU $0086 ; Timer System Control Register
TMSK2: EQU $008D ; Timer Interrupt Mask Register 2
TCNT: EQU $0084 ; Timer Count Register
TOI: EQU %10000000 ; Timer Overflow Interrupt enable
TOF: EQU %10000000 ; Timer Overflow Flag
TEN: EQU %10000000 ; Timer Enable
TOFVEC: EQU $00D0 ; Timer Overflow Flag Vector
Ntimes: EQU 30 ; Number of times flag needs to be set
myData: section
locData: section
;********************************
DISPLAY DS.B 1 ; Allocating space for DISPLAY - one byte
COUNT DS.B 1 ; Allocating space for COUNT - one byte
;*******************************
data: dc.b 12, 4, 6, 2, 3, 1, 9, 8 ; The array that holds all values of the stepping sequence
myCode: section
;--------------------------------------------------
; INITIALIZATION
;--------------------------------------------------
main:
LDS #$07FF ; Initialize Stack
LDAA #0 ; Sets input direction
STAA DDRH ; to DDR H
LDAA #$FF ; Makes Port G & J output
STAA DDRG
STAA DDRJ
;************************************************
LDAA #TOF ;Clear the flag before starting the time
STAA TFLG2
BSET TSCR,#TEN ;Enable the timer
;******************************************************
;--------------------------------
SEI ; Set interrupts off
CLR COUNT ; Clear count
LDAA TOF ; Clear TOF first
STAA TFLG2
LDAA #TOI ;Enable Timer overflow interrupt
STAA TMSK2
CLI ; Set interrupts on
JMP TOFISR ; Jump to TOFISR
;---------------------------------------------------
; STEPPER MOTOR ACTION
;-----------------------------------------------------
start: LDX #data ; Load Register X from array
next: LDAA 0,X
STAA PORTG ; Store the value to port G in order to move the stepper motor
HERE: BRA HERE ; Wait HERE for interrupt
RUN: BSR Switch1 ; Branch to subroutine "Switch 1"
LDAB PORTH
ANDB #$01 ; Check Switch 8
BNE reverse ; Branch if not equal to reverse
forward:
INX ; Increment X
CPX #data+8 ; Compare it
BNE next ; If not equal goto next
BRA start ; Always branch to start
reverse:
DEX ; Decrement X
CPX #data-1 ; Compare it
BNE next ; If not equal goto next
LDX #data+7 ; Load register X from array
BRA next ; Always branch to next
;---------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;-------------------------------------------------
TOFISR:
INC COUNT ; Increment COUNT
LDAA COUNT ; Load accumulator A from COUNT
CMPA #Ntimes ; Compare it with the number of times flag needs to be set
BNE ENDIF ; If not equal branch to ENDIF
INC DISPLAY ; Increment DISPLAY
STAA DISPLAY ; Store value to DISPLAY
STAA PORTJ ; Store it to port J (LEDs)
JSR RUN ; Jump to subroutine RUN
CLR COUNT ; Clear COUNT
ENDIF: LDAA #TOF ; Clear flag
STAA TFLG2
RTI ; Return from interrupt
;---------------------------------------------
; DELAY
;----------------------------------------------
Switch1:
LDAB PORTH ; Check Switch 1
ANDB #$80
BEQ Switch1 ; Branch if equal to Switch1
switch7:
LDAA PORTH ; Check switch 7
ANDA #$02
BNE delay ; Branch if not equal to delay
back:
RTS ; Return from subroutine
delay: LDAA #Ntimes ; Initialize COUNT to wait for Ntimes
STAA COUNT
wait1: BRCLR TFLG2,#TOF,wait1 ; Poll the TOF bit and branch when the bit is set to 1
LDAA #TOF ; CLear the TOF flag
STAA TFLG2
DEC COUNT ; Decrement the counter
BNE wait1 ; Branch if not equal to wait1
BRA back ; Always branch to back
               (
geocities.com/g1ak4)