EMBEDDED SYSTEM.docx

download EMBEDDED SYSTEM.docx

of 42

Transcript of EMBEDDED SYSTEM.docx

  • 7/31/2019 EMBEDDED SYSTEM.docx

    1/42

    1

    EMBEDDED SYSTEM

    What is Embedded System?

    Embedded system employs a combination of software & hardware to perform a specific

    function. It is a part of a larger system which may not be a computerWorks in areactive & time constrained environment.Any electronic system that uses a CPU chip, but that is not a general-purposeworkstation, desktop or laptop computer is known as embedded system. Such systemsgenerally use microprocessors; microcontroller or they may use custom-designed chipsor both. They are used in automobiles, planes, trains, space vehicles, machine tools,cameras, consumer and office appliances, cell phones, PDAs and other handhelds aswell as robots and toys. The uses are endless, and billions of microprocessors areshipped every year for a myriad of applications.

    In embedded systems, the software is permanently set into a read-only memory such asa ROM or flash memory chip, in contrast to a general-purpose computer that loads itsprograms into RAM each time. Sometimes, single board and rack mounted general-purpose computers are called "embedded computers" if used to cont

    Embedded System Applications :-

    Consumer electronics, e.g., cameras, cell phones etc.

    Consumer products, e.g. washers, microwave ovens etc.

    Automobiles (anti-lock braking, engine control etc.)

    Industrial process controller & defense applications.

    Computer/Communication products, e.g. printers, FAX machines etc.

    Medical Equipments.

    ATMs

    Aircrafts

  • 7/31/2019 EMBEDDED SYSTEM.docx

    2/42

    2

    DIFFERENCE BETWEEN MICROPROCESSORS

    AND MICROCONTROLLERS:

    A Microprocessor is a general purpose digital computer central processing

    unit(C.P.U) popularly known as CPU on the chip. The Microprocessorscontain no RAM, no ROM, and no I/P O/P ports on the chip itself.

    On the other hand a Microcontroller has a C.P.U(microprocessor) in addition

    to a fixed amount of RAM, ROM, I/O ports and a timer all on a single chip.

    In order to make a Microprocessor functional we must add RAM, ROM, I/O

    Ports and timers externally to them,i.e any amount of external memory can be

    added to it.

    But in controllers there is a fixed amount of memory which makes them ideal

    for many applications.

    The Microprocessors have many operational codes(opcodes) for moving data

    from external memory to the C.P.U

    Whereas Microcontrollers may have one or two operational codes.

    DISADVANTAGES OF MICROPROCESSORS

    OVER MICROCONTROLLERS

    System designed using Microprocessors are bulky

    They are expensive than Microcontrollers

    We need to add some external devices such as PPI chip, Memory,

    Timer/counter chip, Interrupt controller chip,etc. to make it functional.

    Types of microcontroller architecture:

  • 7/31/2019 EMBEDDED SYSTEM.docx

    3/42

    3

    There are two types of Microcontroller architecture designed for embedded systemdevelopment. These are:1)RISC- Reduced instruction set computer2)CISC- Complex instruction set computer

    Difference between CISC and RISC:

    CISC stands for Complex Instruction Set Computer. Most PC's use CPU based on thisarchitecture. For instance Intel and AMD CPU's are based on CISC architectures.Typically CISC chips have a large amount of different and complex instructions. Incommon CISC chips are relatively slow (compared to RISC chips) per instruction, but uselittle (less than RISC) instructions. MCS-51 family microcontrollers based on CISCarchitecture.

    RICS stands for Reduced Instruction Set Computer. The philosophy behind it is that almost

    no one uses complex assembly language instructions as used by CISC, and people mostlyuse compilers which never use complex instructions. Therefore fewer, simpler and fasterinstructions would be better, than the large, complex and slower CISC instructions.However, more instructions are needed to accomplish a task. Atmells AVRmicrocontroller based on RISC architecture.

    History of 8051Intel Corporation introduced an 8-bit microcontroller called 8051 in 1981 this controllerhad 128 bytes of RAM, 4k bytes of on chip ROM, two timers, one serial port, and fourports all are on single chip. The 8051 is an 8 bit processor, meaning that the CPU can

    work on only 8 bit data at a time. Data larger than 8 bits broken into 8 bit pieces to beprocessed by CPU. It has for I/O 8 bit wide.Features of the 8051:-

    Feature QuantityROM 4K bytesRAM 128 bytesTimer 2I/O pins 32

    Serial port 1Interrupt sources 6

    8051 Architecture Overview

  • 7/31/2019 EMBEDDED SYSTEM.docx

    4/42

    4

    The 8051 family is one of the most common microcontroller architectures used worldwide.

    8051 based microcontrollers are offered in hundreds of variants from many different

    silicon manufacturers

    .The 8051 is based on an 8-bit CISC core with Harvard architecture. It's an 8-bit CPU,

    optimized for control applications with extensive Boolean processing (single-bit logiccapabilities), 64K program and data memory address space and various on-chip

    peripherals.

    The 8051 microcontroller family offers developers a wide variety of high-integration and

    cost-effective solutions for virtually every basic embedded control application. From traffic

    control equipment to input devices and computer networking products, 8051 u.c deliver

    high performance together with a choice of configurations and options matched to the

    special needs of each application. Whether it's low power operation, higher frequency

    performance, expanded on-chip RAM, or an application-specific requirement, there's a

    version of the 8051 microcontroller that's right for the job.

    When it's time to upgrade product features and functionality, the 8051 architecture puts

    you on the first step of a smooth and cost-effective upgrade path - to the enhanced

    performance of the 151 and 251 microcontrollers.

  • 7/31/2019 EMBEDDED SYSTEM.docx

    5/42

    5

    Block diagram of 8051

  • 7/31/2019 EMBEDDED SYSTEM.docx

    6/42

    6

    Internal Architecture of 8051

  • 7/31/2019 EMBEDDED SYSTEM.docx

    7/42

    7

    Pin configuration of 8051

  • 7/31/2019 EMBEDDED SYSTEM.docx

    8/42

    8

    There are four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All the

    ports upon RESET are configured as output, ready to be used as output ports. To use any of

    these ports as an input port, it must be programmed.

    Port 0:- Port 0 occupies a total of 8 pins (pins 32-39) .It can be used for input or output. To

    use the pins of port 0 as both input and output ports, each pin must be connected externally

    to a 10K ohm pull-up resistor. This is due to the fact that P0 is an open drain, unlike P1,

    P2, and P3.Open drain is a term used for MOS chips in the same way that open collectorisused for TTL chips. With external pull-up resistors connected upon reset, port 0 is

    configured as an output port. For example, the following code will continuously send outto port 0 the alternating values 55H and AAH

    Port 0 as input:- With resistors connected to port 0, in order to make it an input, the port

    must be programmed by writing 1 to all the bits. In the following code, port 0 is configured

    first as an input port by writing 1's to it, and then data is received from the port and sent to

    P1.

  • 7/31/2019 EMBEDDED SYSTEM.docx

    9/42

    9

    Dual Role of Port 0 :-Port 0 is also designated as AD0-AD7, allowing it

    to be used for both address and data. When connecting an 8051/31 to an external memory,

    port 0 provides both address and data. The 8051 multiplexes address and data through port

    0 to save pins. ALE indicates if P0 has address or data. When ALE = 0, it provides data

    D0-D7, but when ALE =1 it has address and data with the help of a 74LS373 latch.

    Port 1:- Port 1 occupies a total of 8 pins (pins 1 through 8). It can be used as input or

    output. In contrast to port 0, this port does not need any pull-up resistors since it already

    has pull-up resistors internally. Upon reset, Port 1 is configured as an output port. For

    example, the following code will continuously send out to port1 the alternating values 55h& AAh

    Port 1 as input:-To make port1 an input port, it must be programmed as such by writing 1

    to all its bits. In the following code port1 is configured first as an input port by writing 1s

    to it, then data is received from the port and saved in R7 ,R6 & R5.

    Port 2 :-Port 2 occupies a total of 8 pins (pins 21- 28). It can be used as input or

    output. Just like P1, P2 does not need any pull-up resistors since it already has pull-up

    resistors internally. Upon reset,Port 2 is configured as an output port. For example, the

    following code will send out continuously to port 2 the alternating values 55h and AAH.

    That is all the bits of port 2 toggle continuously.

    Port 2 as input:- To make port 2 an input, it must programmed as such by writing 1 to all

    its bits. In the following code, port 2 is configured first as an input port by writing 1s to it.Then data is received from that port and is sent to P1 continuously.

  • 7/31/2019 EMBEDDED SYSTEM.docx

    10/42

    10

    Dual role of port 2:- In systems based on the 8751, 8951, and DS5000, P2 is used as

    simple I/O. However, in 8031-based systems, port 2 must be used along with P0 to provide

    the 16-bit address for the external memory. As shown in pin configuration 8051, port 2 is

    also designed as A8-A15, indicating the dual function. Since an 8031 is capable of

    accessing 64K bytes of external memory, it needs a path for the 16 bits of the address.While P0 provides the lower 8 bits via A0-A7, it is the job of P2 to provide bits A8-A15 of

    the address. In other words, when 8031 is connected to external memory, P2 is used for the

    upper 8 bits of the 16 bit address, and it cannot be used for I/O.

    Port 3:- port 3 occupies a total of 8 pins, pins 10 through 17. It can be used as input oroutput. P3 does not need any pull-up resistors, the same as P1 and P2 did not. Although

    port 3 is configured as an output port upon reset. Port 3 has the additional function ofproviding some extremely important signals such as interrupts. This information appliesboth 8051 and 8031 chips. There functions are as follows:-

    P3.0 and P3.1 are used for the RxD and TxD serial communications signals. Bits P3.2

    and P3.3 are set aside for external interrupts. Bits P3.4 and P3.5 are used for timers 0 and

    1. Finally P3.6 and P3.7 are used to provide the WR and RD signals of external memories

    connected in 8031 based systems.

    PORT 3 Function pinP3.0 RxD 10P3.1 TxD 11P3.2 ___

    Int0

    12

    P3.3 ___Int1

    13

    P3.4 T0 14P3.5 T1 15P3.6 ___

    WR16

    P3.7 ___RD

    17

  • 7/31/2019 EMBEDDED SYSTEM.docx

    11/42

    11

    ALE/PROG

    Address Latch Enable is an output pulse for latching the low byte of the address duringaccesses to external memory. This pin is also the program pulse input (PROG) duringFlash programming. In normal operation, ALE is emitted at a constant rate of 1/ 6 theoscillator frequency and may be used for external timing or clocking purposes. Note,

    however, that one ALE pulse is skipped during each access to external data memory. Ifdesired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bitset, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin isweakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is inexternal execution mode.

    PSENProgram Store Enable is the read strobe to external program memory. When theAT89S8252 is executing code from external program memory, PSEN is activated twice

    each machinecycle, except that two PSEN activations are skipped during each access to external datamemory.

    EA/VPPExternal Access Enable. EA must be strapped to GND in order to enable the device tofetch code from external program memory locations starting at 0000H up to FFFFH. Note,however, that if lock bit 1 is programmed, EA will be internally latched on reset. EAshould be strapped to VCC for internal program executions. This pin also receives the 12-

    volt programming enable voltage (VPP) during Flash programming when 12-voltprogramming is selected.

    XTAL1Input to the inverting oscillator amplifier and input to the internal clock operating circuit.

    XTAL2Output from the inverting oscillator amplifier.

    AT89s8252AT89S8252 is an ATMEL controller with the core of intel MCS-51. It has same pinconfiguration as give above.The AT89S8252 is a low-power, high-performance CMOS 8-bit microcomputer with 8Kbytes of Downloadable Flash programmable and erasable read only memory and 2K bytesof EEPROM. The device is manufactured using Atmels high density nonvolatile memory

    technology and is compatible with the industry standard 80C51 instruction set and pinout.The on-chip Downloadable Flash allows the program memory to be reprogrammed in-

  • 7/31/2019 EMBEDDED SYSTEM.docx

    12/42

    12

    system through an SPI serial interface or by a conventional nonvolatile memoryprogrammer. By combining a versatile 8-bit CPU with Downloadable Flash on amonolithic chip, the Atmel AT89S8252 is a powerful microcomputer which provides ahighly flexible and cost effective solution to many embedded control applications. TheAT89S8252 provides the following standard features: 8K bytes of Downloadable Flash,2K bytes of EEPROM, 256 bytes of RAM, 32 I/O lines, programmable watchdog timer,

    two Data Pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture,a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S8252is designed with static logic for operation down to zero frequency and supports twosoftware selectable power saving modes. The Idle Mode stops the CPU while allowing theRAM, timer/counters, serial port, and interrupt system to continue functioning. The PowerDown Mode saves the RAM contents but freezes the oscillator, disabling all other chipfunctions until the next interrupt or hardware reset.The Downloadable Flash can be changed a single byte at a time and is accessible throughthe SPI serial interface. Holding RESET active forces the SPI bus into a serialprogramming interface and allows the program memory to be written to or read from

    unless Lock Bit 2 has been activated.

    Features Compatible with MCS-51Products 8K bytes of In-System Reprogrammable Downloadable Flash Memory- SPI Serial Interface for Program Downloading- Endurance: 1,000 Write/Erase Cycles 2K bytes EEPROM

    - Endurance: 100,000 Write/Erase Cycles 4.0V to 6V Operating Range Fully Static Operation: 0 Hz to 24 MHz Three-Level Program Memory Lock 256 x 8 bit Internal RAM 32 Programmable I/O Lines Three 16 bit Timer/Counters Nine Interrupt Sources Programmable UART Serial Channel SPI Serial Interface Low Power Idle and Power Down Modes Interrupt Recovery From Power Down Programmable Watchdog Timer Dual Data Pointer Power Off Flag

  • 7/31/2019 EMBEDDED SYSTEM.docx

    13/42

    13

    Pin Description

    Furthermore, P1.4, P1.5, P1.6, and P1.7 can be configured as the SPI slave port select, datainput/output and shift clock input/output pins as shown in the following table.

    Port 1 also receives the low-order address bytes during Flash programming andverification.

    Hardware interfacings and programming

    There are two types of programming language used for microcontroller programming:1)Low Level Language(Assembly Language)2) High Level Language(C Language)_

    ALE/PROG

    Address Latch Enable is an output pulse for latching the low byte of the address duringaccesses to external memory. This pin is also the program pulse input (PROG) duringFlash programming. In normal operation, ALE is emitted at a constant rate of 1/ 6 theoscillator frequency and may be used for external timing or clocking purposes. Note,however, that one ALE pulse is skipped during each access to external data memory. Ifdesired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bitset, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin isweakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is inexternal execution mode.

  • 7/31/2019 EMBEDDED SYSTEM.docx

    14/42

    14

    PSEN

    Program Store Enable is the read strobe to external program memory. When theAT89S8252 is executing code from external program memory, PSEN is activated twiceeach machinecycle, except that two PSEN activations are skipped during each access to external data

    memory.

    EA/VPP

    External Access Enable. EA must be strapped to GND in order to enable the device tofetch code from external program memory locations starting at 0000H up to FFFFH. Note,however, that if lock bit 1 is programmed, EA will be internally latched on reset. EAshould be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming when 12-voltprogramming is selected.

    XTAL1

    Input to the inverting oscillator amplifier and input to the internal clock operating circuit.

    XTAL2

    Output from the inverting oscillator amplifier.

    Hardware interfacings and programming

    There are two types of programming language used for microcontroller programming:1)Low Level Language(Assembly Language)2) High Level Language(C Language)

    Programming in assembly language:

    TOOLS USED:1). 8051 assembler cum simulator.2).command prompt as a programming environment.

    Introduction to programming in assembly language:

  • 7/31/2019 EMBEDDED SYSTEM.docx

    15/42

    15

    assembly languages weredeveloped that provided mnemonics for the machine code instructions, plus others featuresthat made programming faster and less prone to error.The term mnemonic is frequentlyused in computer science and engg. literature to refer to codes and abbreviations that arerelatively easy to remember .Asssembly language programs must be translated intomachine code by a program called an ASSEMBLER.Assembly language is referred to as

    a low-level-language .Now we look at 8051 assembly language format and use an 8051

    Assembler to create a ready-to run program.

    An assembly language instruction consists of four fields:-

    [label:] mnemonic [operands] [;comment]

    Brackets indicates that a field is optional,and not all lines have them.Bracket shouldnot be typed in.

    1.The label field allows the program to refer to a line of code by name.the label field cannot exceed a certain no. of characters.

    2.The assembly language mnemonics(instruction) and operands fields together perform thereal work of the program and accomplish the tasks for which the program was written.

    3.The comment field begins with a ;. Comments may be at the and of a line or on a lineby themselvess .

    8051 basic instructions:we describe the basic instructions of the 8051 andgive their formats with some examples.1).arithmetic instructions2).logical instructions3).jump,loop,call instructions

    arithmetic instructions:the arithmetic instructions are used to perform arithmetic

    operations like addition,subtraction ,multiplication, division etc.

    1)ADD:- this instruction is used to add 2 operands.the 1 operand should be in accumulatorand 2 in the other register.

    eg. MOV R0,#20MOV A,#10ADD A,R0MOV P1,A

  • 7/31/2019 EMBEDDED SYSTEM.docx

    16/42

    16

    Here,# is used to load immediate value and we observe the final value on port 1.

    2)MUL:-this instruction is used to multiply 2 operands. the 1 operand should be inaccumulator and 2 in the other register.

    eg.MOV R0,#20MOV A,#10MUL ABMOV P1,A

    Here,# is used to load immediate value and we observe the final value on port 1.

    3)DIV:- this instruction is used to divide 2 operands. the 1 operand should be inaccumulator and 2 in the other register.

    eg.MOV R0,#20MOV A,#10DIV ABMOV P1,A

    Here,# is used to load immediate value and we observe the final value on port 1.

    logical instructions: Apart from the input/output instructions ,logic instructions are someof the most widely used instructions.the logical instructions are used to perform logicaloperations likeAND,OR,EXOR etc.

    1). MOV A,#35H ;A=35HANL A,#0FH ;A AND 0FH(now A=05)

    According to this operation, the content 35H gets ANDing with 0FH.

    2). MOV A,#04 ;A=04ORL A,#30H ;A=A OR 30H(now A=34H)

    According to this operation, the content 35H gets ANDing with 0FH.

    Jump,loop,call instructions:

  • 7/31/2019 EMBEDDED SYSTEM.docx

    17/42

    17

    the Jump,loop,call instructions are used to perform logicaloperations in the sequence of instructions to be executed ,it is often necessary to transferprogram control to a different location.

    We have used high level language for microcontroller programming due to its givenadvantages over assembly:

    Advantages of C over Assembly language programming:

    Knowledge of the processor instruction set is not required.

    Details like register allocation and addressing of memory and data is managed by the

    compiler.

    Programs get a formal structure and can be divided into separate functions.

    Programming and program test time is drastically reduced, this increases efficiency.

    Keywords and operational functions can be used that come closer to how humans

    think.

    The supplied and supported C libraries contain many standard routines such as

    numeric conversions.

    Reusable code: Existing program parts can be more easily included into new

    programs, because of the comfortable modular program construction techniques.

    The C language based on the ANSI standard is very portable. Existing programs can

    be quickly adapted to other processors as needed.

    THE 8051 INTERRUPTS

    There are two methods in which a micro-controller can provide its services to its internal

    and external environment:

    1) POLLING: Microcontroller checks the device continuously while using thismethod. But it results in wastage of machine cycles of the micro-controller.

  • 7/31/2019 EMBEDDED SYSTEM.docx

    18/42

    18

    2) INTERRUPTS: Here every device tells the micro-controller when it needs theservices from microcontroller.

    Actually, only 5 interrupts are available to the user in the 8051, but many manufacturersdata sheets state that there are 6 interrupts since they include reset. The 6 interrupts in the8051 are allocated as follows:

    1).Reset: when the reset pin is activated, the 8051 jumps to address location 0000.this isthe power-up reset.

    2).Two interrupts are set aside for the timers:

    One for timer 0 and one for timer 1.memory locations 000BH and 001BH in the interruptvector table belong to timer0 and timer1, respectively.

    3).Two interrupts are set aside for hardware external hardware interrupts. Pin numbers12(p3.2) and 13(p3.3) in port 3 are the external hardware interrupts INT0 and INT1,respectively. These external interrupts are also referred to as EX1 and EX2.

    4).Serial communication has a single interrupts that belongs to both receive and transmit.

    ELECTROMAGNETIC RELAYS

    A relay is an electrically controllable switch widely used in industrial controls, automobilesand appliances. It allows the isolation of two separate sections of a system with twodifferent voltage sources. The electromechanical (or electromagnetic) relay (EMR) has 3components: the coil, spring and contacts. When current flows through the coil, a magnetic

    field is created around the coil (the coil is energized) which causes the armature to beattracted to the coil. The armatures contact acts like a switch and closes or opens a circuit.When the coil is not energized, a spring pulls the armature to its normal state of open orclosed.

    In choosing a relay, the following characteristics need to be considered:

    1) The contacts can be normally open (NO) or normally closed (NC). Inthe NC type, the contacts are closed when the coil is not energized.In the NO, the contacts are open when the coil is un-energized.

    2) There can be one or more contacts (SPST, SPDT, DPDT relays).3) The voltage and current needed to energize the coil. The voltage can

    vary from a few volts to 50 volts, while the current can be from fewmA to 20mA. The relay has a minimum voltage below which the coilwill not be energized. This minimum voltage is called the pull-involtage.

  • 7/31/2019 EMBEDDED SYSTEM.docx

    19/42

    19

    INTERFACING OF VARIOUS DEVICES

    1) LED Interfacing

    Hardware interfacing of LED with AT89s8252

    Title

    Size Document Number Rev

    Date: Sheet of

    Custom

    1 1Tuesday, December 26, 2006

    Q21

    BC547A

    Q14BC547A

    D26

    LED

    VCC

    R40

    330E

    D27

    LED

    VCC

    R41

    330E

    VCC

    D28

    LED

    R61

    330E

    D29

    LED

    R62

    330E

    VCC

    Q15

    BC547A

    D22

    LED

    R37

    330E

    VCC

    Q16

    BC547A

    Q17

    BC547A

    Q18

    BC547A

    D23

    LED

    VCC

    R38

    330E

    Q19

    BC547A D24

    LED

    VCC

    R39

    330E

    D25

    LED

    R63

    330E

    VCC

    Q20

    BC547A

    U10

    AT89S8252

    RST9

    XTAL218 XTAL119

    GND

    20

    PSEN29

    ALE/PROG30

    EA/VPP

    31

    VCC

    40

    P1.0/T21

    P1.1/T2-EX2

    P1.23

    P1.34

    P1.4/SS5

    P1.5/MOSI6

    P1.6/MISO7

    P1.7/SCK8

    P2.0/A821

    P2.1/A922

    P2.2/A1023

    P2.3/A1124

    P2.4/A1225

    P2.5/A1326

    P2.6/A1427

    P2.7/A1528

    P3.0/RXD10P3.1/TXD11

    P3.2/INT012

    P3.3/INT113

    P3.4/T014

    P3.5/T115

    P3.6/WR16P3.7/RD17

    P0.0/AD039

    P0.1/AD138

    P0.2/AD237

    P0.3/AD336

    P0.4/AD435

    P0.5/AD534

    P0.6/AD633

    P0.7/AD732

    C4533pF

    C4633pF

    Y8

    8 Mhz

    12

    3

    4

    VCCVCC

    R710K

    C4710uF/16V

    VCC

    C48104

  • 7/31/2019 EMBEDDED SYSTEM.docx

    20/42

    20

    C code for Blinking LEDs connected on PORT2:

    #includevoid delay(unsigned int i);

    void main(void){

    While(1){P2=0x00;Delay(0xffff);P2=0x00;Delay(0xff);}}void delay(unsigned int i)

    {while(i!=0){i--;}}

    C code for running LED connected on PORT2:

    #includevoid delay(unsigned int i);void main (){P0=0x00;while (1){delay(0xffff);P2_0=1;delay(0xffff);P2_0=0;P2_1=1;delay(0xffff);P2_1=0;P2_2=1;delay(0xffff);

  • 7/31/2019 EMBEDDED SYSTEM.docx

    21/42

    21

    P2_2=0;P2_3=1;delay(0xffff);P2_3=0;P2_4=1;delay(0xffff);

    P2_4=0;P2_5=1;delay(0xffff);P2_5=0;P2_6=1;delay(0xffff);P2_6=0;P2_7=1;delay(0xffff);P2_7=0;

    P2_0=1

    }}

    void delay(unsigned int i){while (i!=0){

    i--;}}

    2) Hardware interfacing of LCD(JHD162A):

    On most displays, the pins are numbered on the LCDs printed circuit board, but if not, it is

    quit easy to locate pin1. Since the pin is connected to ground, it often has a thicker PCB

    track connected to it, and it is generally connected to the metal work at some point.

  • 7/31/2019 EMBEDDED SYSTEM.docx

    22/42

    22

    The function of each of the connections is shown in the table below:-

    Pins 1 & 2 are the power supply lines, Vss & Vdd. The Vdd pin should be connected to the

    positive supply & Vss to the 0V supply or ground.

    Although the LCD module data sheets specify 5V D.C. supply (at only a few milliamps),

    supplies of 6V & 4.5V both work well, and even 3V is sufficient for some modules.

    Consequently, these modules can be effectively and economically powered by batteries.

    Pin 3 is a control pin, Vee, which is used to alter the contrast of the display. Ideally, these pin

    should be connected to a variable voltage supply. A preset potentiometer connected betweenthe power supply lines, with its wiper connected to the contrast pin is suitable in many cases,

    but be aware that some modules may require a

    negative potential; as low as 7V in some cases. For absolute simplicity, connecting this pin to

    0V will often suffice.

    Pin 4 is register select (RS) line.

    PIN NO. NAME FUNCTION

    1 Vss Ground

    2 Vdd +ve supply

  • 7/31/2019 EMBEDDED SYSTEM.docx

    23/42

    23

    3 Vee contrast

    4 RS Register select

    5 R/W Read/Write

    6 E Enable

    7 D0 Data Bit 08 D1 Data Bit 1

    9 D2 Data Bit 2

    10 D3 Data Bit 3

    11 D4 Data Bit 4

    12 D5 Data Bit 5

    13 D6 Data Bit 6

    14 D7 Data Bit 7

    Three command control inputs. When this line is low, data bytes transferred to thedisplay are treated as commands, and data bytes read from the display indicate itsstatus. By setting the RS line high, character data can be transferred to and from themodule.

    Pin 5 is (R/W) line. This line is pulled low in order to write commands or character datato the module, or pulled high to read character data or status information from itsregisters.

    Pin 6 is Enable (E) line. This input is used to initiate the actual transfer of commands orcharacter data between the module and the data lines. When writing to the display, datais transferred only on the high to low transition of this signal. However, when readingfrom the display, data will become available shortly after the low to high transition andremain available until the signal falls low again.

    Pins 7 to 14 are the eight data bus lines (D0 to D7). Data can be transferred to and fromthe display, either as a single 8-bit byte or as two 4-bit nibbles. In the latter case, onlythe upper four data lines (D4 to D7) are used. This $-bit mode is beneficial when usinga microcontroller, as fewer I/O lines are required.

  • 7/31/2019 EMBEDDED SYSTEM.docx

    24/42

    24

    C code for LCD display

    #include #define LCDPRT P1#define RS P3_3

    #define EN P3_4void delay(unsigned int i);void lcd_cmd(unsigned char a);void display(unsigned char b);void wait(void);void Init_lcd(void);void cursor_position(unsigned char c);

    void main(void){

    U1

    AT89S52

    RST9

    XTAL218 XTAL119

    GND

    20

    PSEN29

    ALE/PROG30

    EA/VPP

    31

    VCC

    40

    P1.0/T21

    P1.1/T2-EX2

    P1.23

    P1.34

    P1.4/SS5

    P1.5/MOSI6

    P1.6/MISO7

    P1.7/SCK8

    P2.0/A8 21

    P2.1/A922

    P2.2/A1023

    P2.3/A1124

    P2.4/A1225

    P2.5/A1326

    P2.6/A1427

    P2.7/A1528

    P3.0/RXD10

    P3.1/TXD11

    P3.2/INT012

    P3.3/INT113

    P3.4/T014

    P3.5/T115

    P3.6/WR16P3.7/RD17

    P0.0/AD039 P0.1/AD138 P0.2/AD237 P0.3/AD336 P0.4/AD435 P0.5/AD534 P0.6/AD633 P0.7/AD732

    J2 LCD

    1 2 3 4 5 6 7 8 910

    11

    12

    13

    14

    15

    16

    C133pF

    C233pF

    Y1

    12

    3

    4

    R110K

    C310uF 16V

    VCC

    VCC R52

    56E

    VCC

    VCC

    RS

    Hardware intetrfacing of LCD with AT89s52 microcontroler

    EN

  • 7/31/2019 EMBEDDED SYSTEM.docx

    25/42

    25

    init_lcd();while(1)

    {cursor_position(0x01);display('N');

    cursor_position(0x02);display('E');cursor_position(0x03);display('T');cursor_position(0x04);display('M');cursor_position(0x05);display('A');cursor_position(0x06);display('X');

    }

    }

    void delay (unsigned int i){while (i!=0){

    i--;}

    }

    void lcd_cmd(unsigned char a){wait();LCDPRT=a;RS=0;EN=1;EN=0;}void display(unsigned char b){

    wait ();LCDPRT=b;RS=1;

  • 7/31/2019 EMBEDDED SYSTEM.docx

    26/42

    26

    EN=1;EN=0;}void wait(void){unsigned int count=300;

    while(count!=0){count--;}

    }

    void Init_lcd(void){

    lcd_cmd(0x3c);lcd_cmd(0x0c);lcd_cmd(0x06);lcd_cmd(0x01);

    }void clear_lcd(void){lcd_cmd(0x01);

    }void cursor_position(unsigned char c){lcd_cmd(c+0x80);}

    C code for string display on LCD:

    #include#define LCDPRT P1#define RS P3_3#define EN P3_4code unsigned char name_arry[]={"NETMAX$"};void display_string(unsigned char *sp);void lcd_cmd(unsigned char a);void display(unsigned char b);void wait(void);

  • 7/31/2019 EMBEDDED SYSTEM.docx

    27/42

    27

    void Init_lcd(void);void cursor_position(unsigned char c);

    void main(void){Init_lcd();

    cursor_position(0x40);display_string(&name_arry);

    }

    void display_string(unsigned char *sp)

    {while(*sp!='$')

    {

    display(*sp);

    sp=sp+1;}

    }

    void lcd_cmd(unsigned char a){wait ();LCDPRT=a;RS=0;EN=1;EN=0;}void display(unsigned char b){wait ();LCDPRT=b;RS=1;EN=1;EN=0;}void wait(void){

  • 7/31/2019 EMBEDDED SYSTEM.docx

    28/42

    28

    unsigned int count=300;while(count!=0){count--;}

    }

    void Init_lcd(void){lcd_cmd(0x3c);lcd_cmd(0x0c);lcd_cmd(0x06);

    lcd_cmd(0x01);}void cursor_position(unsigned char c){lcd_cmd(c+0x80);

    }

    3) ADC-0804 interfacing with AT89s52:

    The ADC0804 family is CMOS 8-Bit, successive-approximation A/D converters

    which use a modified potentiometer ladder and are designed to operate with the

    8080A control bus via three-state outputs. These converters appear to theprocessor as memory locations or I/O ports, and hence no interfacing logic is

    required. The differential analog voltage input has good common mode- rejection

    and permits offsetting the analog zero-input voltage value. In addition, the voltage

    reference input can be adjusted to allow encoding any smaller analog voltage span

    to the full 8 bits of resolution.

    Features

    80C48 and 80C80/85 Bus Compatible - No Interfacing Logic Required

    Conversion Time < 100 s

    Easy Interface to Most Microprocessors

  • 7/31/2019 EMBEDDED SYSTEM.docx

    29/42

    29

    Differential Analog Voltage Inputs

    TTL Compatible Inputs and Outputs

    On-Chip Clock Generator

    0V to 5V Analog Voltage Input Range (Single + 5V Supply)

    No Zero-Adjust Required

    PIN DIAGRAM

  • 7/31/2019 EMBEDDED SYSTEM.docx

    30/42

    30

    Hardware interfacing of ADC-0804 for Temperature monitoring

    When interfacing is being 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 software controlled.

    C- code For temperature monitoring system

    #include #define LCDPRT P1#define RS P3_3#define EN P3_4#define SOC P3_2#define EOC P3_5

    R2

    10K

    C610uF 16V

    VCC

    C13104

    EOC

    SOC

    VCC

    C141uf/16v

    R6

    220E

    U4ADC0804

    +IN6

    -IN7

    AGND

    8

    VREF/29

    GND

    10

    DB711DB6

    12 DB513 DB414 DB315 DB216 DB117 DB018

    CLKR19

    VCC/VREF

    20

    CLKIN4

    INTR5

    CS1

    RD2

    WR3

    VCC

    R510K

    R17

    10K

    C7

    150pF

    U21TL431

    2

    3

    1

    C81uf/16v

    C9CAP

    RSEN

    LCD

    CON16_0

    1 2 3 4 5 6 7 8 910

    11

    12

    13

    14

    15

    16

    VCCRS EN R55

    56E

    Temprature monitoring system

    U22 LM35/SO

    GND3

    VCC1

    2

    OUTPUT

    R53

    1k

    VCC

    U2

    AT89S8252

    RST9

    XTAL218 XTAL119

    GND

    20

    PSEN29 ALE/PROG30

    EA/V

    PP

    31

    V

    CC

    40

    P1.0/T21

    P1.1/T2-EX2

    P1.23

    P1.34

    P1.4/SS5

    P1.5/MOSI6

    P1.6/MISO7

    P1.7/SCK8

    P2.0/A821

    P2.1/A922

    P2.2/A1023

    P2.3/A1124

    P2.4/A1225

    P2.5/A1326

    P2.6/A1427

    P2.7/A15 28

    P3.0/RXD10

    P3.1/TXD11

    P3.2/INT0 12

    P3.3/INT113

    P3.4/T014

    P3.5/T115

    P3.6/WR16

    P3.7/RD17

    P0.0/AD039 P0.1/AD138 P0.2/AD237 P0.3/AD336 P0.4/AD435 P0.5/AD534 P0.6/AD633 P0.7/AD732

    C433pF

    C533pF

    Y2

    CRYSTAL

    12

    3

    4

    VCCVCC

  • 7/31/2019 EMBEDDED SYSTEM.docx

    31/42

    31

    unsigned char read_adc(void);void delay(unsigned int i);void lcd_cmd(unsigned char a);void display(unsigned char b);void wait(void);void Init_lcd(void);

    void clear_lcd(void);void cursor_position(unsigned char c);

    void disp_dec(unsigned int digit);code unsigned char table[16]={'0','1','2','3','4','5','6','7','8','9'};

    void main(void){unsigned char e;P2=0xff;Init_lcd();

    while(1){cursor_position(0x00);e=read_adc();disp_dec(e);}

    }unsigned char read_adc(void){

    unsigned char n;SOC=0;SOC=1;while(EOC==1){

    n=P2;}

    return n;}

    void delay (unsigned int i){while (i!=0){i--;}

    }void lcd_cmd(unsigned char a)

  • 7/31/2019 EMBEDDED SYSTEM.docx

    32/42

    32

    {wait();LCDPRT=a;RS=0;EN=1;EN=0;

    }void display(unsigned char b){

    wait ();LCDPRT=b;RS=1;EN=1;EN=0;}void wait(void)

    {unsigned int count=300;while(count!=0){count--;}

    }

    void Init_lcd(void)

    {lcd_cmd(0x3c);lcd_cmd(0x0c);lcd_cmd(0x06);lcd_cmd(0x01);}

    void cursor_position(unsigned char c){lcd_cmd(c+0x80);}

    void disp_dec(unsigned int digit){unsigned int temp;

  • 7/31/2019 EMBEDDED SYSTEM.docx

    33/42

    33

    if(digit99 && digit

  • 7/31/2019 EMBEDDED SYSTEM.docx

    34/42

    34

    C- code for serial transmission(from Microcontroller to PC)

    #includevoid Init_SPT(void);void transmit_serial(unsigned char a);

    void delay(unsigned int i);void main(void){Init_SPT();while(1){delay(0XFFFF);transmit_serial('N');delay(0XFFFF);

    transmit_serial('E');

    delay(0XFFFF);transmit_serial('T');delay(0XFFFF);

    transmit_serial('M');delay(0XFFFF);

    transmit_serial('A');delay(0XFFFF);

    transmit_serial('X');delay(0XFFFF);

    }

    }void Init_SPT(void){

    TMOD=0x20;

    TH1=0xfd;

    TR1=1;

    SCON=0x40;

    }

  • 7/31/2019 EMBEDDED SYSTEM.docx

    35/42

    35

    void transmit_serial(unsigned char a){SBUF=a;delay(500);TI=0;

    }void delay(unsigned int i){while(i!=0){i--;

    }}

    b)Serial Reception(From PC to microcontroller)

    J3 LCD

    1 2 3 4 5 6 7 8 910

    11

    12

    13

    14

    15

    16

    VCC

    NETMAX

    R54

    56E

    VCC

    RS EN

    RSEN

    SPT TXD

    SPT RXD

    U11

    AT89S8252

    RST9

    XTAL218 XTAL119

    GND

    20

    PSEN29

    ALE/PROG30

    EA/VPP

    31

    VCC

    40

    P1.0/T21

    P1.1/T2-EX2

    P1.23

    P1.34

    P1.4/SS5

    P1.5/MOSI6

    P1.6/MISO7

    P1.7/SCK8

    P2.0/A821

    P2.1/A922

    P2.2/A1023

    P2.3/A1124

    P2.4/A1225

    P2.5/A1326

    P2.6/A1427

    P2.7/A1528

    P3.0/RXD10P3.1/TXD11

    P3.2/INT012

    P3.3/INT113

    P3.4/T014

    P3.5/T115

    P3.6/WR 16P3.7/RD

    17

    P0.0/AD039 P0.1/AD138

    P0.2/AD237 P0.3/AD336 P0.4/AD435 P0.5/AD534 P0.6/AD633 P0.7/AD732

    C3433pF

    C3533pF

    Y9

    CRYSTAL

    12

    3

    4

    VCCVCC

    R810K

    C4910uF 16V

    VCC

    C50104

    C5110UF/16V

    VCC

    C5210UF/16V

    VCC

    C5310UF/16V

    C54104

    C55 10UF/16V

    U12

    MAX232

    C1+1

    C1-3

    C2+4

    C2-5

    VCC

    16

    GND

    15

    V+2

    V-6

    R1OUT12

    R2OUT9

    T1IN11

    T2IN10

    R1IN13

    R2IN8

    T1OUT14

    T2OUT7

    J8

    SERIAL PORT OF PC

    123

  • 7/31/2019 EMBEDDED SYSTEM.docx

    36/42

    36

    C- code for serial reception:#include #define LCDPRT P1#define RS P3_3#define EN P3_4

    void Init_SPT(void);unsigned char receive_serial(void);

    void delay(unsigned int i);void lcd_cmd(unsigned char a);void display(unsigned char b);void wait(void);void Init_lcd(void);void clear_lcd(void);void cursor_position(unsigned char d);

    void disp_hex(unsigned char digit);void disp_dec(unsigned int digit);code unsigned char lkup_tbl01[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

    void main(void){

    unsigned char e;

    Init_lcd();Init_SPT();

    while(1){

    e=receive_serial();cursor_position(0x00);display(e);

    }

    }

    void Init_SPT(void){

  • 7/31/2019 EMBEDDED SYSTEM.docx

    37/42

    37

    PCON=PCON&0x7F;

    TMOD=TMOD&0x0F;

    TMOD=TMOD|0x20;

    TH1=0xfd;

    SCON=0X50;

    TR1=1;

    }

    void delay (unsigned int i){

    while (i!=0){i--;}

    }void lcd_cmd(unsigned char a){wait();LCDPRT=a;

    RS=0;EN=1;EN=0;}void display(unsigned char b){wait ();LCDPRT=b;RS=1;EN=1;EN=0;}void wait(void){unsigned int count=300;while(count!=0){count--;

  • 7/31/2019 EMBEDDED SYSTEM.docx

    38/42

    38

    }

    }

    void Init_lcd(void){

    lcd_cmd(0x3c);lcd_cmd(0x0C);lcd_cmd(0x06);lcd_cmd(0x14);lcd_cmd(0x1C);lcd_cmd(0x01);

    }void cursor_position(unsigned char d){

    lcd_cmd(d+0x80);}

    Interfacing of seven segment display

    VCC

    R19 220E

    R20 220E

    R21 220E

    cR24 220E

    VCC

    R25 220E

    U16

    AT89S8252

    RST9

    XTAL218 XTAL119

    GND

    20

    PSEN29 ALE/PROG

    30

    EA/VPP

    31

    VCC

    40

    P1.0/T21

    P1.1/T2-EX2

    P1.23

    P1.34

    P1.4/SS5

    P1.5/MOSI6

    P1.6/MISO7

    P1.7/SCK8

    P2.0/A821

    P2.1/A922

    P2.2/A1023

    P2.3/A1124

    P2.4/A1225

    P2.5/A1326

    P2.6/A14

    27

    P2.7/A15 28

    P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.5/T115P3.6/WR16P3.7/RD17

    P0.0/AD039

    P0.1/AD138

    P0.2/AD237

    P0.3/AD336

    P0.4/AD435

    P0.5/AD534

    P0.6/AD633

    P0.7/AD732

    Y3

    8 Mhz

    12

    3

    4

    VCCVCC

    R34 220E

    R3510KSIP

    1

    23456789

    R3610K

    C4810uF/16V

    VCC

    P01P02P03P04P05P06P07

    VCC

    P08

    VCC

    d

    C49104

    VCCVCC

    VCC

    R37

    10k SIP

    1

    2345678

    e

    C42

    33PF

    C4333PF

    U374LS47

    D07 D11 D22 D36

    BI/RBO4

    RBI5

    LT3

    A13B12

    C11

    D10

    E9

    F15

    G14

    VCC

    16

    GND

    8

    U12

    74LS47

    D07 D11 D22 D36

    BI/RBO

    4

    RBI5

    LT3

    A

    13B12

    C11D10E9

    F 15

    G14

    V

    CC

    16

    GND

    8

    c

    VCC

    U13

    DIP20

    d

    2

    e

    1

    d

    7

    G/V

    3

    c

    4

    dot

    5

    e

    6

    G/V

    8

    dot

    9

    c

    1

    0

    b

    11

    a

    12

    G/v

    13

    g

    15

    b

    16

    a

    17

    G/V

    18

    f

    19

    g

    20

    f

    14

    VCC

    d

    R13 220E

    VCC

    R3 220E

    R7 220E

    R11

    10k SIP

    1

    2345678

    R14 220E

    R 8 220E

    e

    R 9 220ER15 220E

    R16 220E

    VCC

  • 7/31/2019 EMBEDDED SYSTEM.docx

    39/42

    39

    C code for seven segment display

    #include#define EOC P3_6#define SOC P3_7

    void delay(unsigned int i);unsigned char read_adc(void);void dec(unsigned int digit) ;void main (void){unsigned char a=0;P0=0x08;while(1){delay(0xffff);

    a=read_adc();dec(a);

    a++;delay(0xffff);dec(a);P0=1;

    delay(0xffff);

    P0=2;delay(0xffff);

    P0=3;delay(0xffff);

    P0=4;delay(0xffff);

    }}

    void delay(unsigned int i){while(i!=0){i--;}

  • 7/31/2019 EMBEDDED SYSTEM.docx

    40/42

    40

    }unsigned char read_adc(void)

    {unsigned char n=0;SOC=0;SOC=1;

    while(EOC==1){n=P2;

    }return n;

    }

    void dec(unsigned int x){

    x=(x/10)*6+x;P0=x;

    }

    void bcdconv(unsigned int mb)

    {

    unsigned char x;unsigned char y;x=mb&0x0f;x=x|0x30;y=mb&0xf0;y=y>>4;y=y|0x30;display(y);display(x);}

  • 7/31/2019 EMBEDDED SYSTEM.docx

    41/42

    41

    C-code for handling of INT0 interrupt:

    #include

    void delay(unsigned int i)

    {

    while(i!=0)

    i--;

    }

    void int0(void) interrupt 0

    {

    if(INT0==0)

    {

    while(1)

    {

    P0=0xF0;

    delay(0xFFFF);

    P0=0x0F;

    delay(0xFFFF);

    }}}

    void main(){

    EA=1;

    EX0=1;

    While(1)

    {

    P0=0xFF;

    delay(0xFFFF);

    P0=0x00;

    delay(0xFFFF);

    }}

  • 7/31/2019 EMBEDDED SYSTEM.docx

    42/42