SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- ; University of Illinois at Chicago, Dept. of Electrical and Computer Engineering
- ; ECE 367 -Microprocessor-Based Design
- ; Three Bit Counter
- ; Version 2, Aug 27, 2011
- ; By Robert A. Becker
- ; PAY ATTENTION TO THE ALIGNMENT BELOW
- ; Labels start in the first column (left most column = colunm 1)
- ; OP CODES are at column 9
- ; COMMENTS follow a ";" symbol
- ; Blank lines are allowed (Makes the code more readable)
- ; Define symbolic constants
- PortT EQU $240 ;Define Register Locations
- DDRT EQU $242
- INITRG EQU $11
- INITRM EQU $10
- CLKSEL EQU $39
- PLLCTL EQU $3A
- CRGFLG EQU $37
- SYNR EQU $34
- REFDV EQU $35
- COPCTL EQU $3C
- TSCR1 EQU $46
- TSCR2 EQU $4D
- TIOS EQU $40
- TCNT EQU $44
- PortM EQU $250
- DDRM EQU $252
- SAVE EQU $60 ;created a variable to save my increment register because delay sub routine changes it.
- TENSAVE EQU $5020
- TC0 EQU $50
- TFLG1 EQU $4E
- ;
- ; The ORG statment below would normally be followed by variable definitions
- ; There are no variables needed for this project.
- ; THIS IS THE BEGINNING SETUP CODE
- ;
- ORG $3800 ; Beginning of RAM for Variables
- ;
- ; The main code begins here. Note the START Label
- ;
- ORG $4000 ; Beginning of Flash EEPROM
- START LDS #$3FCE ; Top of the Stack
- SEI ; Turn Off Interrupts
- MOVB #$00, INITRG ; I/O and Control Registers Start at $0000
- MOVB #$39, INITRM ; RAM ends at $3FFF
- ;
- ; We Need To Set Up The PLL So that the E-Clock = 24MHz
- ;
- BCLR CLKSEL,$80 ; disengage PLL from system
- BSET PLLCTL,$40 ; turn on PLL
- MOVB #$2,SYNR ; set PLL multiplier
- MOVB #$0,REFDV ; set PLL divider
- NOP ; No OP
- NOP ; NO OP
- PLP BRCLR CRGFLG,$08,PLP ; while (!(crg.crgflg.bit.lock==1))
- BSET CLKSEL,$80 ; engage PLL
- ;
- ;
- ;
- CLI ; Turn ON Interrupts
- ;
- ; End of setup code. You will always need the above setup code for every experiment
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;START CODING HERE____________________________________________________
- LDAA #$FF ; Make PortT Outbound
- STAA DDRT
- LDAA #$FB ; make pm2 inbound but rest outbound
- STAA DDRM
- LDAA #$3f
- STAA PortT
- LDAA #$03
- STAA PortM
- LDAA #$00
- STAA TENSAVE
- STAA PortM
- THIS:
- BRSET SAVE, #$0A, TEN ; Branch to 'TEN' if save variable is incremented all the way to $10
- LDAB #$00
- HERE: BRSET PortM, #$04, HERE ; Branch if PM2 is SET (1) to HERE
- ;
- ; JSR DELAY
- JSR DISPLAY
- BRA HERE
- BRA *
- ; LDAB #$00 ;initialize acc B to 0 to begin count in table
- ; JSR DISPLAY ;jump to sub routine 'display'
- ;THIS: ;loop branch statement takes you here
- JSR DELAY
- ;
- ; We use some built-in timer functions to create an accurate delay
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;------------------------------------------------
- ;GIVEN DELAY SUBROUTINE
- DELAY PSHA ; Save accumulator A on the stack
- LDY #03 ; We will repeat this subroutine 3 times
- MOVB #$90,TSCR1 ; enable TCNT & fast flags clear
- MOVB #$06,TSCR2 ; configure prescale factor to 64
- MOVB #$01,TIOS ; enable OC0
- LDD TCNT ; Get current TCNT value
- AGAIN ADDD #37500 ; start an output compare operation
- STD TC0 ; with 100 ms time delay
- WAIT BRCLR TFLG1,$01,WAIT ; Wait for TCNT to catch up
- LDD TC0 ; Get the value in TC0
- DBNE Y,AGAIN ; 5 X 100ms = 1 sec
- PULA ; Pull A
- RTS ;
- ;___________________________________________________________
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;_____________________________________________________________
- ;displaylab3
- DISPLAY:
- LDAA #$00
- STAA PortM, Y
- LDAB SAVE
- LDX #TABLE ;load table into x
- LDAA B,X ;load b'th element of table into a
- STAA PortT,Y ;display a in port t
- INCB ;increment b for next run through loop
- LDAA #$01 ;load bth element of table into a
- STAA PortM,Y ;display a in port m
- ;
- STAB SAVE ;save b in variable save before delay
- ;
- JSR DELAY ;Keep display on for a second with current uin digit
- JSR DELAY
- LDAB SAVE ;transfer variable back into incrementing accumulator
- BRSET SAVE, #$0A, THIS ; Branch to 'this' if save variable is incremented all the way to $10,
- RTS
- ;__________________________________________________________________________
- TEN
- LDAA #$00
- STAA PortM, Y
- LDAB TENSAVE
- LDX #TABLE
- LDAA B, X
- STAA PortT, Y
- INCB
- STAB TENSAVE
- LDAA #$02
- STAA PortM, Y
- LDAB #$00
- STAB SAVE
- RTS
- ; End of counter code
- ;DISPLAY
- ;DISPLAY:
- ; LDX #TABLE ;load table into x
- ; LDAA B,X ;load b'th element of table into a
- ; STAA PortT,Y ;display a in port t
- ; INCB ;increment b for next run through loop
- ; LDAA B,X ;load bth element of table into a
- ; STAA PortM,Y ;display a in port m
- ;
- ; STAB SAVE ;save b in variable save before delay
- ;
- ; JSR DELAY ;Keep display on for a second with current uin digit
- ; JSR DELAY
- ; LDAB SAVE ;transfer variable back into incrementing accumulator
- ;
- ; LDAA #$00
- ; STAA PortT,Y ;turn display off at the end of the program
- ; STAA PortM,Y ;turn port m display off for break between uin units
- ;
- ;STAB SAVE
- ;JSR DELAY ;Keep off for half second
- ;LDAB SAVE
- ; INCB; ;increment b again to get to next table entry
- ; STAB SAVE
- ; BRSET SAVE, #$12, THIS ; Branch to 'this' if save variable is incremented all the way to $12,
- ; JSR DISPLAY ;back to the top of the loop
- ;table for uin
- ORG $5000 ;memory location of table
- TABLE: DC.B $06, $5b, $4f, $66, $6d, $7D, $07, $7F, $67, $3f
- ;define table
- ; Define Power-On Reset Interrupt Vector
- ; AGAIN - OP CODES are at column 9
- ORG $FFFE ; $FFFE, $FFFF = Power-On Reset Int. Vector Location
- FDB START ; Specify instruction to execute on power up
- ; End of Interrupt code
- END ; (Optional) End of source code
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.