You are on page 1of 42

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 a reactive & time constrained environment. Any electronic system that uses a CPU chip, but that is not a general-purpose workstation, desktop or laptop computer is known as embedded system. Such systems generally use microprocessors; microcontroller or they may use custom-designed chips or both. They are used in automobiles, planes, trains, space vehicles, machine tools, cameras, consumer and office appliances, cell phones, PDAs and other handhelds as well as robots and toys. The uses are endless, and billions of microprocessors are shipped every year for a myriad of applications. In embedded systems, the software is permanently set into a read-only memory such as a ROM or flash memory chip, in contrast to a general-purpose computer that loads its programs into RAM each time. Sometimes, single board and rack mounted generalpurpose 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

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 Microprocessors contain 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:


2

There are two types of Microcontroller architecture designed for embedded system development. These are: 1)RISC- Reduced instruction set computer 2)CISC- Complex instruction set computer Difference between CISC and RISC: CISC stands for Complex Instruction Set Computer. Most PC's use CPU based on this architecture. For instance Intel and AMD CPU's are based on CISC architectures. Typically CISC chips have a large amount of different and complex instructions. In common CISC chips are relatively slow (compared to RISC chips) per instruction, but use little (less than RISC) instructions. MCS-51 family microcontrollers based on CISC architecture. 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 mostly use compilers which never use complex instructions. Therefore fewer, simpler and faster instructions would be better, than the large, complex and slower CISC instructions. However, more instructions are needed to accomplish a task. Atmells AVR microcontroller based on RISC architecture. History of 8051 Intel Corporation introduced an 8-bit microcontroller called 8051 in 1981 this controller had 128 bytes of RAM, 4k bytes of on chip ROM, two timers, one serial port, and four ports 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 be processed by CPU. It has for I/O 8 bit wide. Features of the 8051:Feature ROM RAM Timer I/O pins Serial port Interrupt sources Quantity 4K bytes 128 bytes 2 32 1 6

8051 Architecture Overview


3

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 logic capabilities), 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.

Block diagram of 8051

Internal Architecture of 8051

Pin configuration of 8051

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 collector is used 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 out to 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.

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.

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 or output. 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 of providing some extremely important signals such as interrupts. This information applies both 8051 and 8031 chips. There functions are as follows:-

PORT 3 P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7

Function RxD TxD ___ Int0 ___ Int1 T0 T1 ___ WR ___ RD

pin 10 11 12 13 14 15 16 17

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.

10

ALE/PROG Address Latch Enable is an output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation, ALE is emitted at a constant rate of 1/ 6 the oscillator 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. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode.

PSEN Program Store Enable is the read strobe to external program memory. When the AT89S8252 is executing code from external program memory, PSEN is activated twice each machine cycle, 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 to fetch 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. EA should be strapped to VCC for internal program executions. This pin also receives the 12volt programming enable voltage (VPP) during Flash programming when 12-volt programming is selected. XTAL1 Input to the inverting oscillator amplifier and input to the internal clock operating circuit. XTAL2 Output from the inverting oscillator amplifier.

AT89s8252
AT89S8252 is an ATMEL controller with the core of intel MCS-51. It has same pin configuration as give above. The AT89S8252 is a low-power, high-performance CMOS 8-bit microcomputer with 8K bytes of Downloadable Flash programmable and erasable read only memory and 2K bytes of 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 in11

system through an SPI serial interface or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Downloadable Flash on a monolithic chip, the Atmel AT89S8252 is a powerful microcomputer which provides a highly flexible and cost effective solution to many embedded control applications. The AT89S8252 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 AT89S8252 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power Down Mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset. The Downloadable Flash can be changed a single byte at a time and is accessible through the SPI serial interface. Holding RESET active forces the SPI bus into a serial programming 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

12

Pin Description Furthermore, P1.4, P1.5, P1.6, and P1.7 can be configured as the SPI slave port select, data input/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 and verification.

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 during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation, ALE is emitted at a constant rate of 1/ 6 the oscillator 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. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode.
13

PSEN Program Store Enable is the read strobe to external program memory. When the AT89S8252 is executing code from external program memory, PSEN is activated twice each machine cycle, 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 to fetch 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. EA should be strapped to VCC for internal program executions. This pin also receives the 12volt programming enable voltage (VPP) during Flash programming when 12-volt programming 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:


14

