diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-02-03 16:28:41 -0500 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-02-03 16:28:41 -0500 |
| commit | f88257c06ad029e9e3585d291be983da7ae9c137 (patch) | |
| tree | d9fd599756a13c8e57484a322c5b73b0da088e19 | |
| parent | 8e27239f2ca018dd72a8a459c6eceea163a00249 (diff) | |
Initial idea
| -rw-r--r-- | cmpen472hw3McDonnell/Sources/main.asm | 177 |
1 files changed, 67 insertions, 110 deletions
diff --git a/cmpen472hw3McDonnell/Sources/main.asm b/cmpen472hw3McDonnell/Sources/main.asm index 592bf1b..bdbd7d5 100644 --- a/cmpen472hw3McDonnell/Sources/main.asm +++ b/cmpen472hw3McDonnell/Sources/main.asm @@ -16,10 +16,11 @@ DDRB equ $0003 ; data direction register for PORTB *
org $3000 ; Reserved RAM memory starting address
; for Data for CMPEN 472 class
-Counter1 dc.w $008f ; X register count number for time Delay
- ; inner loop for msec
-Counter2 dc.w $000c ; Y register count number for time delay
- ; output loop for sec
+Counter dc.w $0039 ; X register count number for time Delay
+ ; loop for 10 useconds
+ONN dc.b $0005 ; Counter for how long LED should be on for
+
+OFF dc.b $005f ; Counter for how long LED should be off for
*
**************************************************************************
* Program Section: address used [ $3100 to $3FFF ] RAM Memory
@@ -29,132 +30,88 @@ pgstart lds #$3100 ; initialize the stack pointer ldaa #%11110001 ; LED 1,2,3,4 at PORTB bit 4,5,6,7
staa DDRB ; set PORTB bit 4,5,6,7 as output
-
-
+
+
ldaa #%00000000
staa PORTB ; clear all bits of PORTB
-
+
mainLoop
ldaa PORTB ; check bit 0 of PORTB, switch 1
anda #%00000001 ; if 0, run blinkLED4 20% light level
- bne p80LED4 ; if 1, run blinkLED4 80% light level
-
-p20LED4
- jsr LED4on ; 20% light level (duty cycle)
- jsr LED4on
- jsr LED4off
- jsr LED4off
- jsr LED4off
- jsr LED4off
- jsr LED4off
- jsr LED4off
- jsr LED4off
- jsr LED4off
- bra mainLoop ; check switch, loop forever
-
-p80LED4
- jsr LED4on ; 80% light level (duty cycle)
- jsr LED4on
- jsr LED4on
- jsr LED4on
- jsr LED4on
- jsr LED4on
- jsr LED4on
- jsr LED4on
- jsr LED4off
- jsr LED4off
- bra mainLoop ; check switch, loop forever
-
+ bne p15LED4 ; if 1, run blinkLED4 80% light level
+
+p05LED4
+ ldaa #5 ; load 5 into accumulator A
+ staa ONN ; store A in counter ONN
+ ldaa #95 ; load 95 into accumulator A
+ staa OFF ; store A in counter OFF
+ jsr dimmer ; jump to dimmer subroutine
+ bra mainLoop ; loop to mainLoop to check switch
+
+p15LED4
+ ldaa #15 ; load 15 into accumulator A
+ staa ONN ; store A in counter ONN
+ ldaa #85 ; load 85 into accumulator A
+ staa OFF ; store A in counter OFF
+ jsr dimmer ; jump to dimmer subroutine
+ bra mainLoop ; loop to mainLoop to check switch
+
**************************************************************************
* Subroutine Section: address used [ $3100 to $3FFF ] RAM Memory
*
;*************************************************************************
-; LED4off subroutine
-;
-; This subroutine will turn LED4 off and delay for 1 second
-;
-; Input: no input, parameters are hardcoded
-; Output: LED4 off and delay for 1 second, wasted cycles
-; Registers in use: A accumulator to turn LED4 off
-; Memory locations in use: A 16bit address parameter for PORTB
+; dimmer subroutine
;
-; Comments: This subroutine requires delay1sec subroutine
-;
-LED4off
- psha ; save A register to the stack
- ldaa #%01111111 ; turn off LED 4 at PORTB bit 7
- anda PORTB
- staa PORTB
- jsr delay1sec ; wait for 1 second
- pula ; restore A from the stack
- rts ; return to caller
-
-;*************************************************************************
-; LED4on subroutine
+; This subroutine will dim LED4 to a given level
;
-; This subroutine will turn LED4 on and delay for 1 second
+; Input: Two 1 byte counters, ONN and OFF, for how many times
+; LED4 should be on and off for.
+; Output: LED4 dimmed to a given level, wasted cycles
+; Registers in use: A accumulator to counter number of times looped
+; Memory locations in use: Two bytes ONN and OFF used to dim the LED4 to a given level
;
-; Input: no input, parameters are hardcoded
-; Output: LED4 on and delay for 1 second, wasted cycles
-; Registers in use: A accumulator to turn LED4 on
-; Memory locations in use: A 16bit address parameter for PORTB
+; Comments: This subroutine requires delay10usec subroutine
;
-; Comments: This subroutine requires delay1sec subroutine
-;
-LED4on
- psha ; save A register to the stack
- ldaa #%10000000 ; turn on LED 4 at PORTB bit 7
- oraa PORTB
- staa PORTB
- jsr delay1sec ; wait for 1 second
- pula ; restore A from the stack
+
+dimmer
+ bset PORTB,%10000000 ; Turn LED4 on
+ psha ; Save A to the stack
+loop1 ldaa ONN ; Load counter ONN into A
+ bne loop2 ; if zero jump to loop2 for off
+ jsr delay10usec ; delay for 10 microseconds
+ dec ONN ; decrement counter ONN by 1
+ bra loop1 ; jump back to loop1 always
+ bclr PORTB,%10000000 ; Turn off LED4
+loop2 ldaa OFF ; load counter OFF into A
+ bne doneRunner ; if 0, skip loop
+ jsr delay10usec ; delay 10 microseconds
+ dec OFF ; decrement counter OFF by 1
+ bra loop2 ; jump back to loop2 always
+doneRunner pula ; restore A from the stack
rts ; return to 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
+; delay10usec subroutine
;
-; This subroutine causes a few msec. Delay
+; This subroutine causes a 10 usec. delay
;
-; Input: a 16bit count number in 'Counter1'
+; Input: a 16bit count number in 'Counter'
; 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.
+; Memory locations in use: a 16bit input number at 'Counter'
+;
+; Comments: Code relies on counter being $39 to be exactly 10 usec
;
-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
+delay10usec
+ pshx ; Save register x to the stack
+ ldx Counter ; load counter into register x
+innerLoop dex ; decrement register x by 1
+ bne innerLoop ; loop while register x is not 0
+ pulx ; restore register x from the stack
+ nop ; extra nop to make exactly 10 usec
+ rts ; return to caller
+
+ done
+
|
