Documente Academic
Documente Profesional
Documente Cultură
Microcontroller Technology
Version 240512
Peter Nauth
Microcontroller Technology
Unsigned Numbers cover positive values,only Signed Numbers: Negative values are chracteri ed by an MS! " 1 #$amples unsigned : 1%%%1%%1b " 1&' *i++erence: 1,, ( ,' !it-ise *i++erence 1%%11%11 ( %%111%%1 %11%%%1% Sum o+ Second./omplement 1,, ( ,' )1 1%%11%11 0 11%%%111 1 %11%%%1% signed: ( %111%111b " ( 11)
Seite 2 von 41
Peter Nauth
Microcontroller Technology
Charac Hex NU2 S67 ST: #:T #6T #N> 9/@ !#2 !S 79T 2B KT BB /M S6 SG *2# */1 */2 */& */4 N9@ SQN #T! /9N #M SU! #S/ BS DS MS US % 1 2 & 4 , 4 ' 1 ) 9 ! / * # B 1% 11 12 1& 14 1, 14 1' 11 1) 19 1! 1/ 1* 1# 1B
Charac Hex 2% 8 ; < = ? A C E F H 0 , . N O % 1 2 & 4 , 4 ' 1 ) : T W " \ _ 21 22 2& 24 2, 24 2' 21 2) 29 2! 2/ 2* 2# 2B &% &1 &2 && &4 &, &4 &' &1 &) &9 &! &/ &* &# &B
Dec &2 && &4 &, &4 &' &1 &) 4% 41 42 4& 44 4, 44 4' 41 4) ,% ,1 ,2 ,& ,4 ,, ,4 ,' ,1 ,) 4% 41 42 4&
Dec 44 4, 44 4' 41 4) '% '1 '2 '& '4 ', '4 '' '1 ') 1% 11 12 1& 14 1, 14 1' 11 1) )% )1 )2 )& )4 ),
Charac Hex 5 a b c d e + g h i J L l m n o p P r s t u v $ y V Y [ ^ 4% 41 42 4& 44 4, 44 4' 41 4) 49 4! 4/ 4* 4# 4B '% '1 '2 '& '4 ', '4 '' '1 ') '9 '! '/ '* '# 'B
Dec )4 )' )1 )) 1%% 1%1 1%2 1%& 1%4 1%, 1%4 1%' 1%1 1%) 11% 111 112 11& 114 11, 114 11' 111 11) 12% 121 122 12& 124 12, 124 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
Peter Nauth
Microcontroller Technology
*ata Gnput
*ata 6utput
*ata processing -ith electronic circuits cannot be adapted to ne- procedures -ithout changing the circuit
Program
Microcontroller
*ata Gnput
*ata 6utput
*ata processing -ith microcontroller can easily be adapted by changing the program -hich contains the data processing procedure
/ompiler
9ssembly /ode
9ssembly /ompiler
6bJect code Econsisting o+ instruction bytes: operators and operandsF is stored in the controller to be e$ecuted
Seite 4 von 41
Peter Nauth
Microcontroller Technology
/locL
aP E/PUF
Memory
*ata !us 9dress !us /ontrol !us
GO6
System !us
!locL *iagram o+ a MicrocomputerN The Microprocessor EaP, /PUF reads the Gnstruction !ytes o+ the he$code Emachine codeF +rom the MemoryN 9 Microcomputer on a single chip is called a Microcontroller
6perator !yte
/ontrol Unit
Control Bus
6perand !yte
00 Programm /ounter 9ddress o+ ne$t Gnstruction !yte Data Bus A ress Bus
Seite , von 41
Peter Nauth
Microcontroller Technology
Microprocessor selects address o+ ne$t instruction byte and puts it on address bus
Microprocessor activates the control signal PS#N -hich is connected -ith the control input 6# Eoutput enableF o+ the program memory
Program memory puts instruction byte -hich is stored on the selected address to the data bus
Gnstruction Processing
1%,&,:
MGPS
E12
M7
/locLF
:/111: 12 MGPS E24 M7 /locLF indicates, ho- many 10 6 9ssembly Gnstructions the processor can e$ecute in 1 s ETp: Machine /ycle EM/F TimeFN C!"C : #!"C : /omple$ Gnstruction Set /omputer EeNgN 1%,&,, :/111F Meduced Gnstruction Set /omputer
Seite 4 von 41
Peter Nauth
Microcontroller Technology
*erivate o+ the 1%,1 Micro./ontroller +amily 1.!it /ontroller, /locL ma$N 14 M7 , Gp " 1 MGPS at12 M7 ' Ports available +or GO6 o+ *igital *ata EP% ( P4F or 9nalog signals EP4F & Timer O /ounter ' e$ternal Gnterrupt Gnputs Ethrough the pins o+ Ports P1 und P&F 1 RorLing Megister EM% ( M'F at 4 Megister banLs Gnternal *ata Memory: 2,4 !yte, optional: #$ternal *ata Memory: 44 L!yte #$ternal Program Memory: 44 L!yte
Seite ' von 41
Peter Nauth
Microcontroller Technology
Microprocessor aP
P& RM M*
PS#N
P%
92#
P2
6# *! *ata !us 9*
2 a t c h 9ddress !us
9*
Seite 1 von 41
Peter Nauth
Microcontroller Technology
States Phasen
S1 S2 S3 S4 S5 S6 S1 S2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
PSEN
P0
Adr L !"
Adr L !"
Adr L !"
P2
Adr #i$h"
Adr #i$h"
Timing Diagramm
*ata
"0ecial12unction1#egister +"2#,/ . 9., !.Megister . Ports P% NNN P,
StacL: Stores re.entry address and data 2GB6, de+ault adress is %1h .\ StacLpointer SP points at adrN %'h Rrite: Gncrement Mead: *ecrement /hange *e+ault: M6K SP, <ne-`adr
1%h
2%h %%h
Seite ) von 41
Peter Nauth
Microcontroller Technology
#egister P, P,`*GM ! P4 P4`*GM 9// P4 *9PM 9**9T 9*/6N PSR T72 T22 /M/7 /M/2 T2/6N //7& //2& //7& //22 //71 //21 //#N GM/6N GP1 G#N1 P& GP% G#N% P2 S!UB S/6N P1 T71 T7% T21 T2% TM6* T/6N P/6N *P7 *P2 SP P%
Bita r3 Port , !.Megister Port 4 9.Megister Port 4 9*/ 9*/ *ata Qes Qes
2unction
9*/ /ontrol Programm Status Rort Timer 2 7igh.!yte Timer 2 2o-.!yte /M/ 7igh.!yte /M/ 2o-.!yte
Qes
Timer 2 /ontrol /ompareO/apture 7igh.!yte /ompareO/apture 2o-.!yte /ompareO/apture 7igh.!yte /ompareO/apture 2o-.!yte /ompareO/apture 7igh.!yte /ompareO/apture 2o-.!yte /ompareO/apture #nable.!yte
Gnterrupt.MePuest./ontrol Gnterrupt.Priority.Megister 1 Gnterrupt.#nable.Megister 1 Port & Gnterrupt.Priority.Megister % Gnterrupt.#nable.Megister % Port 2 Serieller Port !u++er Serieller Port /ontrol Port 1 Timer 1 7igh.!yte Timer % 7igh.!yte Timer 1 2o-.!yte Timer % 2o-.!yte Timer #instellung
Qes
Timer /ontrol Po-er /ontrol *ata Pointer E*PTMF 7igh.!yte *ata Pointer E*PTMF 2o-.!yte StacL Pointer
Qes
Port %
Peter Nauth
Microcontroller Technology
SymbN !itadrN /Q
PSRN' PSRN4 PSRN, PSRN4 PSRN& PSRN2 PSRN1 PSRN% PhysN !itadrN %*'h %*4h %*,h %*4h %*&h %*2h %*1h %*%h C5.!it The /arry.Blag indicates an over+lo- +or unsigned numbersN Gt is set Eto 1F, i+ the calculation o+ a sum or a di++erence e$ceeds the limit % % 2,, E%%h % BBhF has been e$ceededN 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 occurredN Gt is used by the instruction *9 9 +or a !/* correctionN B6 % % 1 1 % 1 % 1 The Blag % can be used by the programmerN Megister !anL % activated, adresses %%h . %'h o+ internal *ata Memory Megister !anL 1 activated, adresses %1h . %Bh o+ internal *ata Memory Megister !anL 2 activated, adresses 1%h . 1'h o+ internal *ata Memory Megister !anL & activated, adresses 11h . 1Bh o+ internal *ata Memory #"1 #"0 Megister !anL Select /ontrol !its +or addresses o+ M% ( M'
6K The 6ver+lo-.Blag indicates an over+lo- +or signed numbersN Gt is set Eto 1F, i+ the calculation o+ a sum or a di++erence e$ceeds the limit 12' % .121 E'Bh%1%hF has been e$ceededN B1 P The Blag % can be used by the programmerN The Parity.Blag is set Eto 1F i+ the sum o+ the bits % . ' o+ the 9.Megister is odd
Seite 11 von 41
Peter Nauth
Microcontroller Technology
"2#
P"4
ADC8N !*
T2C8N T2PS !#C8N !9N1 P) !9N0 "C8N P1 TM8D TC8N PC8N #:B2 #:#N2 M* #92 SM% T2 D9T# TB1 SM6*
LE( Schal& S-itch ter "uchsen /onnectrs "uchsen /onnectrs "uchsen /onnectrs
Gnterrupts ,nterru-ts 9nalog 2*ernah/e GO6 .i/er$ate Timer Date anal $er +erte 01hler /ounter
Sens r
Peter Nauth
Microcontroller Technology
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 iNeN +rom operand 2 and & to operand 1 Co0y an arith%etic instructions /opy Gnstructions: M6K 6perand1, 6perand2 eNgN: M6K 9, <2/h 9rithmetic Gnstructions: 9** 6perand1, 6perand2 SU!! 6perand1, 6perand2 eNgN 9** 9, <2*h eNgN /2M / SU!! 9, <2*h T9dd 6perand1 and 6perand2 and copy Tthe sum into 6perand1 TSubstract 6perand2 Eand the /arry.BlagF T+rom 6perand1 T9dd 2*h to the 9.Megister T/lear /`Megister E" /arry.BlagF TSubstract 2*h and the /arry.Blag +rom the 9.Megister T /opy data +rom 6perand2 to 6perand1 T/opy the number 2/h into the 9.Megister
Data !(8 &ith 0orts 1N Set data direction by setting the register P$`*GM: Gnput " %, 6utput " 1 eNgN M6K P4`*GM, <%BBh TP4 output enabled M6K P,`*GM, <%%h TP, input enabled 2N /opy data +rom or to ports eNgN M6K P4, 9
MemarL: in order to address the ports -ith their symbolic addresses, the register library REGXC888_lite.INC (see cha ter REGXC888_lite.INC! m"st #e incl"$e$ in the r%gram (see cha ter E$it& c%m ile an$ r"n a r%gram !.
Peter Nauth
Microcontroller Technology
/omments 6p./ode o+ M6K dadr, <L1 1N 6perand: address o+ P4`*GM 2N 6perand <%BBh 6p./ode o+ M6K dadr, <L1 1N 6perand %1 2N 6perand <%& 6p./ode o+ M6K Mr, <L1 mit r"& 2N 6perand <%4 6p./ode o+ M6K 9, dadr 9ddress o+ P4 in internal *ata Memory E8F 6p./ode o+ 9** 9, 3Mi mit i"1 6p./ode o+ M6K dadr, 9 9ddress o+ P, in internal *ata Memory E8F
& !yte
2 !yte
M6K 9, P4
2 !yte
1 !yte 2 !yte
7e$code Estored in Program MemoryF o+ an e$ample programN The start address is supposed to be %%%%hN Bor P4 and P, the addresses Einternal data memoryF +or the 1%,&, controller are used
Megister
M% M1 M2 M& M4 M, M4 M'
%&
%4
9** 9, 3M1
NNNN 9// P4 ! P,
Seite 14 von 41
Peter Nauth
Microcontroller Technology
2oop instructions
Peter Nauth
Microcontroller Technology
9ddress
*ata
/omment
9ssembly GnstrN
!yte
%% %% %% %1 %% %2 %% %& %% %4 %% %, %% %4 %% %' %% %1 %% %) %% %9
6p./ode o+ M6K Mr, <L1 -ith r"% 2N 6perand <1%d 6p./ode o+ M6K Mr, <L1 -ith r"1 2N 6perand <2%d 6p./ode o+ M6K 9, <L1 2N 6perand <%% 6p./ode o+ M6K 3Mi, 9 mit i" 1 6p./ode o+ GN/ 9 6p./ode o+ GN/ Mr -ith r" 1 6p./ode o+ *INS Mr, rel -ith r" % Iump address 266P is shi+ted by B!h " ., E%4h. %!hF relatively to the address +ollo-ing the Jump instruction *INS 6p./ode o+ 2IMP adr14 7igh !yte o+ absolute Jump addres %% %! 2o- !yte o+ absolute Jump addres %% %!
2 !yte
2 !yte
M6K 9, <%%
2 !yte
%% %! %% %/ %% %* %% %#
%2 %% %! NNN
2IMP #N*
& !yte
Peter Nauth
Microcontroller Technology
!nterru0ts
2N Gnterrupt o+ 27 9nter*rechun$ running program des Pr $ra//s andund Jump to zur S-run$ Adresse address &h 3h
%$%%%&
1N 2o-.signal at 17 L !& Si$nal Pinan &N2 triggers Pin 372 l8st Gnterrupt ,nterru-t aus
Pin 372
4:cks-run$ 4N47 !acL Jump and und ; rtsetzun$ continuation o+ des Pr $ra//s program
Gnterrupt #$ternal GM % #$ternal GM 1 #$ternal GM 2 #$ternal GM & #$ternal GM 4 #$ternal GM , #$ternal GM 4 Timer % Timer 1 Timer 2 Serial Gnter+ace 9*./onverter Gnterrupt Parameter
Gnterrupt Kector Gnterrupt MePuest %&h 1&h 4!h ,&h ,!h 4&h 4!h 2o- 2evel 2o- 2evel Negative Slope Negative Slope Positive Slope Positive Slope Positive Slope
Priority % % % % % % %
Selection #:% #:1 #:2 #:& #:4 #:, #:4 #T% #T1 #T2 #S
2&h
% %
Peter Nauth
Microcontroller Technology
Ti%er Mo e 1
14 bit Timer Timer register is T76:T2% E7igh byte in T7%, 2o- !yte in T2%F 14 bit reload value TM2 must be reloaded in T7% and T2% by program GSM is called in an interval o+ TGSM " E4,,&4. TM2FH1&N&ns
Ti%er Mo e 2
1 bit Timer Timer register is T2% 1 bit reload value TM2 is stored in T7% Meload is per+ormed automatically at over+loGSM is called in an interval o+ TGSM " E2,,. T7%FH1&N&ns
T2% incremented each 1&N& ns E1M/ +or :/111F .L0 !ird 3ede 1Es inkre/entiert '). > 0 @1 4el ad
? 255
.L0
> 255
,nterru-t SerAicer utine ,S4 <:r .i/er 0 6ver+loE2,,.T7%FH1&N& ns .\ Alle B255each C .#0D Es !ird die ,S4 Meload B<alls value aktiAiertD loaded und automatically $estartet .LE /it +rom T7% to T2% and GM> is de/ 4el ad!ert aus .#0an $eladen generated i+ GM is activated
.#0
,/ .i/er/ dus B'). > 0D !ird .L0 3ede 1Es inkre/entiert BPr zess rtakt > 12 M#zD7
Setting o+ Timer /on+iguration done -ith SBM TM6* Set Timer % to Mode 2: M6K TM6*, <%2h Set Timer 1 to Mode 2: M6K TM6*, <2%h TSet !it M1 o+ Timer % TSet !it M1 o+ Timer 1
Set Timer % to Mode2 and enable /ounter: M6K TM6*, <%4h TSet M1 and /OT
Seite 11 von 41
Peter Nauth
Microcontroller Technology
T 9ddress GnterruptveLtor E" 6MD %%%!h +or 1%,&, /ompilerF T Iump to GSMT 2IMP GSM is stored at address %$%%%! T only i+ called by e$ternal program
THHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH Timer`*elay: M6K M6K M6K S#T! S#T! S#T! P4`*GM, <%BBh TM6*, T7%, #T% #9 TM% <%2h T P4 *irection au+ 6utput T Set Timer % to Modus2
<rld TMeload Kallue +or setting Gnterrupt Service Gntervall T`isr"E2,,.rldFHT`m T Timer % Gnterrupt aLtivate T Melease all Gnterrupts T Start Timer
loop: -ait:
<m
T Set loop counter to m T Rait until /Q is set by GSM, then the Time T`isr has passed T /lear /.Blag
-ait
THHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH GSM: S#T! / GSM`Stop: M#TG T GSM is called each T`GSM"E2,,.M2*FHT`MS T Set /QT is checLed in Main Program Timer`*elay,in order to measure T`isr
THHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH end
Seite 1) von 41
Peter Nauth
Microcontroller Technology
Melo y Progra%
P473
P473
'PL P473
'PL P473
.)2
Signal +or the generation o+ a tone -ith a speaLer connected to P4N&N Si$nalAerlau< <:r die . nerzeu$un$ /it eine/ an P473 The speaLerssenen signal must be complemented t-ice during period an$eschl Lauts-recher7 ,n einer Peri de /ussadas
Lauts-rechersi$nal z!ei/al inAertiert !erden
Tone Nu%-er TH: / /is * bbb /C bbb TO2 " T7S H 1)s E" M' H 1)s, i+ T7S is stored in M'F + " 241,4& 7 , T7S " 1%% " ,% H
313 F 13
T7S " 2%% " 1%% H T7S " 11) " 1%% H
313 F 13 311 F 13
Seite 2% von 41
Peter Nauth
Microcontroller Technology
Start
46 > 131
4F >> 0
'PL P57F
(E' 46
4F > .#0
46 >> 0
T
(E' 41
N
41 >> 0
T
Ende . Melody n-r $ra// zur Entk --lun$ A n . nh8he und . ndauer B.#0 > program -ith decoupling o+ tone +rePuency and . tone nh8henzahlD length
T7S .\ M' + " 1 O ET7S H &1asF T2S .\ M1 T2 " T2S H M4 H 1)as " T2S H 2,, ms Ei+ M4 " 1&1F
Seite 21 von 41
Peter Nauth
Microcontroller Technology
"u-routines
/all o+ a subroutine: Structure o+ a subroutine : srname: bbN M#T T!egin o+ subroutine srname T#nd o+ subroutine srname 2/922 srname
EMe.entry address +or bacL Jump to calling program is stored in the stacLF
9pplication +or Melody program Erough structureF M#26: *! T2S1, T7S1, T2S2, T7S2, bNT2Sn, T7Sn, % P29Q: M6K M6K/ IS M6K GN/ M6K M6K/ M6K *PTM, <M#26 9, <%% 9, 39 0 *PTM ST6P M1, 9 *PTM 9, <%% 9, 39 0 *PTM M2, 9 TSet !ase Pointer at table address TSet Gnde$ Pointer TTable access TStore T2S in M1 TSet !ase Pointer to ne$t address TSet Gnde$ Pointer TTable access TStore T7S in M2 TPlay tone TIump to ST6P i+ 9 is %Eend o+ tableF M#P#9T: M6K
Seite 22 von 41
Peter Nauth
Microcontroller Technology
*!: MS: #:
9S/GG. character or control -ord /ontrol mode EMS " %F or *isplay mode EMS " 1F Negative Slope e$ecutes display o+ character or control +unction, -ait 1'%%as EcontrolF or 4%as EdisplayF -ait or until !B""%N *! " %1h .\ /lear display, /ursor to1st column le+t *! " 1%h 0 n .\ /ursor to position n in 1st ro*! " /%h 0 n .\ /ursor to position n in 2nd ro-
/ontrol -ords:
Peter Nauth
Microcontroller Technology
Seite 24 von 41
Peter Nauth
Microcontroller Technology
Seite 2, von 41
Peter Nauth
Microcontroller Technology
!ntegrate De;elo0%ent 9n;iron%ent +!D9, <Vision 4 Create a ne$ pro*ect 1. Create a ne( /%l$er /%r .%"r la# e)ercises 3. 0tart E=isi%n B. Create a ne( r%<ect an$ st%re it in .%"r /%l$er (Data T. e* -r%<ect Giles @."1 r%<!
Seite 24 von 41
Peter Nauth
Microcontroller Technology
C. In %r$er t% create a sim"lati%n an$ a har$(are (%rDs ace& clicD %n Kset" /ile e)tensi%n 4.L
Peter Nauth
Microcontroller Technology
6. 7 en K7 ti%ns /%r Target MTarget 1ML /%r 0im"lati%n /irst an$ then& a/ter ha1ing er/%rme$ the s"#seN"ent ste s& /%r ,CTI0.stem an$ re eat the s"#seN"ent ste s
Seite 21 von 41
Peter Nauth
Microcontroller Technology
;G%r 0im"lati%n O%rDs ace* 9cti1ate KPse 0im"lat%rL ;G%r ,CTI0.stem O%rDs ace* 9cti1ate KIn/ine%n XC800 P+INQ Dri1erL
Seite 2) von 41
Peter Nauth
Microcontroller Technology
&dit+ compile and run a program 1. 7 en the relate$ r%<ect 3. 7 en a ne( /ile* Gile SS Ne( B. 0a1e the /ile* Gile SS 0a1e as E)tensi%n /%r CI r%gram* @.c E)tensi%n /%r 9ssem#l.I r%gram* @.src H. Incl"$e the r%gram int% the r%<ect* Right m%"se clicD %n K0%"rce Gr%" 1L SS +e/t m%"se clicD %n K9$$ Giles t% 0%"rce M0%"rce Gr%" 1ML C. 7 en the /ile again& e$it the r%gram an$ sa1e it. The r%gram scelett%n %/ an assem#l. r%gram is* TN7,7DC1 TINC+PDE (REGXC888_lite.INC! 44 assem#l. c%$e 44 en$ 6. C% . REGXC888_lite.INC int% .%"r /%l$er (i/ n%t a1aila#le* cancel the instr"cti%n TINC+PDE (REGXC888_lite.INC!
Peter Nauth
Microcontroller Technology
Peter Nauth
Microcontroller Technology
,eader "ile &-.C///0lite ?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII ? Erstellt 300R 1%n O.Gr%te ? GUIGranD/"rt ? XC888 -r%cess%r ?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII T09=E TN7+I0T ? ? AVTE Register -H_DIR D9T9 0)CR -H_D9T9 D9T9 0)C8 -C_DIR D9T9 0)RB -C_D9T9 D9T9 0)R3 -H -C TU0 TU1 T+0 T+1 T,7D C,C7N FF -%rt H -H_0 -H_1 -H_3 -H_B -H_H -H_C -H_6 -H_6 AIT 0)C8? AIT 0)CR? AIT 0)C9? AIT 0)CA? AIT 0)CC? AIT 0)CD? AIT 0)CE? AIT 0)CG? D9T9 0)C8 D9T9 0)R3 D9T9 D9T9 D9T9 D9T9 D9T9 D9T9 0)8C 0)8D 0)89 0)8A 0)8R 0)A9
TR0 ET0 E9
TRE0T7RE
Seite &2 von 41
Peter Nauth
Microcontroller Technology
Peter Nauth
Microcontroller Technology
Arith%eti. !nstructions
1nemonic ADD A>#r ADD A> a r ADD A>?#i ADD A>@.onst' ADDC A>#r ADDC A> a r ADDC A> ?#i ADDC A> @.onst' "BBB A>#r "BBB A> a r "BBB A>?#i "BBB A>@.onst' !NC A !NC #r !NC a r !NC ?#i !NC DPT# D9C A D9C #r D9C a r D9C ?#i MB= AB D!V AB DA A 23tes 1 3 1 3 1 3 1 3 1 3 1 3 1 1 3 1 1 1 1 3 1 1 1 1 1C 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 H H 1 4lags CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&CV&9C& 7=&I I I I I I I CV&7=&CV&7=&CV 5p 38I3G 3C 36&36 3H B8IBG BC B6&B6 BH R82RG RC R6&R6 RH 0H 0820G 0C 06&06 9B 1H 1821G 1C 16&16 9H 8H DH
Peter Nauth
Microcontroller Technology
=ogic !nstructions
1nemonic AN= A>#r AN= A> a r AN= A>?#i AN= A>@.onst' AN= a r>A AN= a r>@.onst' 8#= A>#r 8#= A> a r 8#= A>?#i 8#= A>@.onst' 8#= a r>A 8#= a r>@.onst' . L A+ r *#= A> a r *#= A>?#i *#= A>@.onst' *#= a r>A *#= a r>@.onst' C=# A CP= A 23tes 1 3 1 3 3 B 1 3 1 3 3 B 1 3 1 3 3 B 1 1 18 1 1 1 1 1 3 1 1 1 1 1 3 1 1 1 1 1 3 1 1 4lags I I I I I I 5p C82CG CC C6&C6 CH C3 CB H82HG HC H6&H6 HH H3 HB 6826G 6C 66&66 6H 63 6B EH GH
"hi$t !nstructions
1nemonic #= A #=C A ## A ##C A 23tes 1 1 1 1 18 1 1 1 1 4lags I CV&I CV&5p 3B BB 0B 1B
Peter Nauth
Microcontroller Technology
"u-routine !nstructions
1nemonic ACA== a r11 =CA== a r17 #9T #9T! 23tes 3 B 1 1 18 3 3 3 3 4lags I I I I 5p 11 13 33 B3
Cu%0 !nstructions
1nemonic ACMP a r11 =CMP a r17 "CMP rel CMP ?AADPT# C: rel CN: rel CC rel CNC rel CB -a r> rel CNB -a r>rel CBC -a r>rel CJ'& A+dadr+rel CCN9 A>@.onst'>rel CCN9 #r>@.onst'>rel CCN9 ?#i>@.onst'>rel DCN: #r>rel DCN: a r>rel 23tes 3 B 3 1 3 3 3 3 B B B B B B B 3 B 18 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4lags I I I I I I I I I I I CV CV CV CV I I 5p 01 03 80 6B 60 60 H0 C0 30 B0 10 AC AH A82AG A6&A6 D82DG DC
A--ri;iations
9 9/ adr11 adr14 ! badr /Q dadr 6K P rel Mi Mr ? <Lonst1 <Lonst14 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 9ccumulator 9u$iliary./arry.Blag 11.!it.9dress -ithin a 2.L!yte.Seite 14.!it.9dress Megister ! !it.9dress /arry.Blag 9ddress o+ the internal data memory 6ver+lo-.Blag Parity.Blag relativ 1.!it.6++set.9dress E(121 bis 012'F Megister EM% or M1F Megister EM% . M'F 2abel +or indirect addressing 1.!it./onstant 14.!it./onstant
Seite &4 von 41
Peter Nauth
Microcontroller Technology
C- Programming
OOHHHHHHHHH /alculate P4 0 P, and -rite the sum to P&HHHHHHHHHHHHOO <include W:/111/2MNh\ <include WstdioNh\ OO <include cU9MTN7c OO <include WstringNh\ int i,J,LT int arrayU14ZT int sumEvoidFT void mainEvoidF V P4`*GM " %$%%T P,`*GM " %$%%T P&`*GM " %$BBT OO Set Port *irection to Gnput OO Set Port *irection to Gnput OO Set Port *irection to 6utput OO Dlobal Kariables OO Dlobal 9rrays OO Bunction prototype
-hileE1F OO #ndless loop V i" P4T OO Gnput o+ P4 value J" P,T OO Gnput o+ P, value L" sumEFT P&" LT [ [ int sumEvoidF V int aT a " i 0 JT return aT [ OO HHHHHHHHHHHH#$ample o+ an GSMHHHHHHHHHHHHHHOO void isr EF interrupt 1 V bbNNT [ OO instructions o+ GSM OO GSM o+ Timer % ETimer % GSM has number 1, see pN1': numberF OO 6utput o+ result to P&
OO 2ocal variable
Peter Nauth
Microcontroller Technology
C-5perators Arith%etic 80erators 0 . O H ? .. 00 Sum *i++erence *ivision Multiplication Modulo *ecrement Epost and preF Gncrement Epost and preF
Bit 80erators A Y WW \\ ^ 8 9N* 6M 2e+t shi+t Might shi+t /omplement Negation Eresult is 1, i+ 6perand is % and vice verseF
Co%0arison +use e3g3 as con itions in control structures, "" 8" \ W \" W" YY ePual not ePual larger than smaller larger or ePual smaller or ePual 6M
AA 9N*
Peter Nauth
Microcontroller Technology
Assign%ents " H" O" ?" 0" ." *irect assignment 9ssignment o+ multiplication 9ssignment o+ *ivision 9ssignment o+ ModuloN 9ssignment o+ 9dditionN 9ssignment o+ SubtractionN
WW" 9ssignment o+ 2e+t Shi+tN \\" 9ssignment o+ Might Shi+t A" Y" ]" A 9ssignment o+ 9N* 9ssignment o+ 6M 9ssignment o+ :6M
Peter Nauth
Microcontroller Technology
Data Ty0es char unsigned char int unsigned int character or signed numbers E1 !yteF unsigned numbers E1 !yteF signed numbers E2 !yteF unsigned numbers E2 !yteF
Control "tructures -hileEconditionF V OO instructions e$ecuted continously as long as condition is True [ +orEi"%T iWm T i00F OOloop runs m times V OO instructions e$ecuted m times [ i+ EconditionF V OO instructions e$ecuted once i+ condition is True [
Seite 4% von 41
Peter Nauth
Microcontroller Technology
=iterature
Microcontrollers in Practice Springer Series in 9dvanced Microelectronics, KolN 11 Susnea, Goan, Mitescu, Marian Springer Kerlag, 2%%, GS!N: )'1.&.,4%.2,&%1.&
9x0loring C $or Microcontrollers 9 7ands on 9pproach Parab, IN, ShelaLe, KNDN, @amat, MN@N, NaiL, DNMN Springer Kerlag, 2%%' GS!N )'1.1.4%2%.4%44.&
Seite 41 von 41