Professional Documents
Culture Documents
ECE3620Unit 8
ECE3620Unit 8
Introduction to Microcomputers
1
Course Topics
Unit Topic Duration
(weeks)
1 Microcomputer Execution of Assembly Programs: A Brief 1
Overview
2 Instructions, Addressing Modes, Data Representation, 2
Arithmetic and Logic, Branching, and Simple Assembly
Programs
3 68HC11 Assembly Programming and Development Tools 2
4 Stacks, Subroutines and Data Structures 2
5 The Hardware Configuration and Interrupts 1
EXTAL
CPU Core
XTAL
Timer &
counter system
Port A
68HC11
(TCNTL)
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 $100F
Incremented @ every tick of the E clock (cannot 216 = 65,536 counts to cycle it around
writtenAlways
Note: read TCNT as a 16-bit number using once
by the program) LDD,i.e.,
LDX, or LDY $100E
@ 2 MHz, 65536 * 0.5 µs = 32.768 ms
instruction; Reading 8-bit portions separately gives erroneous results. When
Higher bytes are read, the counter freezes the lower byte of the register. This
assures the results are always read in two bytes and are correct
© 2016, Macam, Introduction to Microcomputers 12
The Free Running Counter
Note: The returned count value on a double-byte read corresponds
to the value of the free running counter at the second-to-last cycle
of the double-byte read instruction.
TCNTH $01
$02 $FD
$FC
$FE
$FF
$00 TCNTL
$100E $100F
D Register
$01FF
Read High-byte into D
register, Low-byte is
Note: The TCNT is incremented by 1 after E cycle 5 i.e., after
frozen
LDD instruction
This means if you use
this, ACCA = $01 and Note: The TCNT still reflects the exact
ACCB = $FF number of E clock ticks; so, TCNT has $0200
after LDD
© 2016, Macam, Introduction to Microcomputers 14
The Free Running Counter
• Solution: First Segment
– Recall: The lower byte of the TCNT register is
frozen when higher byte is being read in a 16-bit
read of the TCNT register
– In extended mode, LDD requires 5 cycles
– Loads the high byte in the 4th cycle
– At the 4th cycle, TCNT = $01FF
• This value is frozen and read into D register
• So, ACCA gets $01 and ACCB gets $FF
• Note: The TCNT still reflects the exact number of E
clock ticks; so, TCNT has $0200 after LDD
Adds 5 ms to D
register
• Solution:
– Also, the real-time interrupt vector starting
address should be pointed to by a JMP instruction
placed at $00EB
– This routine must clear the RTIF flag before it
returns.
– The following program meets our objectives:
Flag bits
• NOTE:
– When you run a program that terminates with a
SWI on the simulator, you can replace SWI with
the “loop in place” instruction “BRA *”
– The SWI is a software interrupt that attempts to
run a routine whose default starting address
($FFFF) is stored at $FFF6, $FFF7
• NOTE:
– Edit locations $FFF6 and $FFF7 and write the two
bytes $C0 and $04 in those locations, respectively
– This results in a program that keeps re-running
itself if the program actually starts at $C004
– Alternatively, for the above program, you may
append it with the following code:
ORG $FFF6
FCB $C0,$04
Flag bits
© 2016, Macam, Introduction to Microcomputers 69
68HC11: Output Compare Function
• When the number in the TOC register equals the
number in TCNT
– The flag will set in TFLG1
– This could in turn (settings of register TCTL1) affect
the logic level at the Port A pin associated with that
particular output compare
– If the corresponding bit is set in TMSK1, a compare
will cause an interrupt
– Upon RESET, the TMSK1 register is reset to $00
– Therefore, output compare interrupts are disabled upon RESET
– Have to set the desired bits in TMSK1 to allow output compare
interrupts
PACTL ($1026)
DDRA7 PAEN PAMOD PEDGE DDRA3 I4/O5 RTR1 RTR0
7 1 1 Bit 4 1 Bit 2 Bit 1 Bit 0
PACTL ($1026)
DDRA7 PAEN PAMOD PEDGE DDRA3 I4/O5 RTR1 RTR0
7 1 1 1 1 Bit 2 Bit 1 Bit 0
ORG $C000
LDAA #$40
STAA PACTL
CLR PACNT
CLR PORTB
GO LDAA PACNT
STAA PORTB
BRA GO
© 2016, Macam, Introduction to Microcomputers 92
68HC11: Pulse Accumulator
• The pulse accumulator (PA)
– Associated with two flags in the TFLG2 register
• PAIF (Pulse Accumulator Input Flag)
– Is set whenever the PA is active and a selected edge on PA7 is
detected.
• The PAOVF (Pulse Accumulator Overflow Flag)
– Is set whenever the count in PACNT rolls over from $FF to $00
• both flags are cleared by writing 1s into their bit
positions in TFLG2