************************************************************************** * * Title: LED Light Blinking * * Objective: CMPEN 472 Homework 2 in-class-room demonstration * program * * Revision: V1.0 * * Date: Jan. 29, 2025 * * Programmer: Jacob McDonnell * * Company: The Pennsylvania State University * Department of Computer Science and Engineering * * Algorithm: Simple Parallel I/O use and time delay-loop demo * * Register Use: A: LED Light on/off state and Switch 1 on/off state * X,Y: Delay and loop counters * * Memory Use: RAM Locations from $3000 for data, * RAM Locations from $3100 for program * * Input: Parameters hard-coded in the program - PORTB * Switch 1 at PORTB bit 0 * Switch 2 at PORTB bit 1 * Switch 3 at PORTB bit 2 * Switch 4 at PORTB bit 3 * * Output: LED 1 at PORTB bit 4 * LED 2 at PORTB bit 5 * LED 3 at PORTB bit 6 * LED 4 at PORTB bit 7 * * Observation: This program that blinks LEDs and blinking period can * be changed with the delay loop counter value. * * Note: All Homework programs MUST have comments similar * to this Homework 2 program. So, please use those * comment format for all your subsequent CMPEN472 * Homework programs. * * Adding more explanations and comments help you and * others to understnad your program later. * * Comments: This program is developed and simulated using CodeWarrior * development software and targeted for Axion * Manufacturing's CSM-12C128 board running at 24MHz. * ************************************************************************** * Parameter Declearation Section * * Export Symbols xdef pgstart ; export 'pgstart' symbol absentry pgstart ; for assembly entry point * Symbols and Macros PORTA equ $0000 ; i/o port A addresses DDRA equ $0002 ; data direction register for PORTA PORTB equ $0001 ; i/o port B addresses DDRB equ $0003 ; data direction register for PORTB ************************************************************************** * Data Section: address used [ $3000 to $30FF ] RAM Memory * org $3000 ; Reserved RAM memory starting address ; for Data for CMPEN 472 class Counter1 dc.w $0100 ; X register count number for time Delay ; inner loop for msec Counter2 dc.w $00BF ; Y register count number for time delay ; output loop for sec * ************************************************************************** * Program Section: address used [ $3100 to $3FFF ] RAM Memory * org $3100 ; Program start address, in RAM pgstart lds #$3100 ; initialize the stack pointer ldaa #%11111111 ; LED 1, 2, 3, 4 at PORTB bit 4, 5, 6, 7 FOR CSM-12C128 board staa DDRB ; set PORTB bit 4, 5, 6, 7 as Output ldaa #%00000000 staa PORTB ; Turn off LED 1, 2, 3, 4 (all bits in PORTB, for simulation mainLoop ldaa PORTB anda #%00000001 ; Read switch 1 at PORTB bit 0 bne sw1pushed ; check to see if it is pushed sw1notpsh jsr alternate ; Jump to the alternate subroutine to alternate LED 1 and 4 bra mainLoop ; loop back to the beginning to check the switch sw1pushed jsr allBlink ; Jump to the allBlink subroutine to blink all lights bra mainLoop ; loop back to the beginning to check the switch ************************************************************************** * Subroutine Section: address used [ $3100 to $3FFF ] RAM Memory * alternate bset PORTB,%10000000 ; Turn ON LED 4 at PORTB bit 7 bclr PORTB,%00010000 ; Turn off LED 1 at PORTB bit 4 jsr delay1sec ; Wait for 1 second bclr PORTB,%10000000 ; Turn off LED 4 at PORTB bit 7 bset PORTB,%00010000 ; Turn on LED 1 at PORTB bit 4 jsr delay1sec ; Wait for 1 second rts ; Return to the caller allBlink bset PORTB,%11110000 ; Turn ON all 4 LEDs jsr delay1sec ; Wait for 1 second bclr PORTB,%11110000 ; Turn off all 4 LEDs jsr delay1sec ; Wait for 1 second rts ; Return to the caller ;************************************************************************* ; delay1sec subroutine ; ; This subroutine will delay for 1 second ; ; Input: a 16 bit count number in 'Counter2' ; Output: time delay of 1 second, cpu cycles wasted ; Registers in use: Y register as counter ; Memory locations in use: a 16bit input number at 'Counter2' ; ; Comments: This subroutine requires delayMS subroutine ; delay1sec pshy ; save Y to the stack ldy Counter2 ; long delay by the value of Counter2 dly1Loop jsr delayMS ; total time delay = Y * delayMS dey bne dly1Loop puly ; restore y from the stack rts ; return ;************************************************************************* ; delayMS subroutine ; ; This subroutine causes a few msec. Delay ; ; Input: a 16bit count number in 'Counter1' ; Output: time delay, cpu cycle wasted ; Registers in use: X register, as counter ; Memory locations in use: a 16bit input number at 'Counter1' ; ; Comments: one can add more NOP instructions to lengthen the delay time. ; delayMS pshx ; save X to the stack ldx Counter1 ; short Delay dlyMSLoop nop ; total time delay = X * NOP dex bne dlyMSLoop pulx ; restore X rts ; return * * Add any subroutines here *