PIC Microcontrollers Chap Introduct

download PIC Microcontrollers Chap Introduct

of 9

Transcript of PIC Microcontrollers Chap Introduct

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    1/9

    PIC Microcontrollers on-line  REE! 

    Index

    Development systems

    Contact us

     

    Previous page Table of contents Next Page

    CHAPTER 1

    Introduction to Microcontrollers

     

    Introduction

    HistoryMicrocontrollers versus microprocessors

    1.1 Memory unit1.2 Central processing unit

    1.3 Buses1.4 Input-output unit

    1.5 Serial communication1. !imer unit1." #atc$dog1.% &nalog to digital converter1.' (rogram

    Introduction

    Circumstances t$at )e *ind ourselves in today in t$e *ield o* microcontrollers $ad t$eir +eginnings in t$edevelopment o* tec$nology o* integrated circuits. !$is development $as made it possi+le to store $undreds o*

    t$ousands o* transistors into one c$ip. !$at )as a prere,uisite *or production o* microprocessors and t$e *irstcomputers )ere made +y adding eternal perip$erals suc$ as memory input-output lines timers and ot$er./urt$er increasing o* t$e volume o* t$e pac0age resulted in creation o* integrated circuits. !$ese integratedcircuits contained +ot$ processor and perip$erals. !$at is $o) t$e *irst c$ip containing a microcomputer or)$at )ould later +e 0no)n as a microcontroller came a+out.

    History

    It )as year 1'' and a team o* apanese engineers *rom t$e BSICM company arrived to nited States )it$a re,uest t$at a *e) integrated circuits *or calculators +e made using t$eir proects. !$e proposition )as set to

    I!67 and Marcian Ho** )as responsi+le *or t$e proect. Since $e )as t$e one )$o $as $ad eperience in)or0ing )it$ a computer 8(C9 (:(% it occured to $im to suggest a *undamentally di**erent solution instead o*

    t$e suggested construction. !$is solution presumed t$at t$e *unction o* t$e integrated circuit is determined +ya program stored in it. !$at meant t$at con*iguration )ould +e more simple +ut t$at it )ould re,uire *ar morememory t$an t$e proect t$at )as proposed +y apanese engineers )ould re,uire. &*ter a )$ile t$oug$apanese engineers tried *inding an easier solution Marcian;s idea )on and t$e *irst microprocessor )as +orn.In trans*orming an idea into a ready made product /rederico /aggin )as a maor $elp to I!67. He

    trans*erred to I!67 and in only ' mont$s $ad succeeded in ma0ing a product *rom its *irst conception. I!67o+tained t$e rig$ts to sell t$is integral +loc0 in 1'"1. /irst t$ey +oug$t t$e license *rom t$e BSICM

    http://www.mikroe.com/en/http://www.mikroe.com/en/tools/http://www.mikroe.com/en/contact/http://www.mikroe.com/en/books/picbook/0_Uvod.htmhttp://www.mikroe.com/en/books/picbook/2_01chapter.htmhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#Introduction%23Introductionhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#History%23Historyhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#Microcontrollers%20versus%20Microprocessors%23Microcontrollers%20versus%20Microprocessorshttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.1%20Memory%20unit%231.1%20Memory%20unithttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.2%20Central%20Processing%20Unit%231.2%20Central%20Processing%20Unithttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.3%20Bus%231.3%20Bushttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.4%20Input-output%20unit%231.4%20Input-output%20unithttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.5%20Serial%20communication%231.5%20Serial%20communicationhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.6%20Timer%20unit%231.6%20Timer%20unithttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.7%20Watchdog%231.7%20Watchdoghttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.8%20Analog-Digital%20Converter%231.8%20Analog-Digital%20Converterhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.9%20Program%231.9%20Programhttp://www.mikroe.com/en/http://www.mikroe.com/en/tools/http://www.mikroe.com/en/contact/http://www.mikroe.com/en/books/picbook/0_Uvod.htmhttp://www.mikroe.com/en/books/picbook/0_Uvod.htmhttp://www.mikroe.com/en/books/picbook/2_01chapter.htmhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#Introduction%23Introductionhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#History%23Historyhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#Microcontrollers%20versus%20Microprocessors%23Microcontrollers%20versus%20Microprocessorshttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.1%20Memory%20unit%231.1%20Memory%20unithttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.2%20Central%20Processing%20Unit%231.2%20Central%20Processing%20Unithttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.3%20Bus%231.3%20Bushttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.4%20Input-output%20unit%231.4%20Input-output%20unithttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.5%20Serial%20communication%231.5%20Serial%20communicationhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.6%20Timer%20unit%231.6%20Timer%20unithttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.7%20Watchdog%231.7%20Watchdoghttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.8%20Analog-Digital%20Converter%231.8%20Analog-Digital%20Converterhttp://www.mikroe.com/en/books/picbook/1_chapter.htm#1.9%20Program%231.9%20Program

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    2/9

    company )$o $ad no idea )$at treasure t$ey $ad. :uring t$at year t$ere appeared on t$e mar0et a

    microprocessor called 4

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    3/9

    needed *or its application +ecause all necessary perip$erals are already +uilt into it. !$us )e save t$e time

    and space needed to construct devices.

    1.1 Memory unit

    Memory is part o* t$e microcontroller )$ose *unction is to store data.!$e easiest )ay to eplain it is to descri+e it as one +ig closet )it$ lots o* dra)ers. I* )e suppose t$at )emar0ed t$e dra)ers in suc$ a )ay t$at t$ey can not +e con*used any o* t$eir contents )ill t$en +e easilyaccessi+le. It is enoug$ to 0no) t$e designation o* t$e dra)er and so its contents )ill +e 0no)n to us *or sure.

    Memory components are eactly li0e t$at. /or a certain input )e get t$e contents o* a certain addressedmemory location and t$at;s all. !)o ne) concepts are +roug$t to us@ addressing and memory location. Memoryconsists o* all memory locations and addressing is not$ing +ut selecting one o* t$em. !$is means t$at )e needto select t$e desired memory location on one $and and on t$e ot$er $and )e need to )ait *or t$e contents o*t$at location. Beside reading *rom a memory location memory must also provide *or )riting onto it. !$is isdone +y supplying an additional line called control line. #e )ill designate t$is line as E# 8readE)rite9. Control

    line is used in t$e *ollo)ing )ay@ i* rE)F1 reading is done and i* opposite is true t$en )riting is done on t$e

    memory location. Memory is t$e *irst element and )e need a *e) operation o* our microcontroller .

    1.2 Central Processing Unit 

    7et add 3 more memory locations to a speci*ic +loc0 t$at )ill $ave a +uilt in capa+ility to multiply divide

    su+tract and move its contents *rom one memory location onto anot$er. !$e part )e ust added in is calledGcentral processing unitG 8C(9. Its memory locations are called registers.

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    4/9

    egisters are t$ere*ore memory locations )$ose role is to $elp )it$ per*orming various mat$ematical

    operations or any ot$er operations )it$ data )$erever data can +e *ound. 7oo0 at t$e current situation. #e$ave t)o independent entities 8memory and C(9 )$ic$ are interconnected and t$us any ec$ange o* data is

    $indered as )ell as its *unctionality. I* *or eample )e )is$ to add t$e contents o* t)o memory locations andreturn t$e result again +ac0 to memory )e )ould need a connection +et)een memory and C(. Simplystated )e must $ave some G)ayG t$roug$ data goes *rom one +loc0 to anot$er.

    1.3 Bus

    !$at G)ayG is called G+usG. ($ysically it represents a group o* % 1 or more )ires!$ere are t)o types o* +uses@ address and data +us. !$e *irst one consists o* as many lines as t$e amount o*

    memory )e )is$ to address and t$e ot$er one is as )ide as data in our case % +its or t$e connection line./irst one serves to transmit address *rom C( memory and t$e second to connect all +loc0s inside t$e

    microcontroller.

    &s *ar as *unctionality t$e situation $as improved +ut a ne) pro+lem $as also appeared@ )e $ave a unit t$at;scapa+le o* )or0ing +y itsel* +ut )$ic$ does not $ave any contact )it$ t$e outside )orld or )it$ us In order toremove t$is de*iciency let;s add a +loc0 )$ic$ contains several memory locations )$ose one end is connectedto t$e data +us and t$e ot$er $as connection )it$ t$e output lines on t$e microcontroller )$ic$ can +e seen

    as pins on t$e electronic component.

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    5/9

    1.4 Input-output unit

    !$ose locations )e;ve ust added are called GportsG. !$ere are several types o* ports @ input output or+idiectional ports. #$en )or0ing )it$ ports *irst o* all it is necessary to c$oose )$ic$ port )e need to )or0

    )it$ and t$en to send data to or ta0e it *rom t$e port.

    #$en )or0ing )it$ it t$e port acts li0e a memory location. Somet$ing is simply +eing )ritten into or read *romit and it could +e noticed on t$e pins o* t$e microcontroller.

    1. !erial communication

    Beside stated a+ove )e;ve added to t$e already eisting unit t$e possi+ility o* communication )it$ an outside)orld. Ho)ever t$is )ay o* communicating $as its dra)+ac0s. ne o* t$e +asic dra)+ac0s is t$e num+er o*

    lines )$ic$ need to +e used in order to trans*er data. #$at i* it is +eing trans*erred to a distance o* several

    0ilometers !$e num+er o* lines times num+er o* 0ilometers doesn;t promise t$e economy o* t$e proect. Itleaves us $aving to reduce t$e num+er o* lines in suc$ a )ay t$at )e don;t lessen its *unctionality. Suppose)e are )or0ing )it$ t$ree lines only and t$at one line is used *or sending data ot$er *or receiving and t$e

    t$ird one is used as a re*erence line *or +ot$ t$e input and t$e output side. In order *or t$is to )or0 )e needto set t$e rules o* ec$ange o* data. !$ese rules are called protocol. (rotocol is t$ere*ore de*ined in advance sot$ere )ouldn;t +e any misunderstanding +et)een t$e sides t$at are communicating )it$ eac$ ot$er. /oreample i* one man is spea0ing in /renc$ and t$e ot$er in 6nglis$ it is $ig$ly unli0ely t$at t$ey )ill ,uic0lyand e**ectively understand eac$ ot$er. 7et;s suppose )e $ave t$e *ollo)ing protocol. !$e logical unit G1G is setup on t$e transmitting line until trans*er +egins. nce t$e trans*er starts )e lo)er t$e transmission line to

    logical G

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    6/9

    &s )e $ave separate lines *or receiving and sending it is possi+le to receive and send data 8in*o.9 at t$e same

    time. So called *ull-duple mode +loc0 )$ic$ ena+les t$is )ay o* communication is called a serialcommunication +loc0. nli0e t$e parallel transmission data moves $ere +it +y +it or in a series o* +its )$at

    de*ines t$e term serial communication comes *rom. &*ter t$e reception o* data )e need to read it *rom t$ereceiving location and store it in memory as opposed to sending )$ere t$e process is reversed. :ata goes *rommemory t$roug$ t$e +us to t$e sending location and t$en to t$e receiving unit according to t$e protocol.

    1." #imer unit

    Since )e $ave t$e serial communication eplained )e can receive send and process data.

    Ho)ever in order to utili?e it in industry )e need a *e) additionally +loc0s. ne o* t$ose is t$e timer +loc0)$ic$ is signi*icant to us +ecause it can give us in*ormation a+out time duration protocol etc. !$e +asic unit o* 

    t$e timer is a *ree-run counter )$ic$ is in *act a register )$ose numeric value increments +y one in evenintervals so t$at +y ta0ing its value during periods !1 and !2 and on t$e +asis o* t$eir di**erence )e can

    determine $o) muc$ time $as elapsed. !$is is a very important part o* t$e microcontroller )$oseunderstanding re,uires most o* our time.

    1.$ %atc&dog

    ne more t$ing is re,uiring our attention is a *la)less *unctioning o* t$e microcontrollerduring its run-time. Suppose t$at as a result o* some inter*erence 8)$ic$ o*ten does occur in industry9 ourmicrocontroller stops eecuting t$e program or )orse it starts )or0ing incorrectly.

    * course )$en t$is $appens )it$ a computer )e simply reset it and it )ill 0eep )or0ing. Ho)ever t$ere is no

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    7/9

    reset +utton )e can pus$ on t$e microcontroller and t$us solve our pro+lem. !o overcome t$is o+stacle )e

    need to introduce one more +loc0 called )atc$dog. !$is +loc0 is in *act anot$er *ree-run counter )$ere ourprogram needs to )rite a ?ero in every time it eecutes correctly. In case t$at program gets Gstuc0G ?ero )ill

    not +e )ritten in and counter alone )ill reset t$e microcontroller upon ac$ieving its maimum value. !$is )illresult in eecuting t$e program again and correctly t$is time around. !$at is an important element o* everyprogram to +e relia+le )it$out man;s supervision.

     

    1.' (nalog to )igital Converter 

    &s t$e perip$eral signals usually are su+stantially di**erent *rom t$e ones t$at microcontroller can understand8?ero and one9 t$ey $ave to +e converted into a pattern )$ic$ can +e compre$ended +y a microcontroller. !$istas0 is per*ormed +y a +loc0 *or analog to digital conversion or +y an &:C. !$is +loc0 is responsi+le *orconverting an in*ormation a+out some analog value to a +inary num+er and *or *ollo) it t$roug$ to a C( +loc0

    so t$at C( +loc0 can *urt$er process it.

    /innaly t$e microcontroller is no) completed and all )e need to do no) is to assem+le it into an electronic

    component )$ere it )ill access inner +loc0s t$roug$ t$e outside pins. !$e picture +elo) s$o)s )$at amicrocontroller loo0s li0e inside.

     

    Physical configuration of the interior of a microcontroller 

    !$in lines )$ic$ lead *rom t$e center to)ards t$e sides o* t$e microcontroller represent )ires connecting inner+loc0s )it$ t$e pins on t$e $ousing o* t$e microcontroller so called +onding lines. C$art on t$e *ollo)ing pagerepresents t$e center section o* a microcontroller.

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    8/9

    Microcontroller outline with its basic elements and internal connections 

    /or a real application a microcontroller alone is not enoug$. Beside a microcontroller )e need a program t$at)ould +e eecuted and a *e) more elements )$ic$ ma0e up a inter*ace logic to)ards t$e elements o*regulation 8)$ic$ )ill +e discussed in later c$apters9.

    1.* Program

    (rogram )riting is a special *ield o* )or0 )it$ microcontrollers and is called GprogrammingG. !ry to )rite a small

    program in a language t$at )e )ill ma0e up ourselves *irst and t$en )ould +e understood +y anyone.

    ST!T!"#IST"!$%M"M&!' (&CTI&N)

    !"#IST"!*%M"M&!' (&CTI&N)+P&!T%!"#IST"!$ , !"#IST"!*

    "N

  • 8/15/2019 PIC Microcontrollers Chap Introduct

    9/9

    !$e program adds t$e contents o* t)o memory locations and vie)s t$eir sum on port &. !$e *irst line o* t$e

    program stands *or moving t$e contents o* memory location G&G into one o* t$e registers o* central processingunit. &s )e need t$e ot$er data as )ell )e )ill also move it into t$e ot$er register o* t$e central processing

    unit. !$e net instruction instructs t$e central processing unit to add t$e contents o* t$ose t)o registers andsend a result to port & so t$at sum o* t$at addition )ould +e visi+le to t$e outside )orld. /or a more complepro+lem program t$at )or0s on its solution )ill +e +igger.(rogramming can +e done in several languages suc$ as &ssem+ler C and Basic )$ic$ are most commonly usedlanguages. &ssem+ler +elongs to lo)er level languages t$at are programmed slo)ly +ut ta0e up t$e leastamount o* space in memory and gives t$e +est results )$ere t$e speed o* program eecution is concerned. &sit is t$e most commonly used language in programming microcontrollers it )ill +e discussed in a later c$apter.(rograms in C language are easier to +e )ritten easier to +e understood +ut are slo)er in eecuting *rom

    assem+ler programs. Basic is t$e easiest one to learn and its instructions are nearest a man;s )ay o*reasoning +ut li0e C programming language it is also slo)er t$an assem+ler. In any case +e*ore you ma0e up

    your mind a+out one o* t$ese languages you need to consider care*ully t$e demands *or eecution speed *ort$e si?e o* memory and *or t$e amount o* time availa+le *or its assem+ly.&*ter t$e program is )ritten )e )ould install t$e microcontroller into a device and run it. In order to do t$is)e need to add a *e) more eternal components necessary *or its )or0. /irst )e must give li*e to a

    microcontroller +y connecting it to a po)er supply 8po)er needed *or operation o* all electronic instruments9and oscillator )$ose role is similar to t$e role t$at $eart plays in a $uman +ody. Based on its cloc0smicrocontroller eecutes instructions o* a program. &s it receives supply microcontroller )ill per*orm a smallc$ec0 up on itsel* loo0 up t$e +eginning o* t$e program and start eecuting it. Ho) t$e device )ill )or0

    depends on many parameters t$e most important o* )$ic$ is t$e s0ill*ulness o* t$e developer o* $ard)areand on programmer;s epertise in getting t$e maimum out o* t$e device )it$ $is program.

    Previous page Table of contents Next page

      © Copyright 2003. mikroElektronika. All ights eserved. !or any comments contact "e#master .

    http://www.mikroe.com/en/books/picbook/0_Uvod.htmhttp://www.mikroe.com/en/books/picbook/2_01chapter.htmmailto:[email protected]:[email protected]://www.mikroe.com/en/books/picbook/0_Uvod.htmhttp://www.mikroe.com/en/books/picbook/0_Uvod.htmhttp://www.mikroe.com/en/books/picbook/2_01chapter.htmmailto:[email protected]