********************************************************************* * Authors: B. Alex Bridges and Davy Little * * Class: ECE-374, Summer 1998 * * Project: Lab Assignment #6 * * Description: This program simulates a traffic light at the inter- * * section of two streets. * ********************************************************************* ** CONSTANTS / VARIABLES ** ABSOLUTE ORG $00 TEMP: FDB 33333 * Value Corresponding to .1 Second Delay T1: FCB 0 * Time Delay #1 In Number of TOFs T2: FCB 0 * Time Delay #2 In Number of TOFs SW: FCB 0 * Current Bit Pattern For Switches SWIN: FCB %00111111 * DDRC Bit Pattern For Input Switches/Output LEDs SWOUT: FCB %11000000 * DDRC Bit Pattern For Output Switches/Input LEDs MASK: FCB %11000000 * Mask For Revealing Switches Bit Pattern LIGHT2: FCB %01000000 * Bit Pattern For Street Light Pattern #2 LIGHT1: FCB %10000000 * Bit Pattern For Street Light Pattern #1 LIGHT3: FCB %11000000 * Bit Pattern For Street Light Pattern #3 LIGHT0: FCB %00000000 * Bit Pattern For Street Light Pattern #0 G2R1: FCB %00001100 * Bit Pattern For Lighting R1 and G2 Y2R1: FCB %00010100 * Bit Pattern For Lighting R1 and Y2 R2R1: FCB %00100100 * Bit Pattern For Lighting R1 and R2 R2G1: FCB %00100001 * Bit Pattern For Lighting G1 and R2 R2Y1: FCB %00100010 * Bit Pattern For Lighting Y1 and R2 NONE: FCB %00000000 * Bit Pattern For Lighting Nothing DDRC: EQU $1007 * Address Corresponding to DDRC (PORTC's I/O Settings) PORTC: EQU $1003 * Address Corresponding to Port C TFLG2: EQU $1025 * Address Corresponsing to Timer Interrupt Flag 2 ** PROGRAM - MAIN ** RELATIVE ORG $C100 BEGIN: LDS #$C0FF * Set custom value for stack pointer S LOOP: LDAA SWIN * Set DDRC bit pattern for input switches STAA DDRC LDAA PORTC * Load, reveal, and store bit pattern for switches ANDA MASK STAA SW CMP1: LDAA SW * Load current bit pattern for switches CMPA LIGHT2 * Switches vs. LIGHT2 BNE CMP2 LDAB #152 * 5 seconds = 5000 ms / 33 ms = 151.5 -> 152 times STAB T1 LDAB #61 * 2 seconds = 2000 ms / 33 ms = 60.6 -> 61 times STAB T2 JSR LIGHTS * Call Light Pattern subroutine CMP2: LDAA SW * Load current bit pattern for switches CMPA LIGHT1 * Switches vs. LIGHT1 BNE CMP3 LDAB #91 * 3 seconds = 3000 ms / 33 ms = 90.9 -> 91 times STAB T1 LDAB #30 * 1 seconds = 1000 ms / 33 ms = 30.3 -> 30 times STAB T2 JSR LIGHTS * Call Light Pattern subroutine CMP3: LDAA SW * Load current bit pattern for switches CMPA LIGHT3 * Switches vs. LIGHT3 BNE CMP4 LDAB #6 * 0.2 seconds = 200 ms / 33 ms = 6.1 -> 6 times STAB T1 LDAB #0 * Not Used for LIGHT3 STAB T2 JSR TOGGLE * Call Toggle Pattern subroutine CMP4: LDAA SW * Load current bit pattern for switches CMPA LIGHT0 * Switches vs. LIGHT0 BNE LOOP LDAA NONE * Turn off the LEDs STAA PORTC END: SWI ** PROGRAM - SUBROUTINES ** LIGHTS: LDAA G2R1 * Light R1 and G2 STAA PORTC LDAA T1 * T1 -> A = Current Time Delay JSR DELAY * Call Delay subroutine * LDAA Y2R1 * Light R1 and Y2 STAA PORTC LDAA T2 * T2 -> A = Current Time Delay JSR DELAY * Call Delay subroutine * LDAA R2R1 * Light R1 and R2 STAA PORTC LDAA T2 * T2 -> A = Current Time Delay JSR DELAY * Call Delay subroutine * LDAA R2G1 * Light G1 and R2 STAA PORTC LDAA T1 * T1 -> A = Current Time Delay JSR DELAY * Call Delay subroutine * LDAA R2Y1 * Light Y1 and R2 STAA PORTC LDAA T2 * T2 -> A = Current Time Delay JSR DELAY * Call Delay subroutine * LDAA R2R1 * Light R1 and R2 STAA PORTC LDAA T2 * T2 -> A = Current Time Delay JSR DELAY * Call Delay subroutine RTS * Go Back To MAIN TOGGLE: LDAA Y2R1 * ON = Light R1 and Y2 STAA PORTC LDAA T1 * T1 -> A = Current Time Delay JSR DELAY * Call Delay subroutine LDAA NONE * OFF = Light Nothing STAA PORTC LDAA T1 * T1 -> A = Current Time Delay JSR DELAY * Call Delay subroutine RTS * Go Back To MAIN DELAY: JSR TOF * Call Timer Overflow subroutine DECA * Decrease number of TOFs BNE DELAY * Repeat until 0 TOFs RTS TOF: LDAB TFLG2 * Polling for Timer Overflow BPL TOF LDAB #%10000000 * Clear Timer Overflow STAB TFLG2 RTS