assembly languages were developed that provided mnemonics for the machine code instructions, plus others features that made programming faster and less prone to error.The term mnemonic is frequently used in computer science and engg. literature to refer to codes and abbreviations that are relatively easy to remember .Asssembly language programs must be translated into machine 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 should not be typed in. 1.The label field allows the program to refer to a line of code by name.the label field can not exceed a certain no. of characters. 2.The assembly language mnemonics(instruction) and operands fields together perform the real 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 line by themselvess . 8051 basic instructions: we describe the basic instructions of the 8051 and give their formats with some examples. 1).arithmetic instructions 2).logical instructions 3).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 accumulator and 2 in the other register. eg. MOV R0,#20 MOV A,#10 ADD A,R0 MOV P1,A
15

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 in accumulator and 2 in the other register. eg. MOV R0,#20 MOV A,#10 MUL AB MOV 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 in accumulator and 2 in the other register. eg. MOV R0,#20 MOV A,#10 DIV AB MOV 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 some of the most widely used instructions.the logical instructions are used to perform logical operations likeAND,OR,EXOR etc. 1). MOV A,#35H ANL A,#0FH ;A=35H ;A AND 0FH(now A=05)

According to this operation, the content 35H gets ANDing with 0FH. 2). MOV A,#04 ORL A,#30H ;A=04 ;A=A OR 30H(now A=34H)

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

Jump,loop,call instructions:
16

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

We have used high level language for microcontroller programming due to its given advantages 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 this method. But it results in wastage of machine cycles of the micro-controller.
17

2) INTERRUPTS: Here every device tells the micro-controller when it needs the services from microcontroller. Actually, only 5 interrupts are available to the user in the 8051, but many manufacturers data sheets state that there are 6 interrupts since they include reset. The 6 interrupts in the 8051 are allocated as follows: 1).Reset: when the reset pin is activated, the 8051 jumps to address location 0000.this is the 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 interrupt vector table belong to timer0 and timer1, respectively. 3).Two interrupts are set aside for hardware external hardware interrupts. Pin numbers 12(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, automobiles and appliances. It allows the isolation of two separate sections of a system with two different voltage sources. The electromechanical (or electromagnetic) relay (EMR) has 3 components: 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 be attracted 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 or closed. In choosing a relay, the following characteristics need to be considered: 1) The contacts can be normally open (NO) or normally closed (NC). In the 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. There can be one or more contacts (SPST, SPDT, DPDT relays). 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 few mA to 20mA. The relay has a minimum voltage below which the coil will not be energized. This minimum voltage is called the pull-in voltage.

2) 3)

18

INTERFACING OF VARIOUS DEVICES


1) LED Interfacing
VCC Q14 BC547A R62 D29

VCC 330E VCCVCC


31 40

LED

C48 104

Q15 R61 BC547A D28

8 Mhz 33pF C45 Y8


12

U10

4 3 33pF C46

19 18 XTAL1 XTAL2 9 RST

P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7

39 38 37 36 35 34 33 32

EA/VPP

VCC

VCC 330E Q16 R41 BC547A

LED

D27

VCC C47 10uF/16V R7 10K

12 13 P3.2/INT0 21 14 P3.3/INT1 P2.0/A8 22 P2.1/A9 23 15 P3.4/T0 P3.5/T1 P2.2/A10 24 P2.3/A11 25 P2.4/A12 26 P2.5/A13 27 P2.6/A14 28 P2.7/A15 P3.7/RD P1.0/T2 P3.6/WR P1.1/T2-EX PSEN P1.2 ALE/PROG P1.3 P3.1/TXD P1.4/SS P3.0/RXD P1.5/MOSI P1.6/MISO P1.7/SCK
GND 20

330E VCC Q17 R40 BC547A VCC

LED

D26

1 2 3 4 5 6 7 8

17 16 29 30 11 10

330E

LED

Q18 BC547A R63 VCC 330E

D25

LED

AT89S8252

Q19 BC547A R39 VCC 330E

D24

LED

Q20 BC547A R38 330E VCC

D23

LED

Q21 BC547A R37

D22

Hardware interfacing of LED with AT89s8252

330E

LED

Title <Title> Size Document Number Custom<Doc> Date: Tuesday , December 26, 2006 Sheet 1 of 1 Rev <Rev Code>

19

C code for Blinking LEDs connected on PORT2: #include<at89s8252.h> void 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: #include<at89s8252.h> void 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);
20

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.

21

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 between the 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. 1 2

NAME Vss Vdd


22

FUNCTION Ground +ve supply

3 4 5 6 7 8 9 10 11 12 13 14

Vee RS R/W E D0 D1 D2 D3 D4 D5 D6 D7

contrast Register select Read/Write Enable Data Bit 0 Data Bit 1 Data Bit 2 Data Bit 3 Data Bit 4 Data Bit 5 Data Bit 6 Data Bit 7

