Professional Documents
Culture Documents
Microcontroller Basics: Prof. Dr. Matthias Sturm
Microcontroller Basics: Prof. Dr. Matthias Sturm
CPU
MAB
Bus conv. MDB
V SCG1 SCG0 R9
OSCuniversal register
off CPUoff GIE N Z C
R10 universal register
R11 universal register
R12 universal register
R13 universal register
R14 universal register
R15 universal register
16 bit
unsigned 0
0000h
65535 FFFFh 0001h 1
signed 0
0000h
-1 FFFFh 0001h 1
V
8000h 7FFFh 32767
-32768
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
Flags
Z-Flag (zero)
set, if the result of a logic or arithmetic instruction is zero,
otherwise cleared.
N-Flag (negative)
set, if the result of a logic or arithmetic instruction is negative,
otherwise cleared.
The N-Flag is a copy of the most significant bit (MSB)
C-Flag (carry)
set, if the result of a logic or arithmetic instruction
produced a carry, otherwise cleared.
V-Flag (overflow)
set, if the result of an arithmetic instruction overflows
the signed variable range, otherwise cleared.
CPU
MAB
Bus conv. MDB
unused
03FFh
0200h 512 Byte RAM
01FFh
0100h 16 bit periphery
00FFh
0010h 8 bit periphery RAM
000Fh
0000h
special function register
The board
unused
03FFh
0200h 512 Byte RAM
01FFh
0100h 16 bit periphery
00FFh
0010h 8 bit periphery RAM
000Fh
0000h
special function register
CPU
MAB
Bus conv. MDB
fifty-one instructions
twenty-seven basic instructions RISC
twenty-four emulated instructions CISC
0 0 0
R11 universal register 0
R12 universal register
0 0 0
R13 universal register
1
0 0 R14 universal
0 register 2
R15 universal register
F F F 16 bit F
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
CPU register
special register universal register
V SCG1 SCG0 R9
OSCuniversal register
off CPUoff GIE N Z C
R10 universal register
Under different addressing modes:
R11 universal register
R12 universal register
0 0 0
R13 universal register
0
0 0 R14 universal
0 register 4
R15 universal register
0 0 0 16 bit 8
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
instruction set
V N Z C
ADD src, dst src+dst->dst * * * *
: : : :
: : : :
MOV src, dst src -> dst - - - -
Address
Orthogonality is, when Modes
Source
all instructions
with
Address
all address modes Modes
Destination
are valid for
all operands Instructions
Orthogonality in MSP430
Address
Modes
all single operand instructions use Source
all seven address modes.
and
Address
Modes
all double operand instructions use Destination
all seven source address modes and
Instructions
all four destination address modes Example: Orthogonality for two operand instructions
register mode
indexed mode
symbolic mode
absolute mode
indirect mode
immediate mode
ADD R7,R8 ; ( R7 ) + ( R8 ) ( R8 )
MOV R5,R6 ; ( R5 ) ( R6 )
CLR R5 ; #0 ( R5 )
This is the fastest addressing mode and needs the least memory .
The address of the operand is the sum of the index and the contents
of the register.
The indexed mode with index zero may used for indirect register
addressing of the destination operand.
The content of the words EDE / TONI is used for the operation.
The contents of the fixed addresses are used for the operation.
editor success?
no
yes
assembler
simulator
simulator
success?
debugger yes
no
hardware debugger
(monitor)
success?
no
yes
microcontroller basics end Prof. Dr. Matthias Sturm HTWK Leipzig
software development
.end
.end teminates assembly, should be the last source statement
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
programming techniques - stack and subroutines
CPU
MAB
Bus conv. MDB
mainprogram mainprogram
instruction A instruction A
instruction B CALL subroutine
instruction C instruction D
instruction D CALL subroutine
instruction B instruction E
instruction C CALL subroutine
instruction E instruction F
instruction B CALL subroutine
instruction C instruction G
instruction F subroutine
instruction B instruction B
instruction C instruction C
instruction G RETURN
main process
main process
main process
main process
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and subroutine
subroutine process
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
stack and data
before you save data on the stack you need to initiate the stack
by writing the stack address to the stack pointer (R1)
remember:
be careful not to demage addresses on the stack
avoid underflow and overflow of the stack
Conclusion
remember:
the stack location have to be RAM
the stack is growing to lower addresses
the stack pointer points to the latest used stack address
CPU
MAB
Bus conv. MDB
generally
An interrupt request (usually called an interrupt)
is generated by an interrupt source.
interrupt process
register area memory low address
stack
R3 constant register stack
R2 flag register stack stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register stack
R2 flag register stack stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register stack
R2 flag register stack stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register stack
R2 flag register stack stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register stack
R2 flag register stack stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register stack
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
interrupt process
register area memory low address
stack
R3 constant register flag register
R2 flag register instruction D address stack area
R1 stack pointer
R0 program counter MP instruction A
instruction B
instruction C
mainprogram
instruction D
interrupt sources instruction E JMP MP
int. source 1 / local enable ISR1 instruction X interrupt
instruction Y service routine 1
int. source 2 / local enable instruction Z RETI
ISR2 instruction U interrupt
interrupt logic instruction V
service routine 2
instruction W RETI
global interrupt enableGIE
interrupt vector ISR1 interrupt
hard wired
priority check interrupt vector ISR2 vector table
high address
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
interrupt
programming interrupts
program structure
initiate
main program
Priority falling
interrupt subroutine 1
instructions of the interrupt subroutine
end ISR with RETI instruction
Dont forget to
initiate the interrupt subroutine 2
interrupt instructions of the interrupt subroutine
vector table ! end ISR with RETI instruction
CPU
MAB
Bus conv. MDB
features
One crystal - no external components
stable processor frequency - no accumulating error
fast start up
ACLK
Auxiliary Clock
XOUT
FLL
PUC fMCLK = ( N + 1 ) * fACLK MCLK
Main System Clock
(fSystem)
+ Reset PUC
ACLK synchro- U/D
frequency integrator
:(N+1) nizer CLK 10 bit
- Enable
SCFI1 SCFI0
9 8 7 6 5 4 3 2
N 2 2 2 2 2 2 2 2 ... 21 20
modulator
M 26 25 24 23 22 21 20
SCFQCTL 5 5
OscOff, Control of
operation mode set interrupt flag FN_4 FN_3 FN_2 ...
SCG0, SCG1
in SFRs SCFI0
R2 status register
15 9 8 7 6 5 4 3 2 1 0
V SCG1 SCG0 OSCoff CPUoff GIE N Z C
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
system clock generator
CL
CBSEL1
Q0 Q1 CBSEL0
ACLK 0
1 XBUF
2
MCLK 3
CBE
program example
CPU
MAB
Bus conv. MDB
periphery register
unused
03FFh
0200h 512 Byte RAM
01FFh
0100h 16 bit periphery
00FFh
0010h 8 bit periphery RAM
000Fh
0000h
special function register
: :
0007h reserved
0006h reserved
0005h module enable 2 ME2.2
0004h module enable 1 ME1.1
0003h interrupt flag register 2 IFG2.x
0002h interrupt flag register 1 IFG1.x
0001h interrupt enable 2 IE2.x
0000h interrupt enable 1 IE1.x
03FFh
0200h 512 Byte RAM
01FFh
0100h 16 bit periphery
00FFh
0010h 8 bit periphery RAM
000Fh
0000h
special function register
: : :
0080h - 008Fh reserved
0070h - 007Fh USART register
0060h - 006Fh reserved
0050h - 005Fh system clock generator register
0040h - 004Fh basic timer, 8-Bit timer/counter, timer/port register
0030h - 003Fh LCD register
0020h - 002Fh digital I/O port P3 and P4 control register
0010h - 001Fh digital I/O port P0, P1 and P2 control register
03FFh
0200h 512 Byte RAM
01FFh
0100h 16 bit periphery
00FFh
0010h 8 bit periphery RAM
000Fh
0000h
special function register
: : :
0180h - 018Fh reserverd
0170h - 017Fh timer_A
0160h - 016Fh timer_A
0150h - 015Fh reserved
0140h - 014Fh reserved
0130h - 013Fh multiplier
0120h - 012Fh watchdog timer
0110h - 011Fh analog-to-digital converter
0100h - 010Fh reserved
03FFh
0200h 512 Byte RAM
01FFh
0100h 16 bit periphery
00FFh
0010h 8 bit periphery RAM
000Fh
0000h
special function register
CPU
MAB
Bus conv. MDB
features
P0.1 P0BIT.1
P0DIR.1
P0.2 P0BIT.2
P0DIR.2
P0.6 P0BIT.6
P0DIR.6
P0.7 P0BIT.7
P0DIR.7
P0DIR.x
P0.x
P0BIT.x
output buffer P0OUT.x
input P0IN.x
Pad logic
P0IES.x P0IFG.x
P0IRQ.x
P0IE.x
program example
TPD.4 TP.4
TPE.4
TPD.5 TP.5
TPE.5
program example
program example
CPU
MAB
Bus conv. MDB
EN1 EN2
BTCNT1 BTCNT2
ACLK CLK1 CLK2
Q4 Q5 Q6 Q7 Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7
IP2
FRFQ1
IP1
FRFQ0 SSEL DIV IP0
Set_Int._Flag
0
ACLK / 256 1
2
MCLK
3
fLCD
EN2
LCD data sheet
BTCNT2 fframing=100Hz..30Hz
CLK2
Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7
IP2 ACLK=32768Hz
IP1
IP0
Set_Int._Flag FRFQ:
fLCD=8x100Hz..8x30Hz
fLCD=800Hz..240Hz
select fLCD
64 32 16 8 4 2 1 0.5 ACLK / 256
1024Hz/512Hz/256Hz/128Hz
16384 8192 4096 2048 1024 512 256 128 ACLK
depends on MCLK MCLK
fLCD=256Hz
Interrupt frequency [Hz] CLK2 FRFQ1=1 / FRFQ2=0
program example
CPU
MAB
Bus conv. MDB
LCD Module
MSP430
Mux
Segment S29 / O29 / CMPI
Display
Mux
Memory
Output
15 i 8 bit
Mux S2 / O2
Control S1
Mux S0
COM3
Common COM2
LCD Control & Mode Output COM1
Basic Timer 1
Register Control COM0
Module
R33
Analog R23
Voltage R13
Multiplexer R03
fLCD Timing Generator
7 segment display
a segment n segment n+1
f g b
a
e c
h f g b
d
e c
h
d
4MUX mode
z COM0
A digit consists of seven
z COM1
segments driven from
z COM2
two segment and four
z COM3
common lines.
MDB BIT 7 6 5 4 3 2 1 0
Display memory, 4MUX drive COM 3 2 1 0 3 2 1 0
MAB 003Fh a b c h f g e d digit 15
segment n segment n+1 003Eh a b c h f g e d digit 14
003Dh a b c h f g e d digit 13
003Ch a b c h f g e d digit 12
a 003Bh a b c h f g e d digit 11
003Ah a b c h f g e d digit 10
f g b 0039h a b c h f g e d digit 9
0038h a b c h f g e d digit 8
e c
0037h a b c h f g e d digit 7
h 0036h a b c h f g e d digit 6
d
0035h a b c h f g e d digit 5
z COM0
0034h a b c h f g e d digit 4
z COM1
0033h a b c h f g e d digit 3
z COM2
0032h a b c h f g e d digit 2
z COM3
0031h a b c h f g e d digit 1
;STK/EVK LCD
a .equ 01h
LCD of the starter kit
a b .equ 02h MSP430
c .equ 10h
d .equ 04h
f g b e .equ 80h
z COM0 f .equ 20h
g .equ 08h
e c z COM1 h .equ 40h
h z COM2 ;--- character definitions
d z COM3
LCD_Tab .byte a+b+c+d+e+f ; displays "0"
.byte b+c ; displays "1"
MDB BIT 7 6 5 4 3 2 1 0 .byte a+b+d+e+g ; displays "2"
.byte a+b+c+d+g ; displays "3"
COM 3 2 1 0 3 2 1 0 .byte b+c+f+g ; displays "4"
MAB 0037h e h f c g d b a digit 7 .byte a+c+d+f+g ; displays "5"
.byte a+c+d+e+f+g ; displays "6"
0036h e h f c g d b a digit 6 .byte a+b+c ; displays "7"
.byte a+b+c+d+e+f+g ; displays "8"
0035h e h f c g d b a digit 5 .byte a+b+c+d+f+g ; displays "9"
.byte a+b+c+e+f+g ; displays "A"
0034h e h f c g d b a digit 4 .byte c+d+e+f+g ; displays "B" b
0033h e h f c g d b a digit 3 .byte a+d+e+f ; displays "C"
.byte b+c+d+e+g ; displays "D" d
0032h e h f c g d b a digit 2 .byte a+d+e+f+g ; displays "E"
.byte a+e+f+g ; displays "F"
0031h e h f c g d b a digit 1
microcontroller basics segm. n segm. n+1 Prof. Dr. Matthias Sturm HTWK Leipzig
LCD driver module
program example
mov.b #0FFh,&LCDCTL ; set up LCD driver
mov #0008h,R7 ; clear display
LOOP clr.b LCDM-1(R7)
dec R7
jnz LOOP
MAIN mov &NUMBER,R6 ; load value of NUMBER in R6
clr R7 ; register R7 := 00h
PRINT mov R6,R8 ; move R6 to R8
and #000Fh,R8 ; keep lower 4 bits
mov.b LCD_Tab(R8),LCDM(R7) ; display digit on LCD
rra R6 ; rotate right four times
rra R6
rra R6
rra R6
inc R7
cmp #04h,R7 ; all 4 digits one
jne PRINT ; no -> go to next digit
nop
CPU
MAB
Bus conv. MDB
features
AVCC ACTL1
ACTL12
SVCC
128
Capacitor ARRAY
delay
Resistor Decode
D ADCLK/12
0.75 * SVCC : 12
Range MUX
128
Rext
C
ACTL8 128
B ADCLK
ACTL6
128
Current MUX ACTL7
A SVCC :1
ACTL10
2 :2
ACTL9
AVSS MCLK
:3
7 2 5 :4
A0
ACTL 13
ACTL 14
A1 analog
A2
Input MUX
MSP430 ACTL0
A3
x32x ACTL2 ACTL11
A4 Successive Approximation
ACTL3 ACTL10 Int. flag
A5 Register
ACTL4 ACTL9
A6
ACTL5
A7
ACTL14
ACTL13
ACTL12
ACTL11
ACTL10
ACTL9
ACTL8
ACTL7
ACTL6
ACTL5
ACTL4
ACTL3
ACTL2
ACTL1
ACTL0
digital
8 8 16 16
MDB, 16 bit
A1 MSP430x325
R2
AVSS
SVCC
R1
Ri
A1 MSP430x325
R2
AVSS
N = 214 * 0.25 * R1 / R2 DVSS DVCC AVCC
A1 MSP430x325
Analog
input
AVSS
SVCC ~ AVCC DVSS DVCC AVCC
SVCC switch closed
A1 MSP430x325
Analog
input
0 < SVCC < AVCC AVSS
program example
configures the ADC and works as converter
CPU
MAB
Bus conv. MDB
features
three major functions
serial communication or data exchange
pulse counting or pulse accumulation
timer
three register used for control
T/C control register TCCTL 0042h
pre-load register TCPLD 0043h
counter register TCDAT 0044h
P0.1 or counter interrupt flag P0IFG IFG1.3 0002h
P0.1 or counter interrupt enable P0IE.1 IE1.3 0000h
P0.1 interrupt edge select P0IES.1 P0IES 0014h
P0IES.1
P0.1 ISCTL P0IE.1 Interrupt
0
0 request
Set IRQP0.1
interrupt logic 1
1 Q
IRQA Clear
P0.1 and 8bit T/C
8
0
TXE
SSEL1
ENCNT
RXD
MCLK 1
TXD
SSEL0
RXACT
Q0 ...Q7
ISCTL
2 CLK2 Counter
ACLK 3 TCDAT
EN Load RC
counter, preload
and control register
'Write' to TCDAT
TXD
P0OUT.2
+
P0DIR.2
D Q D Q
TXE
Clear ENCNT Set
RXACT TXD_FF
PUC
D Q RXD Output P0.2
serial communication Set
control
support RXD_FF
PUC
LSB MSB
high
D0 D1 D2 D3 D4 D5 D6 D7
low
CPU
MAB
Bus conv. MDB
features
CIN
Control Register
0 CMP
Enable TPSSEL0 TPCTL
1 TPIN.5 Set_EN1FG
CMPI Control
RC2FG
RC1FG
EN1
TPSEL1
TPSEL0
EN1FG
ENB
ENA
ENB ENA
VCC/4 CPON
TPSSEL1 TPSSEL0
EN1
CMP 0
CLK1
TP.0 TPD.0 ACLK 1 Data Register
MCLK 2 RC1 TPD
TPE.0
3
B16
TPD.5
TPD.4
TPD.3
TPD.2
TPD.1
TPD.0
CPON
TP.1 TPD.1
Set_RC1FG
TPE.1 B16
TPIN.5
TP.2 TPD.2
TPSSEL3 TPSSEL2
TPE.2
TPIN.5 0
TP.3 TPD.3
ACLK 1
EN2
TPE.3 MCLK 2 Data Enable Register
3 CLK2 TPE
TP.4 TPD.4
RC2
TPE.5
TPE.4
TPE.3
TPE.2
TPE.1
TPE.0
TPSEL3
TPSEL2
TPE.4
TP.5 TPD.5
Set_RC2FG
TPE.5
Timer/Port
program example
pulse with measurement with timer / port
mov.b #060h,&TPCTL ; set clock for TPCNT1 enable TPCNT1 with TP.5-IN
mov.b #00h,&TPE ; disable outputs
mov.b #080h,&TPD ; select 16-bit mode
clr.b &TPCNT2 ; set timer start values
clr.b &TPCNT1
bis.b #TPIE,&IE2 ; enable Timer/Port interrupt
eint ; global interrupt enable
MAIN jmp MAIN ; infinite loop
CPU
MAB
Bus conv. MDB
features
CNTCL VCC
PUC
HOLD
SSEL Power-up
EN Clear
Circuitry
MCLK 0 ____
CLK 16-bit Counter RST/NMI
POR
ACLK 1
Q6 Q9 Q13 Q15
NMI
IS1
IS0 TMSEL
3 2 1 0 WDTQn PUC
S Resetwd1
WDTIFG
IFG1.0 Clear EQU
POR Resetwd2
IRQA
IRQ
IRQ: Interrupt Request TMSEL
IRQA: Interrupt Request Accepted WDTIE
power-on reset POR and
IE1.0 Clear
timer/counter and power-up clear PUC
PUC
interrupt logic logic
Password (5Ah)
Password (69h)
microcontroller basics Prof. Dr. Matthias Sturm HTWK Leipzig
watchdog timer module
program example
Price CPU,
H/W MPY with LCD
USART, driver
Timer_A
CPU, Timer/Port x330
A/D converter
Timer/Port
x320
CPU,
Timer/Port
x310
without LCD
driver
More to come
x11x
Complexity
CPU
Timer
Power FLL ROM RAM MUL Watch
A
JTAG
MAB
Bus conv. MDB
microcontroller basics
a description based on TIs MSP430