Architecture and Programming of 8051 MC1_1

download Architecture and Programming of 8051 MC1_1

of 13

Transcript of Architecture and Programming of 8051 MC1_1

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    1/13

    Architecture and programming of 8051 MCU's TOC

    Chapter 1

    Chapter 2

    Chapter 3

    Chapter 4 Chapter 5

    Chapter 6

    Chapter 7

    Chapter1: Introduction to Microcontrollers

    1.1 What are microcontrollers and what are they used for?

    1.2 What is what in microcontroller?

    Introduction

    It was electricity in the beginning....The people were happy because they did not know that it was all around them and

    could be utilized. That was good. Then Faraday came and a stone has started to roll slowly...

    The first machines using a new sort of energy appeared soon. long time has passed since then and !ust when the

    people finally got used to them and stopped paying attention to what a new generation of specialists were doing"

    someone came to an idea that electrons could be a #ery con#enient toy being closed in a glass pipe. It was !ust a

    good idea at first" but there was no return. $lectonics was born and the stone kept on rolling down the hill faster and

    faster...

    new science % new specialists. &lue coats were replaced with white ones and people who knew something about

    electronics appeared on the stage. While the rest of humanity were passi#ely watching in disbelief what was going

    on" the plotters split in two groups % 'software%oriented( and 'hardware%oriented(. )omewhat younger than their

    teachers" #ery enthusiastic and full of ideas" both of them kept on working but separate ways. While the first group

    was de#eloping constantly and gradually" the hardware%oriented people" dri#en by success" threw caution to the wind

    and in#ented transistors.

    *p till that moment" the things could be more or less kept under control" but a broad publicity was not aware of what

    was going on" which soon led to a fatal mistake+ &eing nai#e in belief that cheap tricks could slow down technology

    de#elopment and de#elopment of the world and retrie#e the good all days" mass market opened its doors for the

    products of $lectronics Industry" thus closing a magic circle. rapid drop in prices made these components a#ailable

    for a great #ariety of people. The stone was falling freely...

    The first integrated circuits and processors appeared soon" which caused computers and other products of

    electronics to drop down in price e#en more. They could be bought e#erywhere. nother circle was closed+ ,rdinary

    people got hold of computers and computer era has begun...

    http://www.mikroe.com/products/view/267/architecture-and-programming-of-8051-mcu-s/http://www.mikroe.com/chapters/view/64/chapter-1-introduction-to-microcontrollers/http://www.mikroe.com/chapters/view/65/chapter-2-8051-microcontroller-architecture/http://www.mikroe.com/chapters/view/66/chapter-3-the-8051-instruction-set/http://www.mikroe.com/chapters/view/67/chapter-4-at89s8253-microcontroller/http://www.mikroe.com/chapters/view/68/chapter-5-assembly-language/http://www.mikroe.com/chapters/view/69/chapter-6-examples/http://www.mikroe.com/chapters/view/70/chapter-7-development-systems/http://www.mikroe.com/chapters/view/64/chapter-1-introduction-to-microcontrollers/#ch1.1http://www.mikroe.com/chapters/view/64/chapter-1-introduction-to-microcontrollers/#ch1.2http://www.mikroe.com/chapters/view/64/chapter-1-introduction-to-microcontrollers/http://www.mikroe.com/chapters/view/65/chapter-2-8051-microcontroller-architecture/http://www.mikroe.com/chapters/view/66/chapter-3-the-8051-instruction-set/http://www.mikroe.com/chapters/view/67/chapter-4-at89s8253-microcontroller/http://www.mikroe.com/chapters/view/68/chapter-5-assembly-language/http://www.mikroe.com/chapters/view/69/chapter-6-examples/http://www.mikroe.com/chapters/view/70/chapter-7-development-systems/http://www.mikroe.com/chapters/view/64/chapter-1-introduction-to-microcontrollers/#ch1.1http://www.mikroe.com/chapters/view/64/chapter-1-introduction-to-microcontrollers/#ch1.2http://www.mikroe.com/products/view/267/architecture-and-programming-of-8051-mcu-s/
  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    2/13

    While this drama was going on" hobbyists and professionals" also split in two groups and protected by anonymity"

    were working hard on their pro!ects. Then" someone suddenly put a -uestion Why should not we make a uni#ersal

    component? cheap" uni#ersal integrated circuit that could be programmed and used in any field of electronics"

    de#ice or where#er needed? Technology has been de#eloped enough as well as the market. Why not? )o it

    happened" body and spirit were united and the first integrated circuit was designed and called the

    /I0,0,T,33$.

    1.1 What are microcontrollers and hat are the! used for"

    3ike all good things" this powerful component is basically #ery simple. It is made by mi4ing tested and high% -uality

    5ingredients5 6components7 as per following receipt

    1. The simplest computer processor is used as the 5brain5 of the future system.

    2. 8epending on the taste of the manufacturer" a bit of memory" a few 98 con#erters" timers"input9output lines etc. are added

    :. ll that is placed in some of the standard packages.

    ;. simple software able to control it all and which e#eryone can easily learn about has beende#eloped.

    ,n the basis of these rules" numerous types of microcontrollers were designed and they -uickly became manery low prices enable them to be embedded in such de#ices in which" until recent time it was not

    worthwhile to embed anything. Thanks to that" the world is o#erwhelmed today with cheapautomatic de#ices and #arious 'smart( appliences.

    =rior knowledge is hardly needed for programming. It is sufficient to ha#e a =0 6software in use is

    not demanding at all and is easy to learn7 and a simple de#ice 6called the programmer7 used for'loading( raedy%to%use programs into the microcontroller.

    )o" if you are infected with a #irus called electronics" there is nothing left for you to do but to learn how to use and

    control its power.

    #o does the microcontroller operate"

    $#en though there is a large number of different types of microcontrollers and e#en more programs created for their

    use only" all of them ha#e many things in common. Thus" if you learn to handle one of them you will be able to handle

    them all. typical scenario on the basis of which it all functions is as follows

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    3/13

    1. =ower supply is turned off and e#erything is stillthe program is loaded into the microcontroller"nothing indicates what is about to come

    2. =ower supply is turned on and e#erything starts to happen at high speed+ The control logic unitkeeps e#erything under control. It disables all other circuits e4cept -uartz crystal to operate. Whilethe preparations are in progress" the first milliseconds go by.

    :. =ower supply #oltage reaches its ma4imum and oscillator fre-uency becomes stable. )Fs are

    being filled with bits reflecting the state of all circuits within the microcontroller. ll pins areconfigured as inputs. The o#erall electronis starts operation in rhythm with pulse se-uence. Fromnow on the time is measured in micro and nanoseconds.

    ;. =rogram 0ounter is set to zero. Instruction from that address is sent to instruction decoder whichrecognizes it" after which it is e4ecuted with immediate effect.

    @. The #alue of the =rogram 0ounter is incremented by 1 and the whole process is repeated...se#eralmillion times per second.

    1.$ What is hat in the microcontroller"

    s you can see" all the operations within the microcontroller are performed at high speed and -uite simply" but the

    microcontroller itself would not be so useful if there are not special circuits which make it complete. In continuation"

    we are going to call your attention to them.

    %ead &nl! Memor! %&M(

    ead ,nly /emory 6,/7 is a type of memory used to permanently sa#e the program being e4ecuted. The size of

    the program that can be written depends on the size of this memory. ,/ can be built in the microcontroller or added

    as an e4ternal chip" which depends on the type of the microcontroller. &oth options ha#e some disad#antages. If

    ,/ is added as an e4ternal chip" the microcontroller is cheaper and the program can be considerably longer. t the

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    4/13

    same time" a number of a#ailable pins is reduced as the microcontroller uses its own input9output ports for connection

    to the chip. The internal ,/ is usually smaller and more e4pensi#e" but lea#es more pins a#ailable for connecting to

    peripheral en#ironment. The size of ,/ ranges from @12& to A;B&.

    %andom Access Memor! %AM(

    andom ccess /emory 6/7 is a type of memory used for temporary storing data and intermediate results

    created and used during the operation of the microcontrollers. The content of this memory is cleared once the power

    supply is off. For e4ample" if the program performes an addition" it is necessary to ha#e a register standing for what in

    e#eryday life is called the 'sum( . For that purpose" one of the registers in / is called the 5sum5 and used for

    storing results of addition. The size of / goes up to a few B&s.

    )lectricall! )rasa*le +rogramma*le %&M ))+%&M(

    The $$=,/ is a special type of memory not contained in all microcontrollers. Its contents may be changed during

    program e4ecution 6similar to / 7" but remains permanently sa#ed e#en after the loss of power 6similar to ,/7. It

    is often used to store #alues" created and used during operation 6such as calibration #alues" codes" #alues to count

    up to etc.7" which must be sa#ed after turning the power supply off. disad#antage of this memory is that the process

    of programming is relati#ely slow. It is measured in miliseconds.

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    5/13

    ,pecial -unction %egisters ,-%(

    )pecial function registers are part of / memory. Their purpose is predefined by the manufacturer and cannot be

    changed therefore. )ince their bits are physically connected to particular circuits within the microcontroller" such as

    98 con#erter" serial communication module etc." any change of their state directly affects the operation of the

    microcontroller or some of the circuits. For e4ample" writing zero or one to the )F controlling an input9output port

    causes the appropriate port pin to be configured as input or output. In other words" each bit of this register controls

    the function of one single pin.

    +rogram Counter

    =rogram 0ounter is an engine running the program and points to the memory address containing the ne4t instruction

    to e4ecute. fter each instruction e4ecution" the #alue of the counter is incremented by 1. For this reason" the

    program e4ecutes only one instruction at a time !ust as it is written. Cowe#erthe #alue of the program counter can

    be changed at any moment" which causes a '!ump( to a new memory location. This is how subroutines and branch

    instructions are e4ecuted. fter !umping" the counter resumes e#en and monotonous automatic counting D1" D1" D1

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    6/13

    Central +rocessor Unit C+U(

    s its name suggests" this is a unit which monitors and controls all processes within the microcontroller and the user

    cannot affect its work. It consists of se#eral smaller subunits" of which the most important are

    Instruction decoderis a part of the electronics which recognizes program instructions and runs

    other circuits on the basis of that. The abilities of this circuit are e4pressed in the 5instruction set5which is different for each microcontroller family.

    Arithmetical Logical Unit (ALU)performs all mathematical and logical operations upon data.

    Accumulatoris an )F closely related to the operation of 3*. It is a kind of working desk used

    for storing all data upon which some operations should be e4ecuted 6addition" shift etc.7. It alsostores the results ready for use in further processing. ,ne of the )Fs" called the )tatusegister" is closely related to the accumulator" showing at any gi#en time the 5status5 of anumber stored in the accumulator 6the number is greater or less than zero etc.7.

    A *itis !ust a word in#ented to confuse no#ices at electronics. Eoking aside" this word in practice indicates whether

    the #oltage is present on a conductor or not. If it is present" the approprite pin is set to logic one 617" i.e. the bits #alue

    is 1. ,therwise" if the #oltage is G >" the appropriate pin is cleared 6G7" i.e. the bits #alue is G. It is more complicated in

    theory where a bit is referred to as a binary digit" but e#en in this case" its #alue can be either G or 1.

    Inputoutput ports I& +orts(

    In order to make the microcontroller useful" it is necessary to connect it to peripheral de#ices. $ach microcontroller

    has one or more registers 6called a port7 connected to the microcontroller pins.

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    7/13

    Why do we call them input9output ports? &ecause it is possible to change a pin function according to the user

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    8/13

    each instruction is e4ecuted in se#eral steps. For some microcontrollers" the same number of cycles is needed to

    e4ecute any instruction" while it

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    9/13

    A registeror a memory cell is an electronic circuit which can memorize the state of one byte. &esides H bits a#ailable

    to the user" each register has also a number of addressing bits. It is important to remember that

    ll registers of ,/ as well as those of / referred to as general%purpose registers are

    mutually e-ual and nameless. 8uring programming" each of them can be assigned a name"which makes the whole operation much easier.

    ll )Fs are assigned names which are different for different types of the microcontrollers and

    each of them has a special function as their name suggests.Watchdog timer

    The Watchdog Timer is a timer connected to a completely separate 0 oscillator within the microcontroller.

    If the watchdog timer is enabled" e#ery time it counts up to the program end" the microcontroller reset occurs and

    program e4ecution starts from the first instruction. The point is to pre#ent this from happening by using a special

    command. The whole idea is based on the fact that e#ery program is e4ecuted in se#eral longer or shorter loops.

    If instructions resetting the watchdog timer are set at the appropriate program locations" besides commands being

    regularly e4ecuted" then the operation of the watchdog timer will not affect the program e4ecution.

    If for any reason 6usually electrical noise in industry7" the program counter 5gets stuck5 at some memory location from

    which there is no return" the watchdog will not be cleared" so the registers #alue being constantly incremented will

    reach the ma4imum et #oila+ eset occurs+

    +oer ,uppl! Circuit

    There are two things worth attention concerning the microcontroller power supply circuit

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    10/13

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    11/13

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    12/13

  • 8/10/2019 Architecture and Programming of 8051 MC1_1

    13/13

    table of contentsne4t chapterJ

    -eatured 2e3elopment /ools)as!8051 34 2e3elopment ,!stem

    The)as!8051 34is compatible with 1;%" 1A%" 2G%" 2H%" ;G%pin =300;; and =300:2 /0*s. It comes with an THK)H2@:.

    The board has a *)& 2.G programmer and many peripherals such as 0,L" port e4pander" /$* and ;4; keypads etc.

    Mmore infoN

    miro+rog for 8051

    mikro=rogO for HG@1 is supported with mikro0O" mikro&asicO and mikro=ascalO compilers for HG@1. Pou may also use

    mikro=rogO for HG@1 as a standalone programming tool. Mmore infoN

    -eatured Compilersmiroasic +%& for 8051

    http://www.mikroe.com/products/view/267/architecture-and-programming-of-8051-mcu-s/http://www.mikroe.com/chapters/view/65/chapter-2-8051-microcontroller-architecture/http://www.mikroe.com/chapters/view/65/chapter-2-8051-microcontroller-architecture/http://www.mikroe.com/easy8051/http://www.mikroe.com/easy8051/http://www.mikroe.com/easy8051/http://www.mikroe.com/mikroprog/8051/http://www.mikroe.com/mikroprog/8051/http://www.mikroe.com/mikrobasic/8051/http://www.mikroe.com/mikroprog/8051/http://www.mikroe.com/easy8051/http://www.mikroe.com/products/view/267/architecture-and-programming-of-8051-mcu-s/http://www.mikroe.com/chapters/view/65/chapter-2-8051-microcontroller-architecture/http://www.mikroe.com/easy8051/http://www.mikroe.com/easy8051/http://www.mikroe.com/mikroprog/8051/http://www.mikroe.com/mikroprog/8051/http://www.mikroe.com/mikrobasic/8051/