Three command control inputs. When this line is low, data bytes transferred to the display are treated as commands, and data bytes read from the display indicate its status. By setting the RS line high, character data can be transferred to and from the module. Pin 5 is (R/W) line. This line is pulled low in order to write commands or character data to the module, or pulled high to read character data or status information from its registers.

Pin 6 is Enable (E) line. This input is used to initiate the actual transfer of commands or character data between the module and the data lines. When writing to the display, data is transferred only on the high to low transition of this signal. However, when reading from the display, data will become available shortly after the low to high transition and remain 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 from the display, either as a single 8-bit byte or as two 4-bit nibbles. In the latter case, only the upper four data lines (D4 to D7) are used. This $-bit mode is beneficial when using a microcontroller, as fewer I/O lines are required.

23

J2

LCD

VCC

VCC

31

EA/VPP

Y1

VCC

33pF C1

40

U1

12

4 3 33pF C2

19 18 9 12 15

XTAL1 XTAL2 RST

P1.0/T2 P1.1/T2-EX P1.2 P1.3 P1.4/SS P1.5/MOSI P1.6/MISO P1.7/SCK

1 2 3 4 5 6 7 8 13 14

RS EN

P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15

VCC C3 10uF 16V R1 10K

Hardware intetrfacing of LCD with AT89s52 microcontroler

C code for LCD display #include <at89s8252.h> #define LCDPRT P1 #define RS P3_3 #define EN P3_4 void 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) {
24

20

AT89S52

GND

32 33 34 35 36 37 38 39

P0.7/AD7 P0.6/AD6 P0.5/AD5 P0.4/AD4 P3.7/RD P0.3/AD3 P3.6/WR P0.2/AD2 PSEN P0.1/AD1 ALE/PROG P0.0/AD0 P3.0/RXD P3.1/TXD

21 22 23 24 25 26 27 28 17 16 29 30 10 11

VCC

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
R52 56E

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;
25

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<at89s8252.h> #define LCDPRT P1 #define RS P3_3 #define EN P3_4 code 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);
26

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) {
27

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 the processor 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
28

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

29

Hardware interfacing of ADC-0804 for Temperature monitoring


CON16_0 LCD VCC VCC C13 104 VCC

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
RS EN R55 56E 3

U22 LM35/SO GND VCC 1

31

EA/VPP

VCC

33pF C4 Y2

40

CRY STAL U2

12

4 3 33pF C5

19 18 9 13 14

XTAL1 XTAL2 RST P3.3/INT1 P3.4/T0 P0.7/AD7 P0.6/AD6 P0.5/AD5 P0.4/AD4 P0.3/AD3 P0.2/AD2 P0.1/AD1 P0.0/AD0

P1.0/T2 P1.1/T2-EX P1.2 P1.3 P1.4/SS P1.5/MOSI P1.6/MISO P1.7/SCK

1 2 3 4 5 6 7 8 VCC

OUTPUT

VCC R53 1k VCC R6 220E

RS EN

VCC/VREF

R2 10K

AGND

GND

20

10

AT89S8252

SOC

GND

11 30 29 16 10 17

P3.1/TXD ALE/PROG 15 PSEN P3.5/T1 P3.6/WR P3.2/INT0 12 P3.0/RXD P3.7/RD

P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15

DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 INTR

+IN -IN VREF/2 CLKR CLKIN CS RD WR

9 19 4 1 2 3 C8 1uf /16v

EOC

R17 10K C7 150pF

Temprature monitoring

system

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 <at89s8252.h> #define LCDPRT P1 #define RS P3_3 #define EN P3_4 #define SOC P3_2 #define EOC P3_5
30

VCC

32 33 34 35 36 37 C6 38 10uF 16V 39

21 22 23 24 25 26 27 28

18 17 16 15 14 13 12 11

20

U4 ADC0804 6 7

C9 CAP

3
1 R5 10K U21 TL431 C14 1uf /16v

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)
31

{ 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;


32

if(digit<100) { temp=digit/10; display(table[temp]); temp=digit-temp*10; display(table[temp]); } if(digit>99 && digit<1000) { temp=digit/100; display(table[temp]); digit=digit-(temp*100); temp=digit/10; display(table[temp]); digit=digit-(temp*10); temp=digit; display(table[temp]); }

6) Serial communication between At89s8252 and PC a) Serial Transmission


VCC VCC C19 104

31

EA/VPP

Y4

VCC

33pF C16

40

CRY STAL U5

12

4 3 33pF C17

19 18 9 12 13 14 15

XTAL1 XTAL2 RST P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1

P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15

39 38 37 36 35 34 33 32 21 22 23 24 25 26 27 28 17 16 29 30 11 10

