+ All Categories
Home > Documents > Microcontroller Record 8051

Microcontroller Record 8051

Date post: 03-Apr-2018
Category:
Upload: netgalaxy2010
View: 253 times
Download: 1 times
Share this document with a friend

of 50

Transcript
  • 7/28/2019 Microcontroller Record 8051

    1/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    VIT UNIVERSITY

    SCHOOL OF ELECTRICAL ENGINEERING

    SUB CODE: EEE 303L

    MICROCONTROLLER & ITS APPLICATIONS

    LAB MANUAL

    Name:

    Slot:

    Faculty In-charge:

    Day: Lab system no:

    Student DetailsReg.No.:

  • 7/28/2019 Microcontroller Record 8051

    2/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    SCHOOL OF ELECTRICAL ENGINEERING

    EEE 303L Microcontroller & its Applications Lab

    Certified that this is a bonafide of record work done by

    Registration number of

    B.Tech EEE/ EIE during the academic year 2012 13 at VIT University.

    This record submitted for the practical examination conducted on

    .

    Date: Faculty In charge

    Examiner 1 Examiner - 2

  • 7/28/2019 Microcontroller Record 8051

    3/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    INDEX

    S.No Date Name of the Experiment Marks Sign with

    Date

  • 7/28/2019 Microcontroller Record 8051

    4/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    1.STUDY OF 8051 MICROCONTROLLER

    Architecture of 8051 microcontroller has following features

    4 Kb of ROM is not much at all. 128Kb of RAM (including SFRs) satisfies the user's basic needs. 4 ports having in total of 32 input/output lines are in most cases sufficient to

    make all necessary connections to peripheral environment.

    The whole configuration is obviously thought of as to satisfy the needs of mostprogrammers working on development of automation devices. One of its advantagesis that nothing is missing and nothing is too much. In other words, it is createdexactly in accordance to the average users taste and needs. Other advantages areRAM organization, the operation of Central Processor Unit (CPU) and ports whichcompletely use all recourses and enable further upgrade.

  • 7/28/2019 Microcontroller Record 8051

    5/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Pin out Descript ion

    Pins 1-8: Port 1 each of these pins can be configured as an input or an output.

    Pin 9: RS A logic one on this pin disables the microcontroller and clears the contentsof most registers. In other words, the positive voltage on this pin resets themicrocontroller. By applying logic zero to this pin, the program starts execution fromthe beginning.

    Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or

    output. Besides, all of them have alternative functions:

    Pin 10: RXD Serial asynchronous communication input or Serial synchronouscommunication output.

    Pin 11: TXD Serial asynchronous communication output or Serial synchronouscommunication clock output.

    Pin 12: INT0 Interrupt 0 inputs.

    Pin 13: INT1 Interrupt 1 input.

    Pin 14: T0 Counter 0 clock input.

    Pin 15: T1 Counter 1 clock input.

    Pin 16: WR Write to external (additional) RAM.

    Pin 17: RD Read from external RAM.

  • 7/28/2019 Microcontroller Record 8051

    6/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Pin 18, 19: X2, X1 Internal oscillator input and output. A quartz crystal whichspecifies operating frequency is usually connected to these pins. Instead of it,miniature ceramics resonators can also be used for frequency stability. Laterversions of microcontrollers operate at a frequency of 0 Hz up to over 50 Hz.

    Pin 20: GND Ground.

    Pin 21-28: Port 2 If there is no intention to use external memory then these port pinsare configured as general inputs/outputs. In case external memory is used, thehigher address byte, i.e. addresses A8-A15 will appear on this port. Even thoughmemory with capacity of 64Kb is not used, which means that not all eight port bitsare used for its addressing, the rest of them are not available as inputs/outputs.

    Pin 29: PSEN If external ROM is used for storing program then a logic zero (0)

    appears on it every time the microcontroller reads a byte from memory.

    Pin 30: ALE Prior to reading from external memory, the microcontroller puts the

    lower address byte (A0-A7) on P0 and activates the ALE output. After receivingsignal from the ALE pin, the external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and uses it as a memory chip address.Immediately after that, the ALU pin is returned its previous logic state and P0 is nowused as a Data Bus. As seen, port data multiplexing is performed by means of onlyone additional (and cheap) integrated circuit. In other words, this port is used for bothdata and address transmission.

    Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data andaddress transmission with no regard to whether there is internal memory or not. Itmeans that even there is a program written to the microcontroller, it will not beexecuted. Instead, the program written to external ROM will be executed. By

    applying logic one to the EA pin, the microcontroller will use both memories, firstinternal then external (if exists).

    Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can beused as general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when the ALEpin is driven low (0).

    Pin 40: VCC +5V power supply.

    Input/Output Ports (I/O Ports)

    All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can beconfigured as inputs or outputs. Accordingly, in total of 32 input/output pins enablingthe microcontroller to be connected to peripheral devices are available for use.

    Pin configuration, i.e. whether it is to be configured as an input (1) or an output (0),depends on its logic state. In order to configure a microcontroller pin as an input, it isnecessary to apply a logic zero (0) to appropriate I/O port bit. In this case, voltagelevel on appropriate pin will be 0.

  • 7/28/2019 Microcontroller Record 8051

    7/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Similarly, in order to configure a microcontroller pin as an input, it is necessary toapply a logic one (1) to appropriate port. In this case, voltage level on appropriate pinwill be 5V (as is the case with any TTL input). This may seem confusing but don'tloose your patience. It all becomes clear after studying simple electronic circuitsconnected to an I/O pin.

    Port 0

    The P0 port is characterized by two functions. If external memory is used then thelower address byte (addresses A0-A7) is applied on it. Otherwise, all bits of this portare configured as inputs/outputs.

    The other function is expressed when it is configured as an output. Unlike other portsconsisting of pins with built-in pull-up resistor connected by its end to 5 V powersupply, pins of this port have this resistor left out. This apparently small differencehas its consequences:

  • 7/28/2019 Microcontroller Record 8051

    8/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    If any pin of this port is configured as an input then it acts as if it floats. Such aninput has unlimited input resistance and in determined potential.

    When the pin is configured as an output, it acts as an open drain. By applying logic0 to a port bit, the appropriate pin will be connected to ground (0V). By applying logic1, the external output will keep on floating. In order to apply logic 1 (5V) on thisoutput pin, it is necessary to built in an external pull-up resistor.

    Port 1

    P1 is a true I/O port, because it doesn't have any alternative functions as is the casewith P0, but can be cofigured as general I/O only. It has a pull-up resistor built-in andis completely compatible with TTL circuits.

    Port 2

    P2 acts similarly to P0 when external memory is used. P ins of this port occupyaddresses intended for external memory chip. This time it is about the higheraddress byte with addresses A8-A15. When no memory is added, this port can be

    used as a general input/output port showing features similar to P1.

    Port 3

    All port pins can be used as general I/O, but they also have an alternative function.In order to use these alternative functions, a logic one (1) must be applied toappropriate bit of the P3 register. In tems of hardware, this port is similar to P0, withthe difference that its pins have a pull-up resistor built-in.

  • 7/28/2019 Microcontroller Record 8051

    9/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Memory Organization

    The 8051 has two types of memory and these are Program Memory and DataMemory. Program Memory (ROM) is used to permanently save the program beingexecuted, while Data Memory (RAM) is used for temporarily storing data andintermediate results created and used during the operation of the microcontroller.

    Depending on the model in use (we are still talking about the 8051 microcontrollerfamily in general) at most a few Kb of ROM and 128 or 256 bytes of RAM is used.However

    All 8051 microcontrollers have a 16-bit addressing bus and are capable ofaddressing 64 kb memory. It is neither a mistake nor a big ambition of engineerswho were working on basic core development. It is a matter of smart memoryorganization which makes these microcontrollers a real programmers goody.

    Program Memory

    The first models of the 8051 microcontroller family did not have internal program

    memory. It was added as an external separate chip. These models are recognizableby their label beginning with 803 (for example 8031 or 8032). All later models have afew Kbyte ROM embedded. Even though such an amount of memory is sufficient forwriting most of the programs, there are situations when it is necessary to useadditional memory as well. A typical example are so called lookup tables. They areused in cases when equations describing some processes are too complicated orwhen there is no time for solving them. In such cases all necessary estimates andapproximates are executed in advance and the final results are put in the tables(similar to logarithmic tables).

    How does the microcontroller handle external memory depends on the EA pin logicstate:

  • 7/28/2019 Microcontroller Record 8051

    10/50

  • 7/28/2019 Microcontroller Record 8051

    11/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    this block contains in total of 128 bits with separate addresses (address of bit 0 ofthe 20h byte is 0, while address of bit 7 of the 2Fh byte is 7Fh). The third group ofregisters occupies addresses 2Fh-7Fh, i.e. 80 locations, and does not have anyspecial functions or features.

    Addi tional RAM

    In order to satisfy the programmers constant hunger for Data Memory, themanufacturers decided to embed an additional memory block of 128 locations intothe latest versions of the 8051 microcontrollers. However, its not as simple as itseems to be The problem is that electronics performing addressing has 1 byte (8bits) on disposal and is capable of reaching only the first 256 locations, therefore. Inorder to keep already existing 8-bit architecture and compatibility with other existingmodels a small trick was done.

    What does it mean? It means that additional memory block shares the sameaddresses with locations intended for the SFRs (80h- FFh). In order to differentiatebetween these two physically separated memory spaces, different ways of

    addressing are used. The SFRs memory locations are accessed by directaddressing, while additional RAM memory locations are accessed by indirectaddressing.

  • 7/28/2019 Microcontroller Record 8051

    12/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Special Function Registers (SFRs)

    Special Function Registers (SFRs) are a sort of control table used for running andmonitoring the operation of the microcontroller. Each of these registers as well aseach bit they include, has its name, address in the scope of RAM and preciselydefined purpose such as timer control, interrupt control, serial communication control

    etc. Even though there are 128 memory locations intended to be occupied by them,the basic core, shared by all types of 8051 microcontrollers, has only 21 suchregisters. Rest of locations are intensionally left unoccupied in order to enable themanufacturers to further develop microcontrollers keeping them compatible with theprevious versions. It also enables programs written a long time ago formicrocontrollers which are out of production now to be used today.

    A Regis ter (Accumulator)

    A register is a general-purpose register used for storing intermediate results obtainedduring operation. Prior to executing an instruction upon any number or operand it isnecessary to store it in the accumulator first. All results obtained from arithmetical

    operations performed by the ALU are stored in the accumulator. Data to be movedfrom one register to another must go through the accumulator. In other words, the Aregister is the most commonly used register and it is impossible to imagine amicrocontroller without it. More than half instructions used by the 8051microcontroller use somehow the accumulator.

  • 7/28/2019 Microcontroller Record 8051

    13/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    B Register

    Multiplication and division can be performed only upon numbers stored in the A andB registers. All other instructions in the program can use this register as a spareaccumulator (A).

    During the process of writing a program, each register is called by its name so that their

    exact addresses are not of importance for the user. During compilation, their names will be

    automatically replaced by appropriate addresses.

    R Registers (R0-R7)

    This is a common name for 8 general-purpose registers (R0, R1, R2 ...R7). Eventhough they are not true SFRs, they deserve to be discussed here because of theirpurpose. They occupy 4 banks within RAM. Similar to the accumulator, they areused for temporary storing variables and intermediate results during operation.

    Which one of these banks is to be active depends on two bits of the PSW Register.Active bank is a bank the registers of which are currently used.

    Program Status Word (PSW) Register

  • 7/28/2019 Microcontroller Record 8051

    14/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    PSW register is one of the most important SFRs. It contains several status bits thatreflect the current state of the CPU. Besides, this register contains Carry bit,Auxiliary Carry, two register bank select bits, Overflow flag, parity bit and user-definable status flag.

    P - Parity bit. If a number stored in the accumulator is even then this bit will be

    automatically set (1), otherwise it will be cleared (0). It is mainly used during datatransmit and receive via serial communication.

    - Bit 1. This bit is intended to be used in the future versions of microcontrollers.

    OV Overflow occurs when the result of an arithmetical operation is larger than 255and cannot be stored in one register. Overflow condition causes the OV bit to be set(1). Otherwise, it will be cleared (0).

    RS0, RS1 - Register bank select bi ts. These two bits are used to select one of fourregister banks of RAM. By setting and clearing these bits, registers R0-R7 are storedin one of four banks of RAM.

    RS1 RS2Space in

    RAM

    0 0Bank0 00h-

    07h

    0 1Bank1 08h-

    0Fh

    1 0

    Bank2 10h-

    17h

    1 1Bank3 18h-

    1Fh

    F0 - Flag 0. This is a general-purpose bit available for use.

    AC - Auxil iary Carry Flag is used for BCD operations only.

    CY - Carry Flag is the (ninth) auxiliary bit used for all arithmetical operations and

    shift instructions.

    Data Pointer Register (DPTR)

    DPTR register is not a true one because it doesn't physically exist. It consists of twoseparate registers: DPH (Data Pointer High) and (Data Pointer Low). For this reasonit may be treated as a 16-bit register or as two independent 8-bit registers. Their 16bits are primarly used for external memory addressing. Besides, the DPTR Registeris usually used for storing data and intermediate results.

  • 7/28/2019 Microcontroller Record 8051

    15/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Stack Pointer (SP) Regis ter

    A value stored in the Stack Pointer points to the first free stack address and permitsstack availability. Stack pushes increment the value in the Stack Pointer by 1.Likewise, stack pops decrement its value by 1. Upon any reset and power-on, thevalue 7 is stored in the Stack Pointer, which means that the space of RAM reserved

    for the stack starts at this location. If another value is written to this register, theentire Stack is moved to the new memory location.

    P0, P1, P2, P3 - Input/Output Registers

    If neither external memory nor serial communication system are used then 4 portswith in total of 32 input/output pins are available for connection to peripheralenvironment. Each bit within these ports affects the state and performance ofappropriate pin of the microcontroller. Thus, bit logic state is reflected on appropriatepin as a voltage (0 or 5 V) and vice versa, voltage on a pin reflects the state ofappropriate port bit.

    As mentioned, port bit state affects performance of port pins, i.e. whether they will beconfigured as inputs or outputs. If a bit is cleared (0), the appropriate pin will beconfigured as an output, while if it is set (1), the appropriate pin will be configured asan input. Upon reset and power-on, all port bits are set (1), which means that allappropriate pins will be configured as inputs.

  • 7/28/2019 Microcontroller Record 8051

    16/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Counters and Timers

    As you already know, the microcontroller oscillator uses quartz crystal for itsoperation. As the frequency of this oscillator is precisely defined and very stable,pulses it generates are always of the same width, which makes them ideal for timemeasurement. Such crystals are also used in quartz watches. In order to measure

    time between two events it is sufficient to count up pulses coming from this oscillator.That is exactly what the timer does. If the timer is properly programmed, the valuestored in its register will be incremented (or decremented) with each coming pulse,i.e. once per each machine cycle. A single machine-cycle instruction lasts for 12quartz oscillator periods, which means that by embedding quartz with oscillatorfrequency of 12MHz, a number stored in the timer register will be changed milliontimes per second, i.e. each microsecond.

    The 8051 microcontroller has 2 timers/counters called T0 and T1. As their namessuggest, their main purpose is to measure time and count external events. Besides,they can be used for generating clock pulses to be used in serial communication, socalled Baud Rate.

    Timer T0

    As seen in figure below, the timer T0 consists of two registers TH0 and TL0representing a low and a high byte of one 16-digit binary number.

    Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers itconsists of will contain 0. If the timer contains for example number 1000 (decimal),then the TH0 register (high byte) will contain the number 3, while the TL0 register(low byte) will contain decimal number 232.

    Formula used to calculate values in these two registers is very simple:TH0 256 + TL0 = T

  • 7/28/2019 Microcontroller Record 8051

    17/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Matching the previous example it would be as follows:3 256 + 232 = 1000

    Since the timer T0 is virtually 16-bit register, the largest value it can store is 65 535.In case of exceeding this value, the timer will be automatically cleared and countingstarts from 0. This condition is called an overflow. Two registers TMOD and TCONare closely connected to this timer and control its operation.

    TMOD Register (Timer Mode)

    The TMOD register selects the operational mode of the timers T0 and T1. As seen infigure below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 -bit7) refer to the timer 1. There are 4 operational modes and each of them isdescribed herein.

    Bits of this register have the following function:

    GATE1 enables and disables Timer 1 by means of a signal brought to the INT1 pin(P3.3):

    o 1 - Timer 1 operates only if the INT1 bit is set.o 0 - Timer 1 operates regardless of the logic state of the INT1 bit.

    C/T1 selects pulses to be counted up by the timer/counter 1:o 1 - Timer counts pulses brought to the T1 pin (P3.5).o 0 - Timer counts pulses from internal oscillator.

    T1M1,T1M0 These two bits select the operational mode of the Timer 1.

    T1M1 T1M0 Mode Description

    0 0 0 13-bit timer

    0 1 1 16-bit timer

    1 0 28-bit auto-

    reload

    1 1 3 Split mode

  • 7/28/2019 Microcontroller Record 8051

    18/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):o 1 - Timer 0 operates only if the INT0 bit is set.o 0 - Timer 0 operates regardless of the logic state of the INT0 bit.

    C/T0 selects pulses to be counted up by the timer/counter 0:o 1 - Timer counts pulses brought to the T0 pin (P3.4).o 0 - Timer counts pulses from internal oscillator.

    T0M1,T0M0 These two bits select the oprtaional mode of the Timer 0.

    T0M1 T0M0 Mode Description

    0 0 0 13-bit timer

    0 1 1 16-bit timer

    1 0 28-bit auto-

    reload

    1 1 3 Split mode

    Timer Control (TCON) Register

    TCON register is also one of the registers whose bits are directly in control of timeroperation.Only 4 bits of this register are used for this purpose, while rest of them is used forinterrupt control to be discussed later.

    TF1 bit is automatically set on the Timer 1 overflow. TR1 bit enables the Timer 1.

    o 1 - Timer 1 is enabled.o 0 - Timer 1 is disabled.

    TF0 bit is automatically set on the Timer 0 overflow. TR0 bit enables the timer 0.

    o 1 - Timer 0 is enabled.o 0 - Timer 0 is disabled.

    Timer 1

    Timer 1 is identical to timer 0, except for mode 3 which is a hold-count mode. Itmeans that they have the same function, their operation is controlled by the sameregisters TMOD and TCON and both of them can operate in one out of 4 differentmodes.

  • 7/28/2019 Microcontroller Record 8051

    19/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    2.7 UART (Universal Asynchronous Receiver and Transmitter)

    One of the microcontroller features making it so powerful is an integrated UART,better known as a serial port. It is a full-duplex port, thus being able to transmit andreceive data simultaneously and at different baud rates. Without it, serial data sendand receive would be an enormously complicated part of the program in which thepin state is constantly changed and checked at regular intervals. When using UART,all the programmer has to do is to simply select serial port mode and baud rate.When it's done, serial data transmit is nothing but writing to the SBUF register, whiledata receive represents reading the same register. The microcontroller takes care ofnot making any error during data transmission.

    Serial port must be configured prior to being used. In other words, it is necessary todetermine how many bits is contained in one serial word, baud rate andsynchronization clock source. The whole process is in control of the bits of theSCON register (Serial Control).

    Serial Port Control (SCON) Register

    SM0 - Serial port mode bit 0 is used for serial port mode selection. SM1 - Serial port mode bit 1. SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable

    bit. When set, it enables multiprocessor communication in mode 2 and 3, andeventually mode 1. It should be cleared in mode 0.

  • 7/28/2019 Microcontroller Record 8051

    20/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    REN - Reception Enable bit enables serial reception when set. When cleared, serialreception is disabled.

    TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problemof transmiting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th bit.

    RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware if9th bit received is a logic 0. Set by hardware if 9th bit received is a logic 1.

    TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byteis sent. It's a signal to the processor that the line is available for a new bytetransmite. It must be cleared from within the software.

    RI - Receive Interrupt flag is automatically set upon one byte receive. It signals thatbyte is received and should be read quickly prior to being replaced by a new data.This bit is also cleared from within the software.

    8051 Microcontroller Interrupts

    There are five interrupt sources for the 8051, which means that they can recognize 5different events that can interrupt regular program execution. Each interrupt can beenabled or disabled by setting bits of the IE register. Likewise, the whole interruptsystem can be disabled by clearing the EA bit of the same register. Refer to figure

    below.

    Now, it is necessary to explain a few details referring to external interrupts- INT0 andINT1. If the IT0 and IT1 bits of the TCON register are set, an interrupt will begenerated on high to low transition, i.e. on the falling pulse edge (only in thatmoment). If these bits are cleared, an interrupt will be continuously executed as faras the pins are held low.

    IE Register (Interrupt Enable)

    EA - global interrupt enable/disable:o 0 - disables all interrupt requests.o 1 - enables all individual interrupt requests.

    ES - enables or disables serial interrupt:o 0 - UART system cannot generate an interrupt.o 1 - UART system enables an interrupt.

    ET1 - bit enables or disables Timer 1 interrupt:o 0 - Timer 1 cannot generate an interrupt.o 1 - Timer 1 enables an interrupt.

    EX1 - bit enables or disables external 1 interrupt:o 0 - change of the pin INT0 logic state cannot generate an interrupt.o 1 - enables an external interrupt on the pin INT0 state change.

    ET0 - bit enables or disables timer 0 interrupt:o 0 - Timer 0 cannot generate an interrupt.o 1 - enables timer 0 interrupt.

    EX0 - bit enables or disables external 0 interrupt:o 0 - change of the INT1 pin logic state cannot generate an interrupt.o 1 - enables an external interrupt on the pin INT1 state change.

  • 7/28/2019 Microcontroller Record 8051

    21/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    IP Register (Interrupt Priority)

    The IP register bits specify the priority level of each interrupt (high or low priority).

    PS - Serial Port Interrupt priority bito Priority 0o Priority 1

    PT1 - Timer 1 interrupt priorityo Priority 0o Priority 1

    PX1 - External Interrupt INT1 priorityo Priority 0o Priority 1

    PT0 - Timer 0 Interrupt Priorityo Priority 0o Priority 1

    PX0 - External Interrupt INT0 Priorityo Priority 0o Priority 1

  • 7/28/2019 Microcontroller Record 8051

    22/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    SimulatingtheprogramusingKeiluVision3

    OpenKeiluVision3(Start>Programs>KeiluVision3)

    Start

    a

    new

    project

    (File>New>visionproject)

    o Giveaname,Save

    o SelectNxp>P89V51RD2

    ClickYeswhenaskedwhethertoCopyStandard8051StartupCodetoProjectFolderandAddFiletoProject.

    ClickYesifaskedFileSTARTUP.A51alreadyexists,overwrite?

  • 7/28/2019 Microcontroller Record 8051

    23/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Openanewfile(File>New>File)

    WritetherequiredProgram,Saveitwithanynamewithextension.asmandaddittothe

    groupSourceGroup1

    (Heretheprogramtakenasexampleistakingtheinputfromportanddisplayingitinport2)

    Translate,BuildandRebuildtargetfiles.

    Toverifytheworkingoftheprograminthesoftware:

    o ClickDebug>Start/StopDebugSession.o Enableviewingofportsbyclicking:Peripherals>I/Oports>o Giveanyvalueintheinputport(Here,port1)andverifyitintheoutputport

    (Here,port2)byclickingDebug>Run.

    Togenerate

    the

    hex

    file:

    o ClickoptionsforTargetbutton.

  • 7/28/2019 Microcontroller Record 8051

    24/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    o Inthedialogueboxthatappears,givethefollowingsettings:

    o UnderDevicetab,selectthesamefamily(P89V51RD2)

    o UnderTargettab,givethefrequencyofthecrystaloscillator

    used.(Here11.0592)andenableUseonchipROMoption.

    o UnderOutputtab,enableCreateHEXfileoption.

    o ClickOK.

    o ClickTranslate,BuildandRebuildandmakesurecreatinghexfilefrom

    isshown.

  • 7/28/2019 Microcontroller Record 8051

    25/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    2. ADDITION, SUBTRACTION, MULTIPLICATION AND DIVISION OF

    TWO 8-BIT NUMBERS

    AIM:

    To write an assembly language program to perform the Addition, Subtraction,

    Multiplication and Division of two sixteen bit numbers.

    ALGORITHM:

    a) Addition

    1. Load first no. in A register.2. Load second data in register.3. Add the A content with register content, Result in A Register

    Program:

    Sample Input Sample Output

  • 7/28/2019 Microcontroller Record 8051

    26/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    b) Subtraction

    1. Load first no. in A register.2. Load second data in register.3. Subtract the A content from register content, Result in A Register

    Program:

    Sample Input Sample Output

  • 7/28/2019 Microcontroller Record 8051

    27/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    c) Multiplication

    1. Get the first no. in A2. Get the second no. in B3. Multiply A &B .higher byte of result in B and lower byte of result in A

    Program:

    Sample Input Sample Output

  • 7/28/2019 Microcontroller Record 8051

    28/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    d) Division

    1. Get the first no. in A2. Get the second no. in B3. Divide A by B .Remainder in B and Quotient in A.

    Program:

    Sample Input Sample Output

    RESULT

  • 7/28/2019 Microcontroller Record 8051

    29/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    3. ADDITION OF TWO SIXTEEN BIT NUMBERS

    AIM:

    Write an assembly language program to add two sixteen bit numbers

    ALGORITHM:

    1. Load first 16-bit no. in DPTR2. Get the lower byte of second data in A& higher byte in B3. Add lower byte.4. Save result of lower byte Addition.5. Get higher byte of second number in A6. Add higher byte with carry from lower byte addition7. Save result of higher byte Addition

    Program:

    Sample Input Sample Output

    RESULT :

  • 7/28/2019 Microcontroller Record 8051

    30/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    4. TRANSFERRING A BLOCK OF DATA

    (a) FROM INTERNAL TO EXTERNAL MEMORY

    AIM:

    To transfer a block of data from internal RAM to external RAM

    ALGORITHM:

    1. Load internal RAM location.

    2. Get the count value and move it to registerR3

    3. Initialize DPTR for external memory.

    4. Increment the convert of R0

    5. Get the data from internal memory to accumulator

    6. Move accumulator content to external memory pointed by DPTR.

    7. Increment data pointer.

    8. Decrement the R3 content.

    9. Do the steps 4, 5, 6&7 until R3 content becomes 0.

    Program:

  • 7/28/2019 Microcontroller Record 8051

    31/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Sample Input Sample Output

    (b) FROM EXTERNAL TO INTERNAL MEMORY

    AIM:To transfer a block of data from external RAM to internal RAM

    ALGORITHM:

    1. Initialize data pointer.

    2. Get the count value from memory to accumulator.

    3. Move accumulator content to registerR3.

    4. Load the internal RAM address on Register R0.

    5. Increment DPTR and get the data from DPTR location to accumulator.

    6. Move accumulator content to internal location specified by register R0.

    7. Increment R0 content.

    8. Decrement the R3 content.

    9. Do the steps 5, 6, 7&8 until R3 content becomes 0.

    Program:

  • 7/28/2019 Microcontroller Record 8051

    32/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Sample Input Sample Output

  • 7/28/2019 Microcontroller Record 8051

    33/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    (c) FROM EXTERNAL TO EXTERNAL MEMORY

    AIM: To transfer a block of data from external memory to external memory.

    ALGORITHM:

    1. Initialize data pointer.

    2. Get the count value from DPTR location to accumulator.

    3. Move the content of accumulator registerR0.

    4. Load the external memory address of input on Register R1&R2.

    5. Load the external memory address of output on Register R3&R4.

    6. Move the content of R1 to DPH and R2 to DPL.

    7. Move the first data from data printer to accumulator.

    8. Move the content of R3 to DPH &R4 to DPL.

    9. Move the content of accumulator to external memory.

    10. Increment the content of R2&R4

    11. End the program.

    Program:

  • 7/28/2019 Microcontroller Record 8051

    34/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Sample Input Sample Output

    Result

  • 7/28/2019 Microcontroller Record 8051

    35/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    5. Generation of square wave

    AIM:

    Write an assembly language program to create a square wave of 50% duty cycle on

    bit 0, bit 3 of port 1

    ALGORITHM: for 50% duty cycle

    1. Set to high bit 0 of port12. Call the delay subroutine3. Clear port 1 of bit 04. Call the delay subroutine5. Repeat the from the first step

    Delay program algorithm

    Program:

  • 7/28/2019 Microcontroller Record 8051

    36/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Sample Input Sample Output

    RESULT :

  • 7/28/2019 Microcontroller Record 8051

    37/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    6. LED Switch Interface

    Aim:

    To write a program to interface the led/switch with the 8051.

    Algorithm:

    Program:

    Result:

  • 7/28/2019 Microcontroller Record 8051

    38/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    7.STEPPER MOTOR

    AIM:

    To write a program to run two stepper motors in clockwise direction and anticlockwise

    direction using 8051.

    Algori thm:

    1. In the control word register of 8255 in BSR mode.2. Move the first data in Port a.3. Call delay.4. Move the second data to Port A..5. Call delay.6. Move the third data to Port A.7. Call delay.8. Move the fourth data to Port A.9. Call delay.10. Repeat 2-9 steps.11. Terminate the program.

    Control Word Register:CWR

    Motor 1 ON : 1 A B 0

    Motor 2 ON : 0 1 A B

    1 0 0 0 0 1 0 0 - 84

    1 0 1 0 0 1 0 1 - A5

    1 1 1 0 0 1 1 1 - E7

    1 1 0 0 0 1 1 0 - C6

    1st motor Rating: E0 A0 80 C0

    2nd motor Rating 07 05 04 06

    Both motor Clockwise:

    E0 +07 = E7

    A0 +05 =A5

    80 +04 =84

    C0 +06 =C6

  • 7/28/2019 Microcontroller Record 8051

    39/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Both motor Anticlockwise :

    C0 +06 =C6

    80 +04 =84

    A0 +05 =A5

    E0 +07 =E7

    Clockwise and anticlockwise :

    E0 +06 =E6

    A0 +04 =A4

    80 +05 =85

    C0 +07 =C7

    Working Procedure for stepper motor:

    1. Connect the 5V supply to the trainer kit and stepper motor chord.2. Connect the +12V supply to the power bit wire (yellow color) in the chord.3. Connect the corresponding grounds.4. Connect the 26 pin FRC from the kit to the chord.5. Switch on the Power supply.6. Assemble the program and execute it.7. The stepper motor will start rotating either in clockwise or anticlockwise direction

    based on the order of the coil excitation.8. Switch off the power supply and remove all the connections

    Program:

  • 7/28/2019 Microcontroller Record 8051

    40/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Sample Input Sample Output

    RESULT:

  • 7/28/2019 Microcontroller Record 8051

    41/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    8. ARM Programming: Simulating arithmetic operations using Keil uVision IDE.

    (b) AIM:

    Write Assembly language program to perform arithmetic operations using an ARM

    processor. This will be a simulation.

    ALGORITHM:

    1. Load one number into a register

    2. Load the second number into another register

    3. Depending on the operation to be performed, add, subtract or multiply using a

    suitable assembly instruction.

    4. ARM processors do not natively support division. To divide, you must use repeated

    subtraction. Step 5 onwards discusses division.

    5. Subtract the divisor from the dividend to obtain another dividend.

    6. Keep on doing this till the obtained dividend becomes smaller than the divisor. The

    number of times this happens is the quotient.

    7. The finally obtained dividend (the one that is smaller than the quotient) is the

    remainder.

    Program:

  • 7/28/2019 Microcontroller Record 8051

    42/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

  • 7/28/2019 Microcontroller Record 8051

    43/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Sample Input Sample Output

    RESULT:

  • 7/28/2019 Microcontroller Record 8051

    44/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Programming ARM processors in C: LPCXpresso IDE Introduction:

    LPCXpressos IDE is a highly integrated software development environment for NXPs LPC

    Microcontrollers, which includes all the tools necessary to develop high quality software solutions in

    a timely and cost effective fashion. LPCXpresso is based on Eclipse with many LPC specific

    enhancements. It also features the latest version of the industry standard GNU tool chain with a

    proprietary optimized C library providing professional quality tools at low cost.

    The LPCXpresso IDE can build an executable of any size with full code optimization and it supports a

    download limit of 128kB after registration.

    LPCXpresso supports the full embedded product design cycle by moving beyond chip evaluation

    boards and supporting development on external target boards.

  • 7/28/2019 Microcontroller Record 8051

    45/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Simulating a program using LPCXpresso:

    Open LPCXpresso (Start >Programs>LPCXpresso) Start a new project (File>New> project)

    In popup window select LPCXpresso c project(c/c++> LPCXpresso c project)

  • 7/28/2019 Microcontroller Record 8051

    46/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Select next

    In popup window select c project(NXP LPC 1300 Projects> c project)

    Give a name, next

    Select LPC1343 (LPC13xx>LPC1343)

    Next, select CMSISv1p30_LPC13xx

    Finish

    In left side window you see project name

    Select the source file(project name > src >name.c)

  • 7/28/2019 Microcontroller Record 8051

    47/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Type the code

    Save it

    Connect the board

    Built the code

    Debug the code

  • 7/28/2019 Microcontroller Record 8051

    48/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    9. Programming LED using LPC1343

    Aim:

    Write a C program to blink the onboard LED in LPC1343 using NGX baseboard. The LED

    pin is P0.7. Use LPC XPresso IDE.

    Algori thm:

    1. Include GPIO.H and GPIO.C into the current workspace. You can do this by copying

    the files from the GPIO example and pasting it into the src folder.

    2. Initialize the GPIO function. Set the LED pin to output.

    3. Set the LED pin to the HIGH state

    4. Give some delay using a FOR loop.

    5. Set the LED pin to the LOW state.

    6. Give some delay using a FOR loop.

    7. Go to step 3. Keep doing this.

    Program:

  • 7/28/2019 Microcontroller Record 8051

    49/50

    EEE 303 Microcontroller Lab Page No:

    Microcontroller and its Applications Lab, SELECT, VIT University, Vellore 14

    Result:

  • 7/28/2019 Microcontroller Record 8051

    50/50

    EEE 303 Microcontroller Lab Page No:

    10. Getting the buzzer to sound using LPC1343

    Aim:

    To sound the buzzer included on the LPC1343 NGX baseboard. The buzzer is

    connected to P1.11

    Algori thm:

    1. Include GPIO.H and GPIO.C into the current workspace. You can do this by copying

    the files from the GPIO example and pasting it into the src folder.

    2. Initialize the GPIO function. Set the buzzer pin to output.

    3. Set the buzzer pin to the HIGH state

    Program

    Result:


Recommended