Closed HoldenWright closed 6 years ago
Indicate what floor the elevator is on in real time. Each LED represents a floor.
Maybe I could just get started with making the sequences
; NEEDS A varable called `stateofelevator` to work right
; TODO: I could just use a 1 8 bit variable and set `1` on the floors I need to go to
xdef blink,blinkloop
xdef sec2, sec1
xref stateofelevator, port_t, port_s
going_up_sequence dc.b $01, $02, $04, $08, $10, $20, $40, $80
going_down_sequence dc.b $80, $40, $20, $10, $08, $04, $02, $01
blink_sequence dc.b $FF, $00
lenghtofdelay equ 50000
; ldab #0
blink: ldx #blink_sequence ; alternates between fully on and fully off
ldab #0
clr stateofelevator ;Each time it goes to the blink sequence, it will clear the stateofelevator
blinkloop: cmpb #2
bge blink ; resets the blinking
ldaa 1,x+ ; moves through the blink_sequence
staa port_s; displays it to the led
jsr Delay
incb
ldy stateofelevator ; this will need to change beacuse this should be if a floor has been selected
cpy #1
bge state_of_t ; if greater then 1 check to see of it should move up or down
bra blinkloop
state_of_t: ldaa stateofelevator
ldab #0 ; Loadx clears B which I use for counting
cmpa #1 ; if stateofelevator is less or equal 1 it will start blinking
blo blink
cmpa #2 ; if stateofelevator is equal 2 it will start the going_up_sequence
beq sec1
sec2: ldx #going_down_sequence ; and reloads the sequence into x
;------------------------- LOOP 1 -------------------------------
whi: cmpb #8; checks to see if (B >= 6)
bge blink ; if true, go to "loadx"
ldaa 1,x+ ; else move through the array
INCB ; and increment B
staa port_s ; store the values of A to the LEDS
jsr Delay; adds a delay of 500 ms
;cmpa port_t
;bne state_of_t
bra whi ; LOOP
;----------------------- LOOP 2 --------------------------------
sec1:ldx #going_up_sequence
whil: cmpb #8; checks to see if (B >= 5)
bge blink ; if true, go to "loadx"
ldaa 1,x+ ; else move through the array
INCB ; and increment B
staa port_s ; store the values of A to the LEDS
jsr Delay; adds a delay of 500ms
; cmpa port_t
;bne state_of_t
bra whil ; LOOP
;------------------------- DELAY----------------------------------
Delay: pshb
pshx
ldab #10
outer:ldx #lenghtofdelay
loop: dex
bne loop
DBNE b,outer
pulx
pulb
rts
;**************************************************************
;* This stationery serves as the framework for a *
;* user application. For a more comprehensive program that *
;* demonstrates the more advanced functionality of this *
;* processor, please see the demonstration applications *
;* located in the examples subdirectory of the *
;* Freescale CodeWarrior for the HC12 Program directory *
;**************************************************************
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
; export symbols
XDEF Entry,port_s, ddr_s, port_t,stateofelevator
; we use export 'Entry' as symbol. This allows us to
; reference 'Entry' either in the linker .prm file
; or from C/C++ later on
XREF __SEG_END_SSTACK, blink ; symbol defined by the linker for the end of the stack
My_Constant: section
port_s equ $248
ddr_s equ $24A
port_t equ $240
going_up_sequence dc.b $01, $02, $04, $08, $10, $20, $40, $80
going_down_sequence dc.b $80, $40, $20, $10, $08, $04, $02, $01
blink_sequence dc.b $FF, $00
lenghtofdelay equ 50000
My_Variable: section
stateofelevator ds.b 1
My_Code: SECTION
Entry:
;------------------------- Setup ------------------------------------
lds #__SEG_END_SSTACK
ldaa #$FF ; Flushing the LEDs
staa ddr_s; Loading the flush
clr stateofelevator
jsr blink
XDEF stepper_motor
XREF port_p_ddr,port_t,port_p
XREF direction, is_open_or_closed, LED
XREF flag
XREF stepper_delay, stepper_flag
XREF should_led
val ds.b 1
highorlow ds.w 2
DelayCount ds.w 1
clockwise_seq: dc.b $0A, $12, $14, $0C, $0
counterclockwise_seq: dc.b $0C, $14, $12, $0A, $0
stepper_motor:
ldaa direction
cmpa #0
beq led_blink
ldaa is_open_or_closed
cmpa #1
beq nope
movb #3,flag
change_in_direction:
ldaa direction
cmpa #$2 ; if equal to 2 it will send vals in to x
beq clock
cmpa #$1 ; if equal to 1 it will send vals1 into x
beq counter
rts
Delay: ldaa stepper_flag
cmpa #1
CLI ; had problem with interupt flag not getting reset
beq Delay
again:
LDAA 1,x+
cmpa #$0
beq increment
STAA port_p
movb #1, stepper_flag
bra Delay
increment: inc should_led
ldaa should_led
cmpa #8
bne nope
led_blink: jsr LED
movb #0,should_led
nope: rts
;alternate from clock wise to counter clock wise
clock:
ldx #clockwise_seq ;clock wise
bra again
counter:
ldx #counterclockwise_seq ; counter clock wise
bra again
The LEDs should indicate what floor the elevator is on in real time. Each LED represents a floor. When the elevator is in motion, one LED should travel from right to left when the elevator is moving up and from left to right when elevator is moving down. When the elevator reaches the desired floor, the LED should blink until another floor is selected. If secret mode is activated, the elevator goes in ghost mode and all LEDs are turned off. In addition, if the emergency shut off is activated, the LEDs should repeatedly blink on and off until the user enters the Admin password.