U6 11 12 7 8 C20 10UF/16V 1 3 2 C21 10UF/16V

16

VCC

C23 104 J7 13 14 10 9 4 5 6 C22 MAX232 10UF/16V

T1IN R1OUT T2OUT R2IN

VCC

VCC C18 10uF 16V R4 10K

SPT TXD SPT RXD

R1IN T1OUT T2IN

1 2 3 SERIAL PORT OF PC

GND

VCC

V+

20

AT89S8252

33

15

GND

1 2 3 4 5 6 7 8

P3.7/RD P1.0/T2 P3.6/WR P1.1/T2-EX PSEN P1.2 ALE/PROG P1.3 P3.1/TXD P1.4/SS P3.0/RXD P1.5/MOSI P1.6/MISO P1.7/SCK

C1+ C1-

C24 10UF/16V

R2OUT C2+ C2V-

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

#include<at89s8252.h> void 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; }


34

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

NETMAX
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 VCC

RS EN R54
VCC

56E

VCC VCC
31 40

C50 104

CRY STAL U11 33pF C34 Y9


12

4 3 33pF C35

19 18 9 12 13 14 15

XTAL1 XTAL2 RST P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P0.7/AD7 P0.6/AD6 P0.5/AD5 P0.4/AD4 P0.3/AD3 P0.2/AD2 P0.1/AD1 P0.0/AD0

P1.0/T2 P1.1/T2-EX P1.2 P1.3 P1.4/SS P1.5/MOSI P1.6/MISO P1.7/SCK P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.7/RD P3.6/WR PSEN ALE/PROG P3.1/TXD P3.0/RXD
GND

1 2 3 4 5 6 7 8 21 22 23 24 25 26 27 28 17 16 29 30 11 10

EA/VPP

RS EN

VCC

U12 11 12 7 8 C51 10UF/16V 1 3 2 C52 10UF/16V

VCC

32 33 34 35 36 37 C49 38 10uF 16V 39 R8 10K

16

VCC

C54 104 J8 13 14 10 9 4 5 6 C53 MAX232 10UF/16V

T1IN R1OUT T2OUT R2IN

VCC

SPT TXD SPT RXD

R1IN T1OUT T2IN

1 2 3 SERIAL PORT OF PC

C1+ C1V+
GND

C55 10UF/16V

R2OUT C2+ C2V-

VCC

20

AT89S8252

35

15

C- code for serial reception: #include <at89s8252.h> #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) {
36

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--;
37

} } 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 10KSIP

VCC R37 10k SIP

R35

VCC

VCC

C49

104

4 5 3 6 2 1 7

8 7 6 5 4 3 2
R3 220E B A F G E C D 12 13 15 14 9 11 10 VCC R7 R8 R9 R15 R19 R21 220E 220E 220E 220E 220E 220E

VCC

31

33PF

EA/VPP

VCC

C43 Y3 C42 3

40

8 Mhz

U16

BI/RBO RBI LT D3 D2 D1 D0

12

19 18 9

RST

R11 10k SIP VCC VCC

VCC C48 10uF/16V R36 10K

30 29

P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 ALE/PROG P2.6/A14 PSEN P2.7/A15 P3.7/RD P1.0/T2 P3.6/WR P1.1/T2-EX P3.5/T1 P1.2 P3.4/T0 P1.3 P3.3/INT1 P1.4/SS P3.2/INT0 P1.5/MOSI P3.1/TXD P1.6/MISO P3.0/RXD P1.7/SCK

21 22 23 24 25 26 27 28 17 16 15 14 13 12 11 10

20 19 18 17 VCC 16 15 14 13 12 11
VCC R13 220E R14 R16 R20 R24 R25 R34 220E 220E 220E 220E 220E 220E

33PF

XTAL1 XTAL2

P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7

39 38 37 36 35 34 33 32

P01 P02 P03 P04 P05 P06 P07 P08

9 8 7 6 5 4 3 2

VCC

16

VCC

GND

e c d

74LS47 U3

3 4 5 6 2 1 7

LT BI/RBO RBI D3 D2 D1 D0 U12 74LS47

20

AT89S8252

GND

1 2 3 4 5 6 7 8

38

GND

B A F G E D C

12 13 15 14 9 10 11

VCC

VCC

1 2 3 4 5 6 7 8 9 10
VCC e d c

e g d f G/V G/V c a dot b e g d f G/V G/v dot a c b

U13 DIP20

16

8 7 6 5 4 3 2

C code for seven segment display

#include<at89s8252.h> #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--; }


39

} 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); }

40

1) 8051 Interrupt Programming


C-code for handling of INT0 interrupt: #include<at89s8252.h> 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); }}

41

42