* * Lab3 * * Purpose: Make car dance with following pattern * 1) forward 2 seconds * 2) backward 1 second * 3) left 1 second * 4) stop 1/4 second * 5) right 1 second * 6) stop 1 second * 7) repeat * * Author: Heather D. Pfeiffer * * Setup some useful labels EEPROM equ $f800 RESET equ $fffe FORWARD equ $aa BACKWARD equ $a0 LEFT equ $a2 RIGHT equ $a8 STOP equ 0 MOTORS equ $1004 * Program code for dancing org EEPROM start * First go forward for 2 seconds ldaa #FORWARD * load up forward direction staa MOTORS ldab #8 * initialize the outside down counter forout ldx #49999 * initialize the inside down counter forin staa MOTORS dex bne forin * 10 cycles in loop * 49999 = 499,990 cycles decb bne forout * (499,990 + 8 padding) * 8 = 3,999,984 nop brn forout brn forout * Second go backwards for 1 second ldaa #BACKWARD * load up backward direction * 12 cycles from above padding + 4 next store instruction * gives 3999984 + 16 = 4,000,000 cycles for forward direction staa MOTORS ldab #4 bkout ldx #49999 * initialize the countdown counter bkin staa MOTORS dex bne bkin * 10 cycles in loop * 49999 = 499,990 cycles decb bne bkout * (499,990 + 8 padding) * 4 = 1,999,992 * Third go left for 1 second ldaa #LEFT * load up left direction * 4 cycles from counter and direction loads + 4 next store instruction * gives 1999992 + 8 = 2,000,000 cycles for backward direction staa MOTORS ldab #4 lfout ldx #49999 * initialize the countdown counter lfin staa MOTORS dex bne lfin * 10 cycles in loop * 49999 = 499,990 cycles decb bne lfout * (499,990 + 8 padding) * 4 = 1,999,992 * Fourth go no where for 1/4 of a second ldaa #STOP * load up stop * 4 cycles from counter and direction loads + 4 next store instruction * gives 1999992 + 8 = 2,000,000 cycles for left direction staa MOTORS ldx #49998 * initialize the countdown counter nolp staa MOTORS dex bne nolp * 10 cycles in loop * 49998 = 499,980 cycles brn nolp staa MOTORS staa MOTORS * Fifth go right for 1 second ldaa #RIGHT * load up right direction * 16 cycles from counter and direction loads, and padding * + 4 next store instruction * gives 499980 + 20 = 500,000 cycles for stop staa MOTORS ldab #4 rgout ldx #49999 * initialize the countdown counter rgin staa MOTORS dex bne rgin * 10 cycles in loop * 49999 = 499,990 cycles decb bne rgout * (499,990 + 8 padding) * 4 = 1,999,992 * Sixth go no where for 1 second ldaa #STOP * load up stop * 4 cycles from counter and direction loads + 4 next store instruction * gives 1999992 + 8 = 2,000,000 cycles for right direction staa MOTORS ldab #4 stout ldx #49998 * initialize the countdown counter stin staa MOTORS dex bne stin * 10 cycles in loop * 49998 = 499,980 cycles brn stout brn stout nop decb bne stout * (499,980 + 16 padding) * 4 = 1,999,984 nop brn stout jmp start * 10 cycles here + 2 cycles at start + 4 for store = 16 cycles * gives 1,999,984 + 16 = 2,000,000 cycles for final stop * Setup the RESET vector org RESET fdb start