#define AxiomEVB ;comment this out if not Axiom EVBU * Lab7c.asm * Mike Dawdy * The A-D Subsystem * Program Lab7a reads an analog voltage from PortE bit 3 and displays * the units value of the voltage on a 7 segment display * Program Lab7b additionally uses PortA bit 7 and TO to program the * dot on the 7-segment display as a 1 second iso-phase flashing light * Program Lab7c additionally uses TO instead of the delay loop, and SCAN=1 * The Axiom EVBU does not have a port replacement unit [PRU], * so this program uses PortA bits 6:4 and PortD bits 5:2 * instead of PortB bits 6:0 as called for in the assignment * PB6 PB5 PB4 PB3 PB2 PB1 PB0 * PA7 PA6 PA5 PA4 PD5 PD4 PD3 PD2 * 5 . 10g 9 f 1 e 2 d 4 c 6 b 7 a * This program avoids using bits 1:0 of PortD as their * alternate use is TxD and RxD for the async serial comm * interface, and this is used by Buffalo #ifdef AxiomEVB Program equ $2000 ;for Axiom EVBU #else Program equ $c000 ;for Motorola EVB #endif Data equ $0000 Registers equ $1000 ;indexed addressing mode for registers PortA equ $00 ;Port A register PortD equ $08 ;Port D register DDRD equ $09 ;Port D Data Direction register PortE equ $0a ;Port E register TMsk2 equ $24 ;Timer Interrupt Mask 2 register TFlg2 equ $25 ;Timer Interrupt Flag 2 register PACtl equ $26 ;Pulse Accumulator Control register ADCtl equ $30 ;A/D Control/Status Register ADR1 equ $31 ;A/D Result Register Option equ $39 ;System Configuration Options Register ms1000 equ %11100001 ;31 counts of 32.77 ms ~= 1 second org Data TO_Counter ds.b 1 ;decrement FRC overflows here org Program * 1. Initialization section: once-only code ldx #Registers ;set IX pointing to $1000 registers bset Option,X,#%10000000 ;set ADPU=1: power up & enable AD sys bset ADCtl,X,#%00100011 ;CB=CA=1, SCAN=1 => conv PE3 continuous bset DDRD,X,#%00111100 ;set data direction for PD 5:2 to output bset PACtl,X,#%10000000 ;set data direction for PA7 to output * set up for interrupts from TO ldy #TO_ISR ;EVB int vect for TO sty $00d1 ldaa #ms1000 ;init for 1st 1 second interval staa TO_Counter bclr TFlg2,X,%01111111 ;clear any pending interrupt on TO bset TMsk2,X,%10000000 ;enable TO interrupt cli * 2. Main Program Loop Loop wai bra Loop * 3. Constant Data Segment for main program Segments dc.b $40,$79,$24,$30,$19,$12,$03,$78,$00,$10 ;bit = 0 turns segment on * 4. Timer Overflow Interrupt Service Routine * come to here after each 32.77 ms FRC overflow TO_ISR ldx #Registers bclr TFlg2,X,%01111111 ;clear the interrupt on TO clra ;load AccD with result/Dividend ldab ADR1,X ldx #$33 ;divide by $33 = !51 idiv xgdx ;AccD <- Quotient ldx #Registers ;restore IX ldy #Segments ;begin of segments table aby ;addemup ldaa PortA,X ;select wanted 7-segment code ... anda #%10000000 ; ... while preserving PA7 oraa 0,Y staa PortA,X ;PortA bits 7:4 lsla ;[here we are avoiding ... lsla ; ... PortD bits 1:0] staa PortD,X ;PortD bits 5:2 inc TO_Counter ;increment counter and ... bne TO_Exit ; ... exit if no roll over ldaa PortA,X ;invert PortA bit 7 for eora #%10000000 ;isophase flashing dot staa PortA,X ldaa #ms1000 ;init for next 1 second interval staa TO_Counter TO_Exit rti