mahi report.doc
TRANSCRIPT
-
8/10/2019 MAHI REPORT.doc
1/29
1.DIFFRENCE BETWEEN MICROROCESSOR AND MICROCONTROLLER
A Microprocessor is a general purpose digital computer central processing unit(C.P.U) popularly
known as CPU on the chip. The Microprocessors contain no RAM no R!M and no "#P !#P
ports on the chip itsel$.
!n the other hand a Microcontroller has a C.P.U(microprocessor) in addition to a $i%ed amount
RAM R!M "#! ports and a timer all on a single chip.
"n order to make a Microprocessor $unctional we must add RAM R!M "#! Ports and timers
e%ternally to themie any amount o$ e%ternal memory can &e added to it.
'ut in controllers there is a $i%ed amount o$ memory which makes them ideal $or many
applications.
The Microprocessors hae many operational codes(opcodes) $or moing data $rom e%ternal
memory to the C.P.U
2. DISADVANTAGES OF MICROPROCESSOR OVER MICROCONTROLLER
ystem designed using Microprocessors are &ulky
They are e%pensie than Microcontrollers
*e need to add some e%ternal deices such as PP" chip Memory Timer#counter chip "nterrupt
controller chipetc. to make it $unctional.
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
2/29
3.EMBEDDED SYSTEM USING MICROCONTEOLLER
/.1 INTRODUCTION TO MICROCONTROLLER
An embedded system
0mploys a com&ination o$ so$tware hardware to per$orm a speci$ic $unction.
"s a part o$ a larger system which may not &e a 2computer3.
*orks in a reactie time constrained enironment.
3.2C!ARACTERSTICS
S"#$%e &'#(t")#ed
0%ecutes a single program repeatedly.
T"$*t%y+()#st,-"#ed
4ow power low cost small $ast etc.
Re-(t"e / ,e-% t"me
Continually reacts to the changes in the system5s enironment.
Must compute certain result in real6time without delay
TOOLS USED FOR EMBEDDED SYSTEM
F), Assemb%y L-#$'-$e+
-71 Assem&ler cum imulator
"P68lash Programmer 9ersion /.-a 6:e% 8ile ;ownloader (Machine code gets &urned in controller) 6
F), C L-#$'-$e+
Programming 0nironment6 Programmers
-
8/10/2019 MAHI REPORT.doc
3/29
Embedded System A00%"(-t")#s+
Consumer electronics e.g. cameras cell phones etc.
Consumer products e.g. washers microwae oens etc.
Automo&iles (anti6lock &raking engine control etc.)
"ndustrial process controller de$ense applications.
Computer#Communication products e.g. printers 8A= machines etc.
Medical 0>uipments.
ATMs
3.3 !ISTORY OF 14
"ntel Corporation introduced an 6&it microcontroller called -71 in 1?1 this controller had 1, &ytes o$ RAM
@k &ytes o$ on chip R!M two timers one serial port and $our ports all are on single chip. The -71 is an &i
processor meaning that the CPU can work on only &it data at a time. ;ata larger than &its &roken into &it
pieces to &e processed &y CPU. "t has $or "#! &it wide.
1.1 Fe-t',es )& t*e 14+
Fe-t',e 5'-#t"ty
R!M @+ &ytesRAM 1, &ytes
Timer ,
"#! pins /,
erial port 1
"nterrupt sources
3.6 14 A,(*"te(t',e Oe,"e7
The -71 $amily is one o$ the most common microcontroller architectures used worldwide.-71 &ased
microcontrollers are o$$ered in hundreds o$ ariants $rom many di$$erent silicon manu$acturers.
The -71 is &ased on an 6&it C"C core with :arard architecture. "tBs an 6&it CPU optimied $or control
applications with e%tensie 'oolean processing (single6&it logic capa&ilities) @+ program and data memory
address space and arious on6chip peripherals.
The -71 microcontroller $amily o$$ers deelopers a wide ariety o$ high6integration and Cost6e$$ectie
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
4/29
solutions $or irtually eery &asic em&edded control application. 8rom tra$$ic control e>uipment to input deic
and computer networking products -71 microcontrollers delier high per$ormance together with a choice o$
con$igurations and options matched to the special needs o$ each application. *hether itBs low power operation
higher $re>uency per$ormance e%panded on6chip RAM or an application6speci$ic re>uirement thereBs a ersio
o$ the -71 microcontroller thatBs right $or the Do&.
*hen itBs time to upgrade product $eatures and $unctionality the -71 architecture puts you on the $irst step o$
smooth and cost6e$$ectie upgrade path 6 to the enhanced per$ormance o$ the 171 and ,71 microcontrollers.
4.4 BLOC8 DIAGRAM OF 14
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
5/29
3. PIN DESCRIPTION
P"< ;"AERAM !8 -71
Des(,"0t")# )& 0),ts
There are $our ports P- P1 P, and P/ each use pins making them 6&it ports. All the ports upon R00T ar
con$igured as output ready to &e used as output ports. To use any o$ these ports as an input port it must &e
programmed.
. P),t +Port - occupies a total o$ pins (pins /,6/?) ."t can &e used $or input or output. To use the pins o$ po
- as &oth input and output ports each pin must &e connected e%ternally to a 1-+ ohm pull6up resistor. This is
due to the $act that P- is an open drain unlike P1 P, and P/.!pen drain is a term used $or M! chips in the
same way that open collectoris used $or TT4 chips. *ith e%ternal pull6up resistors connected upon reset port -
is con$igured as an output port. 8or e%ample the $ollowing code will continuously send out to port - the
alternating alues 77: and AA:
P),t -s "#0't+ *ith resistors connected to port - in order to make it an input the port must &e programme
&y writing 1 to all the &its. "n the $ollowing code port - is con$igured $irst as an input port &y writing 1Bs to it
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
6/29
and then data is receied $rom the port and sent to P1.
M!9 A F-88: G A H 88 he%
M!9 P- A G make P- an input port
'AC+I M!9 A P- G get data $rom P-
M!9 P1 A G send it to port 1
JMP 'AC+
D'-% R)%e )& P),t +Port - is also designated as A;-6A;K allowing it to &e used $or &oth address and data.
*hen connecting an -71#/1 to an e%ternal memory port - proides &oth address and data. The -71
multiple%es address and data through port - to sae pins. A40 indicates i$ P- has address or data. *hen A40 H
- it proides data ;-6;K &ut when A40 H1 it has address and data with the help o$ a K@4/K/ latch.
P),t 4+Port 1 occupies a total o$ pins (pins 1 through ). "t can &e used as input or output. "n contrast to por
- this port does not need any pull6up resistors since it already has pull6up resistors internally. Upon reset Port
is con$igured as an output port. 8or e%ample the $ollowing code will continuously send out to port1 the
alternating alues
P),t 4 -s "#0't+To make port1 an input port it must programmed as such &y writing 1 to all its &its. "n the
$ollowing code port1 is con$igured $irst as an input port &y writing 15s to it then data is receied $rom the port
and saed in RK R R7.
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
7/29
M!9 A F-88: G AH88 :0=
M!9 P1 A G make P1 an input port &y writing all 15s to it
M!9 A P1 G get data $rom P1
M!9 RK A G sae it in register RK
ACA44 ;04AL G wait
M!9 A P1 G get another data $rom P1
M!9 R A G sae it in register R
ACA44 ;04AL G wait
M!9 A P1 G get another data $rom
M!9 R7 A G sae it in register R7
P),t 2+Port , occupies a total o$ pins (pins ,16 ,). "t can &e used as input or output. Just like P1 P, does no
need any pull6up resistors since it already has pull6up resistors internally. Upon reset Port , is con$igured as an
output port. 8or e%ample the $ollowing code will send out continuously to port , the alternating alues 77h and
AA:. That is all the &its o$ port , toggle continuously.
M!9 A F77: G A H 77 he%
'AC+I M!9 P, A G send it to Port ,
ACA44 ;04AL G call delay routine
CP4 A G make AH-
P),t 2 -s "#0't +To make port , an input it must programmed as such &y writing 1 to all its &its. "n the$ollowing code port , is con$igured $irst as an input port &y writing 15s to it. Then data is receied $rom that
port and is sent to P1 continuously.
M!9 A F-88: G AH88 he%
M!9 P, A G make P, an input port &y writing all 15s to it
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
8/29
-
8/10/2019 MAHI REPORT.doc
9/29
S"#$%e b"t -dd,ess-b"%"ty )& 0),ts+There are times that we need to access only 1 or , &its o$ the port instead o
the entire &its. A power$ul $eature o$ -71 "#! ports is their capa&ility to access indiidual &its o$ the port
without altering the rest o$ the &its in that port.
8or e%ample the $ollowing code toggles the &it p1., continuously.
'AC+I CP4 P1., G complement p1., only
ACA44 ;04AL
JMP 'AC+
-
8/10/2019 MAHI REPORT.doc
10/29
&us into a serial programming inter$ace and allows the program memory to &e written to or read $rom unless
4ock 'it , has &een actiated.
Fe-t',es
Compati&le with MC671NProducts
+ &ytes o$ "n6ystem Reprogramma&le ;ownloada&le 8lash Memory
6 P" erial "nter$ace $or Program ;ownloading
6 0nduranceI 1--- *rite#0rase Cycles
@.-9 to 7.79 !perating Range
8ully tatic !perationI - : to // M:
Three64eel Program Memory 4ock
,7 % &it "nternal RAM
/, Programma&le "#! 4ines
Three 1 &it Timer#Counters
0ight "nterrupt ources
8ull ;uple% UART erial Channel
4ow Power "dle and Power ;own Modes
"nterrupt Recoery 8rom Power ;own Mode
*atchdog Timer
RSTReset input. A high on this pin $or two machine cycles while the oscillator is running resets the deice.
ALE:PROG
Address 4atch 0na&le is an output pulse $or latching the low &yte o$ the address during accesses to e%tern
memory. This pin is also the program pulse input (PR!E) during 8lash programming. "n normal operation A4
is emitted at a constant rate o$ 1# the oscillator $re>uency and may &e used $or e%ternal timing or clockin
purposes.
-
8/10/2019 MAHI REPORT.doc
11/29
PSEN
Program tore 0na&le is the read stro&e to e%ternal program memory. *hen the AT?,7, is e%ecuting cod
$rom e%ternal program memory P0< is actiated twice each machine cycle e%cept that two P0< actiation
are skipped during each access to e%ternal data memory.
EA:VPP
0%ternal Access 0na&le. 0A must &e strapped to E
-
8/10/2019 MAHI REPORT.doc
12/29
incremented eery machine cycle. ince a machine cycle consists o$ 1, oscillator periods the count rate is 1#1
o$ the oscillator $re>uency. "n the Counter $unction the register is incremented in response to a 16to6- transitio
at its corresponding e%ternal input pin T,. "n this $unction the e%ternal input is sampled during 7P, o$ ee
machine cycle. *hen the samples show a high in one cycle and a low in the ne%t cycle the count
incremented. The new count alue appears in the register during /P1 o$ the cycle $ollowing the one in whic
the transition was detected. ince two machine cycles (,@ oscillator periods) are re>uired to recognie a 16to6
transition the ma%imum count rate is 1#,@ o$ the oscillator $re>uency. To ensure that a gien leel is sampled a
least once &e$ore it changes the leel should &e held $or at least one $ull machine cycle
I#te,,'0ts
The AT?7, has a total o$ si% interrupt ectorsI two e%ternal interrupts ("
-
8/10/2019 MAHI REPORT.doc
13/29
when the serice routine is ectored to. "n $act the serice routine may hae to determine whether it was T8, o
0=8, that generated the interrupt and that &it will hae to &e cleared in so$tware. The Timer - and Timer
$lags T8- and T8" are set at 7P, o$ the cycle in which the timers oer$low. The alues are then polled &y th
circuitry in the ne%t cycle. :oweer the Timer , $lag T8, is set at ,P, and is polled in the same cycle i
which the timer oer$lows.
I#te,,'0t Re$"ste,s
The glo&al interrupt ena&le &it and the indiidual interrupt ena&le &its are in the "0 register. "n addition th
indiidual interrupt ena&le &it $or the P" is in the PCR register. Two priorities can &e set $or each o$ the si%
interrupt sources in the "P register.
CODE FOR INTERRUPTS
FincludeOat?s,7,.hoid enQint(oid)G
oid delay(unsigned int i)G
oid main (oid)
P1H-%--G
"
-
8/10/2019 MAHI REPORT.doc
14/29
delay(1------)G
P1Q-H-G
delay(1------)G
S
S
S
oid delay(unsigned int i)
while(iH-)
i66G
S
S
Ad-#t-$es )& C )e, Assemb%y %-#$'-$e 0,)$,-mm"#$
+nowledge o$ the processor instruction set is not re>uired.
;etails like register allocation and addressing o$ memory and data is managed &y the compiler.
Programs get a $ormal structure and can &e diided into separate $unctions.
Programming and program test time is drastically reduced this increases e$$iciency.
+eywords and operational $unctions can &e used that come closer to how humans think.
The supplied and supported C li&raries contain many standard routines such as numeric conersions.
Reusa&le codeI 0%isting program parts can &e more easily included into new programs &ecause o$ the
com$orta&le modular program construction techni>ues.
The C language &ased on the A
-
8/10/2019 MAHI REPORT.doc
15/29
I#te,&-("#$ t) LCD D"s0%-y
!n most displays the pins are num&ered on the 4C;5s printed circuit &oard &ut i$ not it is >uit easy to locate
pin1. ince the pin is connected to ground it o$ten has a thicker p.c.&. track connected to it and it is generally
connected to the metal work at some point.
T*e &'#(t")# )& e-(* )& t*e ()##e(t")#s "s s*)7# "# t*e t-b%e -b)e+
Pins 1 , are the power supply lines 9ss 9dd. The 9dd pin should &e connected to the positie supply 9
the -9 supply or ground.
Although the 4C; module data sheets speci$y 79 ;.C. supply (at only a $ew milliamps) supplies o$ 9 @.79
&oth work well and een /9 is su$$icient $or some modules. Conse>uently these modules can &e e$$ectiely an
economically powered &y &atteries.
Pin / is a control pin 9ee which is used to alter the contrast o$ the display. "deally these pin should &e connec
a aria&le oltage supply. A preset potentiometer connected &etween the power supply lines with its wiper
connected to the contrast pin is suita&le in many cases &ut &e aware that some modules may re>uire a negatie
potentialG as low as K9 in some cases. 8or a&solute simplicity connecting this pin to -9 will o$ten su$$ice.
Pin @ is register select (R) line.
PIN NO. NAME FUNCTION
1 9ss Eround
, 9dd e supply
/ 9ee Contrast
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
16/29
@ R Register select
7 R#* Read#*rite
0 0na&le
K ;- ;ata 'it -
;1 ;ata 'it 1
? ;, ;ata 'it ,
1- ;/ ;ata 'it /
11 ;@ ;ata 'it @
1, ;7 ;ata 'it 71/ ; ;ata 'it
1@ ;K ;ata 'it K
Three command control inputs. *hen this line is low data &ytes trans$erred to the display are treated ascommands and data &ytes read $rom the display indicate its status. 'y setting the R line high characterdata can &e trans$erred to and $rom the module.
Pin 7 is (R#*) line. This line is pulled low in order to write commands or character data to the module orpulled high to read character data or status in$ormation $rom its registers.Pin is 0na&le (0) line. This input is used to initiate the actual trans$er o$ commands or character data&etween the module and the data lines. *hen writing to the display data is trans$erred only on the high tolow transition o$ this signal. :oweer when reading $rom the display data will &ecome aaila&le shortlya$ter the low to high transition and remain aaila&le until the signal $alls low again.
Pins K to 1@ are the eight data &us lines (;- to ;K). ;ata can &e trans$erred to and $rom the display either aa single 6&it &yte or as two @6&it 2ni&&les3. "n the latter case only the upper $our data lines (;@ to ;K) areused. This V6&it mode is &ene$icial when using a microcontroller.
C!;0 8!R "
-
8/10/2019 MAHI REPORT.doc
17/29
de$ine lcdprt P-
de$ine rs P1Q,
de$ine en P1Q/
oid delay(unsigned int i)G
oid lcdQcmd(unsigned char a)G
oid display(unsigned char &)G
oid wait(oid)G
oid initQlcd(oid)G
oid clearQlcd(oid)G
oid cursorQposition(unsigned char c)G
oid dispQhe%(unsigned char digit)G
oid dispQdec(unsigned int digit)G
ode unsigned char
upQt&1-1W1XHB-BB1BB,BB/BB@BB7BBBBKBBBB?BBABB'BBCBB;BB0BB8BSG
4C; R!UT"
-
8/10/2019 MAHI REPORT.doc
18/29
ait()G
dprtH&G
H1G
H1G
H-G
id wait(oid)
nsigned int countH/--G
hile(countH-)
ount66G
d cursorQposition(unsigned char c)
dQcmd(c-%-)G
id dispQhe%(unsigned char digit)
nsigned char tempG
mpHdigit@G
play(lkupQt&1-1WtempX)
mpH(digit-%-$)G
play(lkupQt&1-1WtempX)G
id dispQdec(unsigned int digit)
nsigned int tempG
(digitO1--)
empHdigit#1-G
play(lkupQt&1-1WtempX)G
mpHdigit6tempY1-G
play(lkupQt&1-1WtempX)G
digit??digitO1---)
empHdigit#1--G
play(lkupQt&1-1WtempX)G
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
19/29
gitHdigit6(tempY1--)G
mpHdigit#1-G
play(lkupQt&1-1WtempX)G
gitHdigit6(tempY1-)G
mpHdigitG
play(lkupQt&1-1WtempX)G
(digit??digitO1----)
empHdigit#1--G
play(lkupQt&1-1WtempX)G
gitHdigit6(tempY1---)G
mpHdigit#1--G
play(lkupQt&1-1WtempX)G
gitHdigit6(tempY1--)G
mpHdigit#1-G
play(lkupQt&1-1WtempX)G
gitHdigit6(tempY1-)G
mpHdigitG
play(lkupQt&1-1WtempX)G
digit1----)
empHdigit#1----G
play(lkupQt&1-1WtempX)G
gitHdigit6(tempY1----)G
mpHdigit#1---G
play(lkupQt&1-1WtempX)G
gitHdigit6(tempY1---)G
mpHdigit#1--G
play(lkupQt&1-1WtempX)G
gitHdigit6(tempY1--)G
mpHdigit#1-G
play(lkupQt&1-1WtempX)G
gitHdigit6(tempY1-)G
mpHdigitG
Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
20/29
play(lkupQt&1-1WtempX)G
SS
id delay(unsigned int i)
hile(iH-)
G
S
oid main(oid)
hile(1)
nitQlcd()G
rsorQposition(-%--)G
play(BhB)G
lay(-%$$$$)G
rsorQposition(-%-1)G
play(BeB)G
lay(-%$$$$)G
cursorQposition(-%-,)G
play(BlB)G
lay(-%$$$$)G
cursorQposition(-%-/)G
splay(BlB)G
lay(-%$$$$)G
cursorQposition(-%-@)G
play(BoB)G
delay(-%$$$$)GS
S
SERIAL COMMUNICATION
,Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
21/29
CODE FOR SERIAL PORT COMMUNICATION IN TRANSMIT MODE
FincludeOat?s,7,.hoid initQsit(oid)
TM!;H-%--G
TM!;H-%,-G
C!
-
8/10/2019 MAHI REPORT.doc
22/29
-
8/10/2019 MAHI REPORT.doc
23/29
1+B"t =P C)m0-t"b%e D:A C)#e,te,s 7"t* 1+C*-##e%
The A;C--@ $amily is CM! 6'it successie6appro%imation A#; conerters which use a modi$ied
potentiometric ladder and are designed to operate with the --A control &us ia three6state outputs. These
conerters appear to the processor as memory locations or "#! ports and hence no inter$acing logic is re>uired
The di$$erential analog oltage input has good common mode6 reDection and permits o$$setting the analog ero6
input oltage alue. "n addition the oltage re$erence input can &e adDusted to allow encoding any smaller
analog oltage span to the $ull &its o$ resolution.
Fe-t',es
-C@ and -C-#7 'us Compati&le 6
-
8/10/2019 MAHI REPORT.doc
24/29
*hen inter$acing is &eing done then gets lowered then only it allows the controller to read the data
otherwise controller can not read the data.
is always grounded.
is so$tware controlled.
CODE FOR INTERFACING OF ADC>16? WIT! AT19S2 MICROCONTROLLER
FincludeOat?s,7,.h
Fde$ine lcdprt P-
Fde$ine rs P1Q,
Fde$ine en P1Q/ unsigned char readQadc(oid)G
unsigned char displayQdec(unsigned char i)G
oid initQsit(oid)G
oid transmitQserial(unsigned int a)G
oid delay(unsigned int i)G
,Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
25/29
oid lcdQcmd(unsigned char a)G
oid display(unsigned char &)G
oid wait(oid)G
oid initQlcd(oid)G
oid clearQlcd(oid)G
oid cursorQposition(unsigned char c)G
oid dispQhe%(unsigned char digit)G
oid dispQdec(unsigned int digit)G
oid shi$t(oid)G
code unsigned char
lkupQt&1-1W1XHB-BB1BB,BB/BB@BB7BBBBKBBBB?BBABB'BBCBB;BB0BB8BSG
##4C; R!UT"
-
8/10/2019 MAHI REPORT.doc
26/29
lcdprtH&G
rsH1G
enH1G
enH-G
S
oid wait(oid)
unsigned int countH/--G
while(countH-)
count66G
S
S
oid shi$t(oid)
lcdQcmd(-%1c)G
S
oid cursorQposition(unsigned char c)
lcdQcmd(c-%-)G
S
oid dispQhe%(unsigned char digit)
unsigned char tempG
tempHdigit@G
display(lkupQt&1-1WtempX)G
tempH(digit-%-$)G
display(lkupQt&1-1WtempX)G
S
oid dispQdec(unsigned int digit)
unsigned int temptemp1temp,G
i$ (digitO1--)
temp1Hdigit#1-G
display(lkupQt&1-1Wtemp1X)G
temp,Hdigit6temp1Y1-G
display(lkupQt&1-1Wtemp,X)G
transmitQserial(temp1Y1-temp,)GS
,Ramanpreet +aur (,1,-,-1)
-
8/10/2019 MAHI REPORT.doc
27/29
-
8/10/2019 MAHI REPORT.doc
28/29
display(lkupQt&1-1WtempX)G
digitHdigit6(tempY1-)G
tempHdigitG
display(lkupQt&1-1WtempX)G
SS
oid delay(unsigned int i)
while(iH-)
i66G
S
S
oid initQsit(oid)
TM!;H-%--G
TM!;H-%,-G
C!
-
8/10/2019 MAHI REPORT.doc
29/29
cursorQposition(-%--)G
delay(-%$$$$)G
dispQdec(e)G
S
S
unsigned char readQadc(oid)
unsigned char nG
P1Q-H-G ## !CH-
P1Q-H1G ## !CH1
while(P1Q1HH1) ##while( 0!CHH1)
nHP,G
S
return(n)G
S