summaryrefslogtreecommitdiff
path: root/cmpen472hw10_McDonnell/Sources
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2025-04-07 19:30:15 -0400
committerJacob McDonnell <jacob@jacobmcdonnell.com>2025-04-07 19:30:15 -0400
commit2fd1f7292d432684783e021c149e89c275f69334 (patch)
tree99df5110ada26fd9144367aab76504449073f8a3 /cmpen472hw10_McDonnell/Sources
parent9b8d7d6fc21b4627973a100c73eca46e8f8524ed (diff)
HW10: 8KHz waves working
Diffstat (limited to 'cmpen472hw10_McDonnell/Sources')
-rw-r--r--cmpen472hw10_McDonnell/Sources/example.asm356
-rw-r--r--cmpen472hw10_McDonnell/Sources/main.asm180
2 files changed, 483 insertions, 53 deletions
diff --git a/cmpen472hw10_McDonnell/Sources/example.asm b/cmpen472hw10_McDonnell/Sources/example.asm
new file mode 100644
index 0000000..0ab912d
--- /dev/null
+++ b/cmpen472hw10_McDonnell/Sources/example.asm
@@ -0,0 +1,356 @@
+;*******************************************************
+;* CMPEN 472, 2022 Spring
+;* Homework 10: Timer Interrupt Sample Program,
+;* MC9S12C128 Program (set to MC9S12C32 for Simulation/Debug)
+;* CodeWarrior Simulator/Debug edition, not for CSM-12C128 board
+;* Nov. 01, 2021 Kyusun Choi
+;* March 27, 2022 Kyusun Choi
+;* Nov. 07, 2022 Kyusun Choi
+;*
+;* This program is a 1024 data transfer program running on the
+;* CodeWarrior Debugger/Simulator as follows:
+;* 1. Program starts with print messages on the simulator Terminal,
+;* an intro message at 1.5M baud (this program will not work
+;* on the CSM-12C128 board - 1.5M baud too fast).
+;* 2. Then user may hit any key, it's a typewriter program at 1.5M baud.
+;* But hitting the Enter key will terminate the typewriter mode with
+;* the instruction message print.
+;* 3. Two messages are (1) start terminal data capture into a file and
+;* (2) hit Enter key for the 1024 data transfer to begin.
+;* 4. At this time, user setup the Terminal Output file, data capture to a file.
+;* 5. User hits an Enter key to send 1024 data, to the Terminal and
+;* the data saved in to a file named RxData3.txt which may be looked at
+;* or plotted using Excel sheet.
+;* 6. User may repeat the step 3 above as many times as he/she like.
+;* User plots or prints the data to verify the correct data transmit.
+;*
+;* We assumed 24MHz bus clock and 4MHz external resonator clock frequency.
+;*
+;*******************************************************
+;*******************************************************
+
+; export symbols - program starting point
+ XDEF Entry ; export 'Entry' symbol
+ ABSENTRY Entry ; for assembly entry point
+
+; include derivative specific macros
+PORTB EQU $0001
+DDRB EQU $0003
+
+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
+
+TIOS EQU $0040 ; Timer Input Capture (IC) or Output Compare (OC) select
+TIE EQU $004C ; Timer interrupt enable register
+TCNTH EQU $0044 ; Timer free runing main counter
+TSCR1 EQU $0046 ; Timer system control 1
+TSCR2 EQU $004D ; Timer system control 2
+TFLG1 EQU $004E ; Timer interrupt flag 1
+TC6H EQU $005C ; Timer channel 2 register
+
+CR equ $0d ; carriage return, ASCII 'Return' key
+LF equ $0a ; line feed, ASCII 'next line' character
+
+DATAmax equ 1024 ; Data count maximum, 1024 constant
+
+;*******************************************************
+; variable/data section
+ ORG $3000 ; RAMStart defined as $3000
+ ; in MC9S12C128 chip
+
+ctr125u DS.W 1 ; 16bit interrupt counter for 125 uSec. of time
+
+BUF DS.B 6 ; character buffer for a 16bit number in decimal ASCII
+CTR DS.B 1 ; character buffer fill count
+
+msg1 DC.B 'Hello, this is 1024 data transmit program.', $00
+msg2 DC.B 'When ready, hit Enter key.', $00
+;* more text messages at the End of this program
+
+;*******************************************************
+; interrupt vector section
+
+ ORG $FFE2 ; Timer channel 6 interrupt vector setup, on simulator
+ DC.W oc6isr
+
+;*******************************************************
+; code section
+
+ ORG $3100
+Entry
+ LDS #Entry ; initialize the stack pointer
+
+ LDAA #%11111111 ; Set PORTB bit 0,1,2,3,4,5,6,7
+ STAA DDRB ; as output
+ LDAA #%00000000 ; Clear PORTB bit 0,1,2,3,4,5,6,7
+ STAA PORTB ; Clear all bits of PORTB, initialize
+
+ ldaa #$0C ; Enable SCI port Tx and Rx units
+ staa SCICR2 ; disable SCI interrupts
+
+ ldd #$0001 ; Set SCI Baud Register = $0001 => 1.5M baud at 24MHz (for simulation)
+; ldd #$0002 ; Set SCI Baud Register = $0002 => 750K baud at 24MHz
+; ldd #$000D ; Set SCI Baud Register = $000D => 115200 baud at 24MHz
+; ldd #$009C ; Set SCI Baud Register = $009C => 9600 baud at 24MHz
+ std SCIBDH ; SCI port baud rate change
+
+ ldx #msg1 ; print the first message, '1024 data transmit'
+ jsr printmsg
+ jsr nextline
+
+ ldx #msg2 ; print the second message, user instruction,
+ jsr printmsg ; hit 'Enter'
+ jsr nextline
+
+mloop1
+ jsr getchar
+ cmpa #0
+ beq mloop1
+ jsr putchar ; type writer, with echo print
+ cmpa #CR
+ bne mloop1 ; if Enter/Return key is pressed, move the
+
+ ldaa #LF ; cursor to next line
+ jsr putchar
+
+ ldx #msg3 ; print '> Set Terminal save file RxData3.txt'
+ jsr printmsg
+ jsr nextline
+
+ ldx #msg4 ; print '> Press Enter/Return key to start sawtooth wave'
+ jsr printmsg
+ jsr nextline
+
+ jsr delay1ms ; flush out SCI serial port
+ ; wait to finish sending last characters
+
+mloop2
+ jsr getchar
+ cmpa #0
+ beq mloop2
+ cmpa #CR
+ bne mloop2 ; if Enter/Return key is pressed, move the
+
+ jsr nextline
+ jsr nextline
+ jsr delay1ms ; flush out SCI serial port
+ ; wait to finish sending last characters
+
+ ldx #0 ; Enter/Return key hit
+ stx ctr125u
+ jsr StartTimer6oc
+
+ CLI ; Interrupt enable, for Timer OC6 interrupt start
+
+
+loop1024
+ ldd ctr125u
+ cpd #DATAmax ; 1024 bytes will be sent, the receiver at Windows PC
+ bhs loopTxON ; will only take 1024 bytes.
+ bra loop1024 ; set Terminal Cache Size to 10000 lines, update from 1000 lines
+
+loopTxON
+ LDAA #%00000000
+ STAA TIE ; disable OC6 interrupt
+
+ jsr nextline
+ jsr nextline
+
+ ldx #msg5 ; print '> Done! Close Output file.'
+ jsr printmsg
+ jsr nextline
+
+ ldx #msg6 ; print '> Ready for next data transmission'
+ jsr printmsg
+ jsr nextline
+
+ BRA mloop2
+
+
+;subroutine section below
+
+;***********Timer OC6 interrupt service routine***************
+oc6isr
+ ldd #3000 ; 125usec with (24MHz/1 clock)
+ addd TC6H ; for next interrupt
+ std TC6H ;
+ bset TFLG1,%01000000 ; clear timer CH6 interrupt flag, not needed if fast clear enabled
+ ldd ctr125u
+ ldx ctr125u
+ inx ; update OC6 (125usec) interrupt counter
+ stx ctr125u
+ clra ; print ctr125u, only the last byte
+ jsr pnum10 ; to make the file RxData3.txt with exactly 1024 data
+oc2done RTI
+;***********end of Timer OC6 interrupt service routine********
+
+;***************StartTimer6oc************************
+;* Program: Start the timer interrupt, timer channel 6 output compare
+;* Input: Constants - channel 6 output compare, 125usec at 24MHz
+;* Output: None, only the timer interrupt
+;* Registers modified: D used and CCR modified
+;* Algorithm:
+; initialize TIOS, TIE, TSCR1, TSCR2, TC2H, and TFLG1
+;**********************************************
+StartTimer6oc
+ PSHD
+ LDAA #%01000000
+ STAA TIOS ; set CH6 Output Compare
+ STAA TIE ; set CH6 interrupt Enable
+ LDAA #%10000000 ; enable timer, Fast Flag Clear not set
+ STAA TSCR1
+ LDAA #%00000000 ; TOI Off, TCRE Off, TCLK = BCLK/1
+ STAA TSCR2 ; not needed if started from reset
+
+ LDD #3000 ; 125usec with (24MHz/1 clock)
+ ADDD TCNTH ; for first interrupt
+ STD TC6H ;
+
+ BSET TFLG1,%01000000 ; initial Timer CH6 interrupt flag Clear, not needed if fast clear set
+ LDAA #%01000000
+ STAA TIE ; set CH6 interrupt Enable
+ PULD
+ RTS
+;***************end of StartTimer2oc*****************
+
+
+;***********pnum10***************************
+;* Program: print a word (16bit) in decimal to SCI port
+;* Input: Register D contains a 16 bit number to print in decimal number
+;* Output: decimal number printed on the terminal connected to SCI port
+;*
+;* Registers modified: CCR
+;* Algorithm:
+; Keep divide number by 10 and keep the remainders
+; Then send it out to SCI port
+; Need memory location for counter CTR and buffer BUF(6 byte max)
+;**********************************************
+pnum10 pshd ;Save registers
+ pshx
+ pshy
+ clr CTR ; clear character count of an 8 bit number
+
+ ldy #BUF
+pnum10p1 ldx #10
+ idiv
+ beq pnum10p2
+ stab 1,y+
+ inc CTR
+ tfr x,d
+ bra pnum10p1
+
+pnum10p2 stab 1,y+
+ inc CTR
+;--------------------------------------
+
+pnum10p3 ldaa #$30
+ adda 1,-y
+ jsr putchar
+ dec CTR
+ bne pnum10p3
+ jsr nextline
+ puly
+ pulx
+ puld
+ rts
+;***********end of pnum10********************
+
+;***********printmsg***************************
+;* Program: Output character string to SCI port, print message
+;* Input: Register X points to ASCII characters in memory
+;* Output: message printed on the terminal connected to SCI port
+;*
+;* Registers modified: CCR
+;* Algorithm:
+; Pick up 1 byte from memory where X register is pointing
+; Send it out to SCI port
+; Update X register to point to the next byte
+; Repeat until the byte data $00 is encountered
+; (String is terminated with NULL=$00)
+;**********************************************
+NULL equ $00
+printmsg psha ;Save registers
+ pshx
+printmsgloop ldaa 1,X+ ;pick up an ASCII character from string
+ ; pointed by X register
+ ;then update the X register to point to
+ ; the next byte
+ cmpa #NULL
+ beq printmsgdone ;end of strint yet?
+ bsr putchar ;if not, print character and do next
+ bra printmsgloop
+printmsgdone pulx
+ pula
+ rts
+;***********end of printmsg********************
+
+;***************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****************
+
+;****************nextline**********************
+nextline
+ psha
+ ldaa #CR ; move the cursor to beginning of the line
+ jsr putchar ; Cariage Return/Enter key
+ ldaa #LF ; move the cursor to next line, Line Feed
+ jsr putchar
+ pula
+ rts
+;****************end of nextline***************
+
+;****************delay1ms**********************
+delay1ms: pshx
+ ldx #$1000 ; count down X, $8FFF may be more than 10ms
+d1msloop nop ; X <= X - 1
+ dex ; simple loop
+ bne d1msloop
+ pulx
+ rts
+;****************end of delay1ms***************
+
+msg3 DC.B '> Be sure to start saving Terminal data: open Output file = RxData3.txt', $00
+msg4 DC.B '> When ready, hit Enter/Return key for sawtooth wave, 1024 point print.', $00
+msg5 DC.B '> Done! You may close the Output file.', $00
+msg6 DC.B '> Ready for next data transmission, hit Enter key.', $00
+
+ END ; this is end of assembly source file
+ ; lines below are ignored - not assembled
+
diff --git a/cmpen472hw10_McDonnell/Sources/main.asm b/cmpen472hw10_McDonnell/Sources/main.asm
index 48b407b..5be05f0 100644
--- a/cmpen472hw10_McDonnell/Sources/main.asm
+++ b/cmpen472hw10_McDonnell/Sources/main.asm
@@ -59,6 +59,14 @@ CRGFLG EQU $0037 ; Clock and Reset Generator Flags
CRGINT EQU $0038 ; Clock and Reset Generator Interrupts
RTICTL EQU $003B ; Real Time Interrupt Control
+TIOS EQU $0040 ; Timer Input Capture (IC) or Output Compare (OC) select
+TIE EQU $004C ; Timer interrupt enable register
+TCNTH EQU $0044 ; Timer free runing main counter
+TSCR1 EQU $0046 ; Timer system control 1
+TSCR2 EQU $004D ; Timer system control 2
+TFLG1 EQU $004E ; Timer interrupt flag 1
+TC5H EQU $005A ; Timer channel 5 register
+
CR equ $0d ; carriage return, ASCII 'Return' key
LF equ $0a ; line feed, ASCII 'next line' character
NULL equ $00 ; NULL Terminator character
@@ -89,6 +97,7 @@ numBuf dc.b $0000 ; Used by ReadDecimal for reading number
operator dc.b $0000 ; Used by ReadDecimal for reading numbers
inputBuffer ds.b $0010 ; Input Buffer Length
+ dc.b NULL
lenInput dc.w $0010 ; Length of the Input Buffer
@@ -98,9 +107,13 @@ outputVal dc.b $00 ; Used to track the output value of the
outputCnt dc.w $0000 ; Used to track how many values have been outputted
-interval dc.w $3000 ; Used to set the timer module based on clock cycles
+interval dc.w 3000 ; Used to set the timer module based on clock cycles
+
+numPoints dc.w 2048 ; Max Number of points for waves
+
+timeTrigger dc.b $00 ; Tracks when timer is triggered
-waveType dc.b 'S' ; Used to track wave type 'T' for increasing triangle,
+waveType dc.b 'q' ; Used to track wave type 'T' for increasing triangle,
; 't' for decreasing triangle,
; 'Q' for square high
; 'q' for square low
@@ -115,10 +128,10 @@ waveType dc.b 'S' ; Used to track wave type 'T' for increa
dc.w rtiisr ; Real Time Interrupt vector
*
**************************************************************************
-* Timer Interrupt Vector Section: address used [ $FFE2 to $FFE3 ] RAM Memory
+* Timer Interrupt Vector Section: address used [ $FFE4 to $FFE5 ] RAM Memory
*
- org $FFE2 ; Timer channel 6 interrupt vector setup, on simulator
- dc.w oc6isr
+ org $FFE4 ; Timer channel 5 interrupt vector setup, on simulator
+ dc.w oc5isr
*
**************************************************************************
* Program Section: address used [ $3100 to $3FFF ] RAM Memory
@@ -146,34 +159,28 @@ pgstart lds #$3100 ; initialize the stack pointer
ldaa #$FF ; Two 7 segment displays on PORTB
staa DDRB ; Set all of PORTB as output
- ldx #inputBuffer ; Load the address of inputBuffer into X
- ldy lenInput ; Load the length of inputBuffer into Y
- jsr Zeros ; Zero out inputBuffer
cli ; Enable interrupts
- jsr PrintTime ; Jump to PrintTime to write to serial console
- ldx #spacer ; Load the address of spacer into X
- jsr WriteString ; Write the spacer string to the output
- jsr PrintPrompt ; Jump to PrintPrompt to write to serial console
mainLoop
ldx #inputBuffer ; Load the address of inputBuffer into X
ldy lenInput ; Load the length of inputBuffer into Y
jsr ReadString ; Jump to ReadString to read input
- ldx #inputBuffer ; Load the address of inputBuffer into X
- jsr ExecuteCommand ; Jump to ExecuteCommand
+ ldd #0 ; Clear D
+ std outputCnt ; Clear outputCnt
+ staa outputVal ; Clear outputVal
- ldx #inputBuffer ; Load the address of inputBuffer into X
- ldaa 0,x ; Load first character from inputBuffer into A
- beq mainLoop ; If A == 0, branch to mainLoop, only zero if Solve was called
- ldy lenInput ; Load the length of inputBuffer into Y
- jsr Zeros ; Zero out inputBuffer
+ jsr StartTimer5oc ; Start Timer on CH5
- sei ; Disable interrupts
- jsr PrintTime ; Jump to PrintTime to print new time
- ldx #spacer ; Load the address of spacer into X
- jsr WriteString ; Write the spacer string to the output
- jsr PrintPrompt ; Jump to PrintPrompt to write to serial console
- cli ; Enable interrupts
+looooop ldaa timeTrigger
+ beq looooop
+ clra
+ staa timeTrigger
+ jsr PrintWave ; Jump to PrintWave
+ ldd outputCnt
+ cpd numPoints
+ blo looooop
+
+ jsr StopTimerCH5
bra mainLoop ; Loop back to mainLoop always
@@ -212,6 +219,7 @@ twLoop jsr getchar ; Read a character from the serial conso
;
rtiisr bset CRGFLG,%10000000; Clear RTI Interrupt Flag
+ cli ; Enable interrupts
ldx counter ; Load counter into X
inx ; Increment counter by 1
stx counter ; Save X to counter
@@ -243,85 +251,151 @@ rtiisr bset CRGFLG,%10000000; Clear RTI Interrupt Flag
rtidone jsr PrintTime ; Jump to PrintTime
rtiSkip RTI ; Return from RTI ISR
-oc6isr ldd interval ; Load the interval for the next clock cycle
- addd TC6H ; for next interrupt
- std TC6H ;
+oc5isr ldd interval ; Load the interval for the next clock cycle
+ addd TC5H ; for next interrupt
+ std TC5H ;
+ bset TFLG1,%00100000 ; Clear CH5 interrupt flag
+ ldaa #1 ; Load 1 into A
+ staa timeTrigger ; Signal that timer went off
ldd outputCnt ; Load the count of values outputed into D
addd #1 ; Increase output count by 1
std outputCnt ; Update the count of outputted values
- cpd #2048 ; Compare D to the max number of values
- bne oc6Done ; If D != 2048, exit ISR
- ldd #0 ; Clear the D register
- std outputCnt ; Reset the count
- staa outputVal ; Reset the output value
- RTI ; Return from interrupt
-oc6Done jsr PrintWave ; Jump to PrintWave
- RTI ; Return from interrupt
+ cpd numPoints ; Compare D to numPoints
+ blo oc5Done ; If D < numPoints, Done
+ jsr StopTimerCH5 ; Stop Channel 5 Timer
+oc5Done RTI ; Return from interrupt
PrintWave
pshd ; Save D to the stack
+ pshy ; Save Y to the stack
ldaa waveType ; Load the waveType into A
cmpa #'T' ; Compare to 'T'
- beq TriangleInc ; If A == 'T', triangle wave increasing
+ lbeq TriangleInc ; If A == 'T', triangle wave increasing
cmpa #'t' ; Compare A to 't'
- beq TriangleDec ; If A == 't', triangle wave decreasing
+ lbeq TriangleDec ; If A == 't', triangle wave decreasing
cmpa #'Q' ; Compare A to 'Q'
- beq SquareWaveH ; If A == 'Q', square wave high
+ lbeq SquareWaveH ; If A == 'Q', square wave high
cmpa #'q' ; Compare A to 'q'
- beq SquareWaveL ; If A == 'q', square wave low
+ lbeq SquareWaveL ; If A == 'q', square wave low
SawToothWav clra ; Clear A
ldab outputVal ; Load the output value into B
+ ldy #buffer ; Load the address of buffer into Y
jsr PrintDecimalWord; Print the lower byte of the output value;
+ psha ; Save A to the stack
+ ldaa #CR ; Load CR into A
+ jsr putchar ; Write CR to serial console
+ ldaa #LF ; Load LF into A
+ jsr putchar ; Write LF to serial console
+ pula ; Restore A from the stack
addd #1 ; Increment output value by 1
cpd #256 ; Compare D to 256
- bne DonePrint ; If D != 256, Done
+ lbne DonePrint ; If D != 256, Done
clrb ; Reset to Zero
- bra DonePrint ; Branch to DonePrint
+ lbra DonePrint ; Branch to DonePrint
SquareWaveH clra ; Clear A
ldab #255 ; Load 255 into B
+ ldy #buffer ; Load the address of buffer into Y
jsr PrintDecimalWord; Print the lower byte of the output value;
+ psha ; Save A to the stack
+ ldaa #CR ; Load CR into A
+ jsr putchar ; Write CR to serial console
+ ldaa #LF ; Load LF into A
+ jsr putchar ; Write LF to serial console
+ pula ; Restore A from the stack
+ clra ; Clear A
ldab outputVal ; Load the output value into B
- addb #1 ; Add 1 to B
- cmpb #255 ; Compare B to 255
- bnq DonePrint ; If B != 255, done
+ addd #1 ; Add 1 to D
+ cpd #256 ; Compare D to 256
+ lbne DonePrint ; If D != 256, done
clrb ; Reset B to zero
ldaa #'q' ; Load 'q' into A
staa waveType ; Update wave type to square wave low
bra DonePrint ; Branch to DonePrint
SquareWaveL clra ; Clear A
clrb ; Reset B to zero
+ ldy #buffer ; Load the address of buffer into Y
jsr PrintDecimalWord; Print the lower byte of the output value;
+ psha ; Save A to the stack
+ ldaa #CR ; Load CR into A
+ jsr putchar ; Write CR to serial console
+ ldaa #LF ; Load LF into A
+ jsr putchar ; Write LF to serial console
+ pula ; Restore A from the stack
+ clra ; Clear A
ldab outputVal ; Load the output value into B
- addb #1 ; Add 1 to B
- cmpb #255 ; Compare B to 255
- bnq DonePrint ; If B != 255, done
+ addd #1 ; Add 1 to D
+ cpd #256 ; Compare D to 256
+ bne DonePrint ; If D != 256, done
clrb ; Reset B to zero
ldaa #'Q' ; Load 'Q' into A
staa waveType ; Update wave type to square wave low
bra DonePrint ; Branch to DonePrint
TriangleInc clra ; Clear A
ldab outputVal ; Load the output value into B
+ ldy #buffer ; Load the address of buffer into Y
jsr PrintDecimalWord; Print the lower byte of the output value;
+ psha ; Save A to the stack
+ ldaa #CR ; Load CR into A
+ jsr putchar ; Write CR to serial console
+ ldaa #LF ; Load LF into A
+ jsr putchar ; Write LF to serial console
+ pula ; Restore A from the stack
addd #1 ; Add 1 to D
cpd #256 ; Compare D to 256
bne DonePrint ; If D != 256, done
- subd #1 ; Subtract 1 from D
ldaa #'t' ; Load 't' into A
staa waveType ; Update wave type to decreasing triangle
+ subd #1 ; Subtract 1 from D
bra DonePrint ; Branch to DonePrint
TriangleDec clra ; Clear A
ldab outputVal ; Load the output value into B
+ ldy #buffer ; Load the address of buffer into Y
jsr PrintDecimalWord; Print the lower byte of the output value;
- cpd #0 ; Compare D to 0
- bne DonePrint ; If D != 0, done
+ psha ; Save A to the stack
+ ldaa #CR ; Load CR into A
+ jsr putchar ; Write CR to serial console
+ ldaa #LF ; Load LF into A
+ jsr putchar ; Write LF to serial console
+ pula ; Restore A from the stack
+ subd #1 ; Subtract 1 from D
+ cpd #$FFFF ; Compare D to $FFFF
+ bne DonePrint ; If D != $FFFF, done
ldaa #'T' ; Load 'T' into A
staa waveType ; Update wave type to increasing triangle
- bra DonePrint ; Branch to DonePrint
-TringleGood subd #1 ; Subtract 1 from D
+ clrb ; Clear B
DonePrint stab outputVal ; Store updated output value
+ puly ; Restore Y from the stack
puld ; Restore D from the stack
rts ; Return from Caller
+StartTimer5oc
+ PSHD
+ LDAA #%00100000
+ STAA TIOS ; set CH5 Output Compare
+ STAA TIE ; set CH5 interrupt Enable
+ LDAA #%10000000 ; enable timer, Fast Flag Clear not set
+ STAA TSCR1
+ LDAA #%00000000 ; TOI Off, TCRE Off, TCLK = BCLK/1
+ STAA TSCR2 ; not needed if started from reset
+
+ LDD #3000 ; 125usec with (24MHz/1 clock)
+ ADDD TCNTH ; for first interrupt
+ STD TC5H ;
+
+ BSET TFLG1,%00100000 ; initial Timer CH5 interrupt flag Clear, not needed if fast clear set
+ LDAA #%00100000
+ STAA TIE ; set CH5 interrupt Enable
+ PULD
+ RTS
+
+StopTimerCH5
+ psha ; Save A to the stack
+ clra ; Clear A
+ staa TIE ; Stop Timers
+ pula ; Restore A from the stack
+ rts ; Return
+
+
;*************************************************************************
; PrintTime subroutine
;