Micro controller script
Transcript of Micro controller script
-
8/13/2019 Micro controller script
1/41
Peter Nauth
MicrocontrollerTechnology
Version 240512
-
8/13/2019 Micro controller script
2/41
Peter Nauth Microcontroller Technology
Seite 2 von 41
Basics in Digital Technology
Signed and unsigned numbers
Unsigned Numbers cover positive values,onlySigned Numbers: Negative values are chracteried by an MS! " 1
#$amplesunsigned : 1%%%1%%1b " 1&' signed: ( %111%111b " ( 11)
*i++erence: 1 ( '
!it-ise *i++erence Sum o+ Second./omplement
1%%11%11 1 1%%11%11( %%111%%1 ( ' 0 11%%%111
%11%%%1% ) 1 %11%%%1%
-
8/13/2019 Micro controller script
3/41
Peter Nauth Microcontroller Technology
Seite & von 41
Charac Hex Dec Charac Hex Dec Charac Hex Dec Charac Hex Dec
NU % % 2% &2 3 4% 4 5 % )
S67 1 1 8 21 && 9 41 a 1 )'
ST 2 2 ; 22 &4 ! 42 b 2 )
#T & & < 2& & / 4& ' c & ))
#6T 4 4 = 24 & * 44 d 4 1%%
#N> ? 2 &' # 4 ) e 1%1
9/@ A 2 & B 4 '% + 1%2
!# ' ' C 2' &) D 4' '1 g ' 1%&
!S E 2 4% 7 4 '2 h 1%4
79T ) ) F 2) 41 G 4) '& i ) 1%
B 9 1% H 29 42 I 49 '4 J 9 1%
KT ! 11 0 2! 4& @ 4! ' L ! 1%'
BB / 12 , 2/ 44 4/ ' l / 1%
/ * 1& . 2* 4 M 4* '' m * 1%)
S6 # 14 2# 4 N 4# ' n # 11%
SG B 1 O 2B 4' 6 4B ') o B 111
*# 1% 1 % &% 4 P % % p '% 112
*/1 11 1' 1 &1 4) > 1 1 '1 11&
*/2 12 1 2 &2 % 2 2 r '2 114
*/& 1& 1) & && 1 S & & s '& 11
*/4 14 2% 4 &4 2 T 4 4 t '4 11
N9@ 1 21 & & U u ' 11'
SQN 1 22 & 4 K v ' 11
#T! 1' 2& ' &' R ' ' - '' 11)
/9N 1 24 & $ ' 12%
#M 1) 2 ) &) ' Q ) ) y ') 121
SU! 19 2 : &9 9 )% '9 122
#S/ 1! 2' &! ) ! )1 V '! 12&
BS 1/ 2 W &/ % X / )2 Y '/ 124
DS 1* 2) " &* 1 Z * )& [ '* 12
S 1# &% \ 2 ] # )4 ^ '# 12
US 1B &1 _ &B & ` B ) 'B 12'
9S/GG./ode
/onversion o+ !inary Numbers to 7e$ Numbers by the rule:
4 binary digits correspond to 1 he$adecimal digit
#$ample: %1111111b " Bh
-
8/13/2019 Micro controller script
4/41
Peter Nauth Microcontroller Technology
Seite 4 von 41
9nalog andO or digitalelectronic circuit
Microcontroller
*ata Gnput
*ata Gnput *ata 6utput
*ata 6utput
7igh evelanguageSource /ode
9ssembly/ode
6bJect code Econsisting o+instruction bytes: operatorsand operandsF is stored inthe controller to be e$ecuted
Basics in Microcontroller Technology
*ata processing -ith electronic circuits cannot be adapted to ne- procedures -ithout changing the circuit
*ata processing -ith microcontroller can easily be adapted by changing the program -hich contains the dataprocessing procedure
Program code levels
*ata Processingaccording to a +i$ed
-ired procedure
*ata Processingaccording to a+le$ible and
adptable program
Program
/ompiler 9ssembly
/ompiler
-
8/13/2019 Micro controller script
5/41
Peter Nauth Microcontroller Technology
Seite von 41
*ataGnput O 6utput
/ontrol !us
*ata !us
!locL *iagram o+ a Microcomputer The Microprocessor EP, /PUF reads the Gnstruction !ytes o+ the he$codeEmachine codeF +rom the Memory 9 Microcomputer on a single chip is called a Microcontroller
/omponents o+ a Microprocessor EP, /PUF
P E/PUF Memory GO6
/locL
9dress !usSystem !us
/ontrol Unit
6theregisters
9LLu9U
Programm /ounter
Aress
9ddress o+ ne$t Gnstruction!yte
00
6perator !yte
6perand !yte
Data Bus
Control Bus
-
8/13/2019 Micro controller script
6/41
Peter Nauth Microcontroller Technology
Seite von 41
Gnstruction Processing
!nstruction rate
Gp MGPSZ "][
1
sTp %&: 1 MGPS E12 M7 /locLF
/: 12 MGPS E24 M7 /locLF
indicates, ho- many 610 9ssembly Gnstructions the processor can e$ecute in 1 sETp: Machine /ycle EM/F TimeF
C!"C : /omple$ Gnstruction Set /omputer Eeg %&, /F#!"C : educed Gnstruction Set /omputer
Microprocessor selects address o+ ne$tinstruction byte and puts it on address bus
Microprocessor activates the control signalPS#N -hich is connected -ith the controlinput 6# Eoutput enableF o+ the program
memory
Program memory puts instruction byte-hich is stored on the selected address to
the data bus
Microprocessor reads instruction byte +romdata bus
Microprocesser decodes instruction byte ande$ecutes it
-
8/13/2019 Micro controller script
7/41
Peter Nauth Microcontroller Technology
Seite ' von 41
Design o$ Microcontroller "yste%s &ith the "AB '0515( 5)5
Pin connections o+ the Micro./ontroller %1O &
*erivate o+ the %1 Micro./ontroller +amily
.!it /ontroller, /locL ma$ 1 M7, Gp " 1 MGPS at12 M7
' Ports available +or GO6 o+ *igital *ata EP% ( PF or 9nalog signals EPF
& Timer O /ounter
' e$ternal Gnterrupt Gnputs Ethrough the pins o+ Ports P1 und P&F
RorLing egister E% ( 'F at 4 egister banLs
Gnternal *ata Memory: 2 !yte, optional: #$ternal *ata Memory: 4 L!yte
#$ternal Program Memory: 4 L!yte
-
8/13/2019 Micro controller script
8/41
Peter Nauth Microcontroller Technology
Seite von 41
Connection o$ external %e%ory to '05)5 an *C''' Controller
atch#$ternal
ProgramMemory
4 L!yte
#$ternal
*ataMemory
4 L! te
Microcontroller
P2P%P&
6#
PS#N 9#
6#
R#
R *
Microprocessor P Gnternal *ata Memory
2 ! te
*!
*!
9*
9*
9ddress!us
*ata!us
-
8/13/2019 Micro controller script
9/41
Peter Nauth Microcontroller Technology
Seite ) von 41
Ti%ing Diagra% $or external Progra% Me%ory Access +'05)5,
S1P1 P2
S2P1 P2
S6P1 P2
S1P1 P2
S2P1 P2
S5P1 P2
S4P1 P2
S3P1 P2
Maschinenzyklus
StatesPhasen
ALE
PSEN
P0
P2
X X XAdr
L!"
Adr#i$h"
Adr#i$h"
AdrL!"
AdrL!"
Timing Diagramm
!nternal Data Me%ory
9ddress *ata
BBh StacL: Stores re.entry address and data
GB6, de+ault adress is %h
.\ StacLpointer SP points at adr %'h
%h Rrite: Gncrement
ead: *ecrement
/hange *e+ault: M6K SP,
-
8/13/2019 Micro controller script
10/41
Peter Nauth Microcontroller Technology
Seite 1% von 41
#egister Aresse Bitar3 unction De$ault
P B E/: )2F Qes Port BB
P`*G E/: )&F
! B% Qes !.egister %%
P4 # E/: /F Qes Port 4 BB
P4`*G E/: /)F
9// #% Qes 9.egister %%
P *! Port BB
*9P *9 9*/ %%
9**9T *) 9*/ *ata %%
9*/6N * Qes 9*/ /ontrol %%
PSR *% Qes Programm Status Rort %%
T72 /* Timer 2 7igh.!yte %%
T2 // Timer 2 o-.!yte %%
//7 /! // 7igh.!yte %%// /9 // o-.!yte %%
T2/6N / Qes Timer 2 /ontrol %%
//7& /' /ompareO/apture 7igh.!yte %%
//& / /ompareO/apture o-.!yte %%
//7& / /ompareO/apture 7igh.!yte %%
//2 /4 /ompareO/apture o-.!yte %%
//71 /& /ompareO/apture 7igh.!yte %%
//1 /2 /ompareO/apture o-.!yte %%
//#N /1 /ompareO/apture #nable.!yte %%
G/6N /% Qes Gnterrupt.euest./ontrol %%GP1 !) Gnterrupt.Priority.egister 1 %%
G#N1 ! Qes Gnterrupt.#nable.egister 1 %%
P& !% Qes Port & BB
GP% 9) Gnterrupt.Priority.egister % %%
G#N% 9 Qes Gnterrupt.#nable.egister % %%
P2 9% Qes Port 2 BB
S!UB )) Serieller Port !u++er Unde+iniert
S/6N ) Qes Serieller Port /ontrol %%
P1 )% Qes Port 1 BB
T71 * Timer 1 7igh.!yte %%
T7% / Timer % 7igh.!yte %%
T1 ! Timer 1 o-.!yte %%
T% 9 Timer % o-.!yte %%
TM6* ) Timer #instellung %%
T/6N Qes Timer /ontrol %%
P/6N ' Po-er /ontrol %%
*P7 & *ata Pointer E*PTF 7igh.!yte %%
*P 2 *ata Pointer E*PTF o-.!yte %%
SP 1 StacL Pointer %'
P% % Qes Port % BB
Special Bunction egister o+ %&
-
8/13/2019 Micro controller script
11/41
Peter Nauth Microcontroller Technology
Seite 11 von 41
P" +Progra% "tatus ort,
!itnumber !it ' !it !it !it 4 !it & !it 2 !it 1 !it %
Kalue 2' 2 2 24 2& 22 21 2%
Symb !itadr /Q 9/ B% S1 S% 6K B1 PPSR' PSR PSR PSR4 PSR& PSR2 PSR1 PSR%
Phys !itadr %*'h %*h %*h %*4h %*&h %*2h %*1h %*%h
C.!it The /arry.Blag indicates an over+lo- +or unsigned numbers Gt is set Eto 1F, i+ thecalculation o+ a sum or a di++erence e$ceeds the limit % % 2 E%%h % BBhF has beene$ceeded
9/.!it The 9u$illary./arry.Blag is set i+ the calculation o+ a sum or di++erence an over+lo-+rom !it & and !it 4 or vice versa occurred Gt is used by the instruction *9 9 +or a
!/* correctionB6 The Blag % can be used by the programmer
#"1 #"0 egister !anL Select /ontrol !its +or addresses o+ % ( '
% % egister !anL % activated, adresses %%h . %'h o+ internal *ata Memory
% 1 egister !anL 1 activated, adresses %h . %Bh o+ internal *ata Memory
1 % egister !anL 2 activated, adresses 1%h . 1'h o+ internal *ata Memory
1 1 egister !anL & activated, adresses 1h . 1Bh o+ internal *ata Memory
6K The 6ver+lo-.Blag indicates an over+lo- +or signed numbers Gt is set Eto 1F, i+ thecalculation o+ a sum or a di++erence e$ceeds the limit 12' % .12 E'Bh%%hF has beene$ceeded
B1 The Blag % can be used by the programmer
P The Parity.Blag is set Eto 1F i+ the sum o+ the bits % . ' o+ the 9.egister is odd
-
8/13/2019 Micro controller script
12/41
Peter Nauth Microcontroller Technology
Seite 12 von 41
"# Bit 6 Bit 7 Bit 5 Bit 4 Bit ) Bit 2 Bit 1 Bit 0
ADC8N !* /@ 9*# !SQ 9*M M2 M1 M%
P" /Q 9/ B% S1 S% 6K B1 P
T2C8N T2PS G&B G2B T21 T2% T2/M T2G1 T2G%
!#C8N #B2 TB2 G# G# G#& G#& G#2 G9*/
!9N1 ##N2 SR*T # # #4 # #2 #9*/
P) * R T1 T% GNT1 GNT% T$* $*
!9N0 #9 R*T #T2 #S #T1 #1 #T% #%
"C8N SM% SM1 SM2 #N T! ! TG G
P1 T2 /@6 T2# GNT2 GNT GNT GNT4 GNT&
TM8D D9T# /OT M1 M% D9T# /OT M1 M%
TC8N TB1 T1 TB% T% G#1 GT1 G#% GT%
PC8N SM6* P*S G*S . DB1 DB% P*# G*#
The most important Special.Bunction.egister and their symbolic !it 9dresses
Mini& Mdul 515
L'(& Anzei$e
Schal&ter
LE(
"uchsen "uchsen "uchsen
P1 P3
P6
Ein&) Aus$a*edi$italer +erte
,nterru-ts.i/er$ate
hler
*ernah/eanal$er +erte
Sensr
P5 P4P4
Anal$&tastatur
/ompnents o+ an Microcontroller System
/* @eybd
S-itch
/onnectrs
*igital GO6
/onnectrs/onnectrs
GnterruptsTimer Date
/ounter
9nalog GO6
Microcontroller
-
8/13/2019 Micro controller script
13/41
Peter Nauth Microcontroller Technology
Seite 1& von 41
Asse%-ly Progra%%ing o$ "AB '0515(5)5 an *C'''
"tructure o$ an asse%-ly instruction
Label: 6perator 6perand1, 6perand2, 6perand& ;comment*ata +lo- is +rom right to le+t ie +rom operand 2 and & to operand 1
Coy an arith%etic instructions
/opy Gnstructions:
M6K 6perand1, 6perand2 /opy data +rom 6perand2 to 6perand1eg:
M6K 9,
-
8/13/2019 Micro controller script
14/41
Peter Nauth Microcontroller Technology
Seite 14 von 41
9ddres *ata /omments Gnstruction < bytes
%% %% ' 6p./ode o+ M6K dadr,
-
8/13/2019 Micro controller script
15/41
Peter Nauth Microcontroller Technology
Seite 1 von 41
Unconditional Jump Instructions
'"m t% target a$$ress ith%"t e)"mti%ns*
+',- a$r16'"m t% the target a$$ress a$r16 l+a#el %r hsical a$ress!. In the instr"cti%n the%erat%r a$r16 can #e ritten as the la#el (sm#%lic a$$ress! %r the hsicala$$ress %/ the target
',- rel'"m # the relatie a$ress rel. In the instr"cti%n the %erat%r rel can #e rittenas the la#el (sm#%lic a$$ress! %/ the target %r the $i//erence %/ the targeta$$ress an$ the a$$ress a/ter the ',- instr"cti%n. The a$$ress $i//erence m"st
n%t e)cee$ 21384513.
Conditional Jump Instructions
'"m& i/ a c%n$iti%n has #een met. 7therise c%ntin"e ith the instr"cti%n/%ll%ing the '"m instr"cti%n
' rel'"m # the relatie a$$ress rel& i/ 9 :: 0
'N rel
'"m # the relatie a$$ress rel& i/ 9 ;:0
C'NE 9& $a$r& rel
'"m # the relatie a$$ress rel& i/ 9 ;:$a$r
D'N Rr& relDecrement Rr an$
-
8/13/2019 Micro controller script
16/41
Peter Nauth Microcontroller Technology
Seite 1 von 41
Loop Program: Write 0-9 to Adresses 20-29
R: M6K %,
-
8/13/2019 Micro controller script
17/41
Peter Nauth Microcontroller Technology
Seite 1' von 41
!nterruts
r$ 0003h
l/- ,S0
set* EAL
set* EX0
l- 77
77
77
l/- l-
,S0 77
77
reti
Pin 372
17 L!& Si$nal
an Pin 372 l8st
,nterru-t aus
27 9nter*rechun$
des Pr$ra//sund S-run$ zur
Adresse 3h
37 S-run$
zu ,S0
47 :cks-run$
und ;rtsetzun$
des Pr$ra//s
A*lau
-
8/13/2019 Micro controller script
18/41
Peter Nauth Microcontroller Technology
Seite 1 von 41
Ti%er Moe 1
1 bit Timer
Timer register is T76:T% E7igh byte in T7%, o- !yte in T%F
1 bit reload value T must be reloaded in T7% and T% by program
GS is called in an interval o+ TGS " E&. TFH&&ns
Ti%er Moe 2
bit Timer
Timer register is T%
bit reload value T is stored in T7%
eload is per+ormed automatically at over+lo-
GS is called in an interval o+ TGS " E2. T7%FH&&ns
.L0
.#0
> 255
? 255@1
elad
,nterru-tSericerutine
,S 0D !ird .L0 ede 1Es inkre/entiert BPrzessrtakt > 12 M#zD7
Setting o+ Timer /on+iguration done -ith SB TM6*
Set Timer % to Mode 2: M6K TM6*,
-
8/13/2019 Micro controller script
19/41
Peter Nauth Microcontroller Technology
Seite 1) von 41
Progra%%ing o$ Delays &ith Ti%er in Moe 2 -y %eans o$ !"#signals
=GN/U*# E#D/`liteGN/F
P6D S#DM#NT /6*# only i+ called by e$ternal program
PU!G/ Timer`*elay only i+ called by e$ternal program
/S#D 9T %$%%%! 9ddress GnterruptveLtor E" 6D %%%!h +or %& /ompilerF
IMP GS Iump to GS IMP GS is stored at address %$%%%!
S#D P6D only i+ called by e$ternal program
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
Timer`*elay:
M6K P4`*G,
-
8/13/2019 Micro controller script
20/41
Peter Nauth Microcontroller Technology
Seite 2% von 41
Meloy Progra%
P473
t.)2 .
P473
SAB 80515/ 535
'PL
P473
'PL
P473
Si$nalerlau<
-
8/13/2019 Micro controller script
21/41
Peter Nauth Microcontroller Technology
Seite 21 von 41
Start
F > .#
1 > .nln$e
6 > 131
eiterz8$erun$
(E' F
'PL P57F
F >> 0
F > .#
(E' 6
(E' 1
6 >> 0
1 >> 0
Ende
.n-r$ra// zur Entk--lun$ n .nh8he und .ndauer B.# >
.nh8henzahlD
Schlei
-
8/13/2019 Micro controller script
22/41
Peter Nauth Microcontroller Technology
Seite 22 von 41
"u-routines
/all o+ a subroutine: /9 srname
Structure o+ a subroutine :
srname: !egin o+ subroutine srname
#T #nd o+ subroutine srname
Ee.entry address +or bacL Jump to calling program is stored in the stacLF
Ta-le Calculation/ E#$ample: read &rddata o+ table @#NNF
@#NN: *! %1, %4, %), 1, 2 Table declaration
M6K *PT,
-
8/13/2019 Micro controller script
23/41
Peter Nauth Microcontroller Technology
Seite 2& von 41
*!: 9S/GG. character or control -ord
S: /ontrol mode ES " %F or *isplay mode ES " 1F
OR: Rrite mode EOR " %F or ead mode EOR " 1F#: Negative Slope e$ecutes display o+ character or control +unction,
-ait 1'%%s EcontrolF or 4%s EdisplayF -ait or until !B""%
/ontrol -ords: *! " %1h .\ /lear display, /ursor to1st column le+t*! " %h 0 n .\ /ursor to position n in 1st ro-*! " /%h 0 n .\ /ursor to position n in 2ndro-
/ontrol -ord 9S/GG char
-
8/13/2019 Micro controller script
24/41
Peter Nauth Microcontroller Technology
Seite 24 von 41
Connection lan *C''' 9xeri%ental Boar
-
8/13/2019 Micro controller script
25/41
Peter Nauth Microcontroller Technology
Seite 2 von 41
-
8/13/2019 Micro controller script
26/41
Peter Nauth Microcontroller Technology
Seite 2 von 41
!ntegrate De;elo%ent 9n;iron%ent +!D9,
-
8/13/2019 Micro controller script
27/41
Peter Nauth Microcontroller Technology
Seite 2' von 41
. In %r$er t% create a sim"lati%n an$ a har$are %rsace& clic %n Kset"/ile e)tensi%n 4.L
an$ create 3 %rsaces* im"lati%n an$ ,CTstem
-
8/13/2019 Micro controller script
28/41
Peter Nauth Microcontroller Technology
Seite 2 von 41
6. 7en K7ti%ns /%r Target MTarget 1ML /%r im"lati%n /irst an$ then& a/terhaing er/%rme$ the s"#se"ent stes& /%r ,CTstem an$ reeat thes"#se"ent stes
. et Target as /%ll%s
-
8/13/2019 Micro controller script
29/41
Peter Nauth Microcontroller Technology
Seite 2) von 41
8. et De#"g as /%ll%s
;%r im"lati%n O%rsace* 9ctiate KPse im"lat%rL;%r ,CTstem O%rsace* 9ctiate KIn/ine%n XC800 P+INQDrierL
-
8/13/2019 Micro controller script
30/41
Peter Nauth Microcontroller Technology
Seite &% von 41
. et Ptilities as %ll%s
&dit+ compile and run a program
1. 7en the relate$ r%
-
8/13/2019 Micro controller script
31/41
Peter Nauth Microcontroller Technology
Seite &1 von 41
. C%mile the r%gram an$ start the $e#"gger m%$"s
8. 9ctiate eriherials
. R"n the r%gram
-
8/13/2019 Micro controller script
32/41
Peter Nauth Microcontroller Technology
Seite &2 von 41
,eader "ile &.C///lite
?? Erstellt 300 %n O.Gr%te
? Uran/"rt? XC888 -r%cess%r?9=EN7+IT?? AVTE Register-H_DIR D9T9 0)C-H_D9T9 D9T9 0)C8-_DIR D9T9 0)B-_D9T9 D9T9 0)3
-H D9T9 0)C8- D9T9 0)3
TU0 D9T9 0)8CTU1 D9T9 0)8DT+0 D9T9 0)89T+1 D9T9 0)8A
T,7D D9T9 0)8C,C7N D9T9 0)A9
FF -%rt H
-H_0 AIT 0)C8?-H_1 AIT 0)C?-H_3 AIT 0)C9?-H_B AIT 0)CA?
-H_H AIT 0)CC?-H_ AIT 0)CD?-H_6 AIT 0)CE?-H_ AIT 0)C?
TR0 AIT 0)8C?ET0 AIT 0)9?E9 AIT 0)9?
RET7RE
-
8/13/2019 Micro controller script
33/41
Peter Nauth Microcontroller Technology
Seite && von 41
'051!nstruction =ist
Coy !nstructions
1nemonic 3te 1C 4lags 5p
M8V A>#r 1 1 - E82E
M8V A>ar 3 1 - E
M8V A>?#i 1 1 - E6&E
M8V A>@.onst' 3 1 - H
M8V #r>A 1 1 82
M8V #r>ar 3 3 9829
M8V #r>@.onst' 3 1 82
M8V ar>A 3 1
M8V ar>#r 3 3 8828
M8V ar>ar B 3 8
M8V ar>?#i 3 3 86&8
156 dadr+7konst/ B 3
M8V ?#i>A 1 1 6&
M8V ?#i>ar 3 3 96&9
M8V ?#i>@.onst' 3 1 6&
M8V DPT#>@.onst17 B 3 0
M8VC A>?ADPT# 1 3 B
M8VC A>?APC 1 3 - 8B
M8V* A>?#i 1 3 - E3&EB
M8V* A>?DPT# 1 3 - E0
M8V* ?#i>A 1 3 3&B
M8V* ?DPT#>A 1 3 0
P"H ar 3 3 C0
P8P ar 3 3 D0
*CH A>#r 1 1 - C82C
*CH A>ar 3 1 - C
*CH A>?#i 1 1 - C6&C
*CHD A>?#i 1 1 - D6&D
"AP A 1 1 CH
N8P 1 1 00
-
8/13/2019 Micro controller script
34/41
Peter Nauth Microcontroller Technology
Seite &4 von 41
Arith%eti. !nstructions1nemonic 3tes 1C 4lags 5p
ADD A>#r 1 1 CV&9C&7=&-
383
ADD A>ar 3 1 CV&9C&7=&-
3
ADD A>?#i 1 1 CV&9C&7=&-
36&3
ADD A>@.onst' 3 1 CV&9C&7=&-
3H
ADDC A>#r 1 1 CV&9C&7=&-
B8B
ADDC A> ar 3 1 CV&9C&7=&-
B
ADDC A> ?#i 1 1 CV&9C&7=&-
B6&B
ADDC A> @.onst' 3 1 CV&9C&7=&-
BH
"BB A>#r 1 1 CV&9C&7=&-
82
"BB A>ar 3 1 CV&9C&7=&-
"BB A>?#i 1 1 CV&9C&7=&-
6&
"BB A>@.onst' 3 1 CV&9C&7=&-
H
!NC A 1 1 - 0H
!NC #r 1 1 0820
!NC ar 3 1 0
!NC ?#i 1 1 06&0
!NC DPT# 1 3 9BD9C A 1 1 - 1H
D9C #r 1 1 1821
D9C ar 3 1 1
D9C ?#i 1 1 16&1
M= AB 1 H CV&7=&- 9H
D!V AB 1 H CV&7=&- 8H
DA A 1 1 CV DH
-
8/13/2019 Micro controller script
35/41
Peter Nauth Microcontroller Technology
Seite & von 41
=ogic !nstructions1nemonic 3tes 18 4lags 5p
AN= A>#r 1 1 - 82
AN= A>ar 3 1 -
AN= A>?#i 1 1 - 6&
AN= A>@.onst' 3 1 - HAN= ar>A 3 1 3
AN= ar>@.onst' B 3 B
8#= A>#r 1 1 - H82H
8#= A>ar 3 1 - H
8#= A>?#i 1 1 - H6&H
8#= A>@.onst' 3 1 - HH
8#= ar>A 3 1 H3
8#= ar>@.onst' B 3 HB
.L A+r 1 1 - 6826
*#= A>ar 3 1 - 6
*#= A>?#i 1 1 - 66&6*#= A>@.onst' 3 1 - 6H
*#= ar>A 3 1 63
*#= ar>@.onst' B 3 6B
C=# A 1 1 - EH
CP= A 1 1 - H
Bit Maniulation !nstructions
1nemonic 3tes 18 4lags 5p
C=# C 1 1 CV CB
C=# -ar 3 1 C3
"9TB C 1 1 CV DB
"9TB -ar 3 1 D3
CP= C 1 1 CV AB
CP= -ar 3 1 A3
AN= C>-ar 3 3 CV 83
AN= C>(-ar 3 3 CV 80
8#= C>-ar 3 3 CV 3
8#= C>(-ar 3 3 CV 90
M8V C>-ar 3 3 CV 93
156 adr+C 3 3 3
"hi$t !nstructions
1nemonic 3tes 18 4lags 5p
#= A 1 1 3B
#=C A 1 1 CV&- BB
## A 1 1 0B
##C A 1 1 CV&- 1B
-
8/13/2019 Micro controller script
36/41
Peter Nauth Microcontroller Technology
Seite & von 41
"u-routine !nstructions
1nemonic 3tes 18 4lags 5p
ACA== ar11 3 3 11
=CA== ar17 B 3 13
#9T 1 3 33
#9T! 1 3 B3
u% !nstructions
1nemonic 3tes 18 4lags 5p
AMP ar11 3 3 01
=MP ar17 B 3 03
"MP rel 3 3 80
MP ?ADPT# 1 3 B
: rel 3 3 60
N: rel 3 3 0C rel 3 3 H0
NC rel 3 3 0
B -ar> rel B 3 30
NB -ar>rel B 3 B0
BC -ar>rel B 3 10
CJ'& A+dadr+rel B 3 CV A
CN9 A>@.onst'>rel B 3 CV AH
CN9 #r>@.onst'>rel B 3 CV A82A
CN9 ?#i>@.onst'>rel B 3 CV A6&A
DN: #r>rel 3 3 D82D
DN: ar>rel B 3 D
A--ri;iations
9 2 9ccumulator
9/ 2 9u$iliary./arry.Blag
adr11 2 11.!it.9dress -ithin a 2.L!yte.Seite
adr1 2 1.!it.9dress
! 2 egister !
badr 2 !it.9dress
/Q 2 /arry.Blag
dadr 2 9ddress o+ the internal data memory
6K 2 6ver+lo-.Blag
P 2 Parity.Blag
rel 2 relativ .!it.6++set.9dress E(12 bis 012'F
i 2 egister E% or 1F
r 2 egister E% . 'F
? 2 abel +or indirect addressing
-
8/13/2019 Micro controller script
37/41
Peter Nauth Microcontroller Technology
Seite &' von 41
C- Programming
OOHHHHHHHHH /alculate P4 0 P and -rite the sum to P&HHHHHHHHHHHHOO
-
8/13/2019 Micro controller script
38/41
Peter Nauth Microcontroller Technology
Seite & von 41
C-5perators
Arith%etic 8erators
0 Sum. *i++erence
O *ivision
H Multiplication
? Modulo
.. *ecrement Epost and preF
00 Gncrement Epost and preF
Bit 8erators
A 9N*
Y 6
WW e+t shi+t
\\ ight shi+t
^ /omplement8 Negation Eresult is 1, i+ 6perand is % and vice verseF
Co%arison +use e3g3 as conitions in control structures,
"" eual
8" not eual
\ larger than
W smaller
\" larger or eual
W" smaller or eual
AA 9N*
YY 6
-
8/13/2019 Micro controller script
39/41
Peter Nauth Microcontroller Technology
Seite &) von 41
Assign%ents
" *irect assignment
H" 9ssignment o+ multiplication
O" 9ssignment o+ *ivision?" 9ssignment o+ Modulo
0" 9ssignment o+ 9ddition
." 9ssignment o+ Subtraction
WW" 9ssignment o+ e+t Shi+t
\\" 9ssignment o+ ight Shi+t
A" 9ssignment o+ 9N*
Y" 9ssignment o+ 6
]" 9ssignment o+ 6
Aress 8erators
A 9ddress o+
H Pointer to
-
8/13/2019 Micro controller script
40/41
Peter Nauth Microcontroller Technology
Seite 4% von 41
Data Tyes
char character or signed numbers E1 !yteFunsigned char unsigned numbers E1 !yteF
int signed numbers E2 !yteFunsigned int unsigned numbers E2 !yteF
Control "tructures
-hileEconditionFV
OO instructions e$ecuted continously as long as condition is True[
+orEi"% iWm i00F OOloop runs m timesV
OO instructions e$ecuted m times[
i+ EconditionFV
OO instructions e$ecuted once i+ condition is True[
-
8/13/2019 Micro controller script
41/41
Peter Nauth Microcontroller Technology
=iterature
Microcontrollers in PracticeSpringer Series in 9dvanced Microelectronics, Kol 1
Susnea, Goan, Mitescu, Marian
Springer Kerlag, 2%%
GS!N: )'.&.4%.2&%1.&
9xloring C $or Microcontrollers9 7ands on 9pproachParab, I, ShelaLe, KD, @amat, @, NaiL, DM
Springer Kerlag, 2%%'
GS!N )'.1.4%2%.%.&