Microcontroller Simulator Task 7 - Electronics Tutorials

The AQA microcontroller contains a timer register called TMR.
This simulator memory-maps this register at address 0xFF.
There is also a prescaler register, PRE, memory-mapped at address 0xFE.

If PRE contains zero, TMR does nothing.
If PRE contains 10 (for example), on each clock pulse, a counter is incremented. When the counter reaches 10, one is subtracted from TMR and the counter reset to zero. This decrements TMR on every eleventh clock pulse.
If PRE contains some larger number, the counter counts from zero to this larger number and then subtracts one from TMR.
In this way, the clock frequency is divided by PRE + 1 and used to decrement TMR.

When TMR reaches zero, the TMR (T) flag is set and stays set until a non zero value is assigned to TMR.

TASK: Copy and paste this code into the simulator and run the program.
Note roughly how long it takes before the code controlled by the timer runs.
Modify this code by storing 8 into PRE.
Run the modified code and note that the timer counts far slower and the timer events are less frequent.

START:
; ===========================================
;       Initialise PRE and TMR
; ===========================================
        MOVW    0X1     ; Copy 1 into ...
        MOVWR   PRE     ; ... the prescaler
        MOVW    0X08    ; Copy 8 into ...
        MOVWR   TMR     ; ... the timer

; ===========================================
;       Poll the TMR flag (T)
; ===========================================
POLL:
        MOVRW   SR      ; Copy SR into W
        ANDW    0x02    ; Bit mask
        JPZ     POLL

; ============================================
; === This code runs when TMR reaches zero ===
; ============================================
        NOP
        NOP
        NOP
        NOP
        JMP     START
; ============================================

Topics:

01-nop-jmp   02-LEDs   03-Heater   03-Tlight   04-SevSeg   05-Delay   06-H-Bridge   07-Interrupts   08-Gray   09-Stepper   doc   hex-num   index  

Flash:

sim  

PDF:

Microcontroller Simulator  

DOC:

Microcontroller Simulator   Microcontroller Simulator.   Microcontroller with Harvard Architecture  

Images:

architecture   assem-H-Bridge   assem-Heater-FC   assem-Heater   assem-Stepper   assem-TLIGHT-grid   Gray   pinout   sim-leds   sim-sev-seg-design   sim-sev-seg   sim-traffic  

 

Privacy Policy, © Copyright, Contact Information and Disclaimers

Site highly rated by Schoolzone.co.uk

Valid XHTML 1.0 Transitional

Valid CSS!