summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2025-02-18 19:09:59 -0500
committerJacob McDonnell <jacob@jacobmcdonnell.com>2025-02-18 19:09:59 -0500
commit101fbb010f0a580b1227b5fab699dac39508c136 (patch)
tree363c41d37080d5f9a03919a8b58eef0a76a2704f
parentd130e95e39401aa09b10836d8b26cc659ee3b1ba (diff)
WriteString and initial serial
-rw-r--r--cmpen472hw5_McDonnell/Sources/main.asm97
1 files changed, 75 insertions, 22 deletions
diff --git a/cmpen472hw5_McDonnell/Sources/main.asm b/cmpen472hw5_McDonnell/Sources/main.asm
index 55f7e17..06b44c8 100644
--- a/cmpen472hw5_McDonnell/Sources/main.asm
+++ b/cmpen472hw5_McDonnell/Sources/main.asm
@@ -57,6 +57,15 @@ DDRA equ $0002 ; data direction register for PORTA
PORTB equ $0001 ; i/o port B addresses
DDRB equ $0003 ; data direction register for PORTB
+SCIBDH equ $00C8 ; Serial port (SCI) Baud Register H
+SCIBDL equ $00C9 ; Serial port (SCI) Baud Register L
+SCICR2 equ $00CB ; Serial port (SCI) Control Register 2
+SCISR1 equ $00CC ; Serial port (SCI) Status Register 1
+SCIDRL equ $00CF ; Serial port (SCI) Data Register
+
+CR equ $0d ; carriage return, ASCII 'Return' key
+LF equ $0a ; line feed, ASCII 'next line' character
+
**************************************************************************
* Data Section: address used [ $3000 to $30FF ] RAM Memory
*
@@ -66,7 +75,7 @@ Counter dc.w $0036 ; X register count number for time Delay
; loop for 10 useconds
; The work to calculate this number is in
; the comments for the delay10usec subroutine.
-
+
LEVEL dc.b $0005 ; Light Level that the LED should be
*
@@ -80,22 +89,6 @@ pgstart lds #$3100 ; initialize the stack pointer
staa DDRB ; set PORTB bit 4,5,6,7 as output
mainLoop
- ldaa #1
- jsr TurnOnLED
- ldaa #2
- jsr TurnOnLED
- ldaa #3
- jsr TurnOnLED
- ldaa #1
- jsr TurnOffLED
- ldaa #2
- jsr TurnOffLED
- ldaa #3
- jsr TurnOffLED
- jsr HighToLow
- jsr HighToLow
- jsr LowToHigh
- jsr LowToHigh
bra mainLoop ; Loop back to mainLoop always
**************************************************************************
@@ -103,6 +96,28 @@ mainLoop
*
;*************************************************************************
+; WriteString subroutine
+;
+; This subroutine will write a given null terminated string to the serial.
+;
+; Input: Address of null terminated string in X
+; Output: Null terminated string written to serial
+; Registers in use: X for the address of the string and A for the current byte
+; Memory locations in use: Memory Address for serial line, address of the string
+;
+; Comments: This subroutine requires serial to be setup and putchar subroutine.
+;
+
+WriteString
+ psha ; Save A to the stack
+writeLoop ldaa 1,x+ ; Load the byte at addr in X, then add 1
+ beq doneWrite ; if A == 0, branch to doneWrite
+ jsr putchar ; Jump to putchar to write byte to serial
+ bra writeLoop ; branch always to writeLoop
+doneWrite pula ; restore A from the stack
+ rts ; return to caller
+
+;*************************************************************************
; TurnOnLED subroutine
;
; This subroutine will dim turn on a specified LED
@@ -124,7 +139,7 @@ onCheckTwo cmpa #2 ; Compare A to 2
bne onCheckThr ; If A != 2, check next number
bset PORTB,%00100000 ; Turn On LED 2
bra onDone ; Jump to onDone
-onCheckThr bset PORTB,%01000000 ; Turn On LED 3
+onCheckThr bset PORTB,%01000000 ; Turn On LED 3
onDone rts ; Return to caller
;*************************************************************************
@@ -149,7 +164,7 @@ ofCheckTwo cmpa #2 ; Compare A to 2
bne ofCheckThr ; If A != 2, check next number
bclr PORTB,%00100000 ; Turn Off LED 2
bra ofDone ; Jump to onDone
-ofCheckThr bclr PORTB,%01000000 ; Turn Off LED 3
+ofCheckThr bclr PORTB,%01000000 ; Turn Off LED 3
ofDone rts ; Return to caller
;*************************************************************************
@@ -178,7 +193,7 @@ decrease tbeq A,doneDec ; Test if A == 0, skip loop if so
bra decrease ; loop to decrease always
doneDec pula ; Restore A from the stack
rts ; Return to caller
-
+
;*************************************************************************
; HighToLow subroutine
;
@@ -252,9 +267,9 @@ doneLoop pula ; restore A from the stack
; Comments: Code relies on counter being $39 to be exactly 10 usec work is below
; Given: freq = 24MHz = 24000000 sec = 10 usec = 0.00001
; freq = cycles / seconds
-;
+;
; cycles = freq * seconds = 24000000Hz * 0.00001 = 240
-;
+;
; This sub routine is 12 + 4 * 'Counter' cycles long, solving for 'Counter'
; the result is found to be 57.
;
@@ -268,5 +283,43 @@ innerLoop dex ; decrement register x by 1
nop ; extra nop to make exactly 10 usec
rts ; return to caller
+;***************putchar************************
+;* Program: Send one character to SCI port, terminal
+;* Input: Accumulator A contains an ASCII character, 8bit
+;* Output: Send one character to SCI port, terminal
+;* Registers modified: CCR
+;* Algorithm:
+; Wait for transmit buffer become empty
+; Transmit buffer empty is indicated by TDRE bit
+; TDRE = 1 : empty - Transmit Data Register Empty, ready to transmit
+; TDRE = 0 : not empty, transmission in progress
+;**********************************************
+putchar brclr SCISR1,#%10000000,putchar ; wait for transmit buffer empty
+ staa SCIDRL ; send a character
+ rts
+;***************end of putchar*****************
+
+
+;****************getchar***********************
+;* Program: Input one character from SCI port (terminal/keyboard)
+;* if a character is received, other wise return NULL
+;* Input: none
+;* Output: Accumulator A containing the received ASCII character
+;* if a character is received.
+;* Otherwise Accumulator A will contain a NULL character, $00.
+;* Registers modified: CCR
+;* Algorithm:
+; Check for receive buffer become full
+; Receive buffer full is indicated by RDRF bit
+; RDRF = 1 : full - Receive Data Register Full, 1 byte received
+; RDRF = 0 : not full, 0 byte received
+;**********************************************
+getchar brclr SCISR1,#%00100000,getchar7
+ ldaa SCIDRL
+ rts
+getchar7 clra
+ rts
+;****************end of getchar****************
+
end ; last line of the file