Introduction An embedded system is a special-purpose system in which the computer is completely encapsulated by the device it controls. Unlike a general-purpose computer, such as a personal computer, an embedded system performs predefined tasks, usually with very specific requirements. Since the system is dedicated to a specific task, design engineers can optimize it, reducing the size and cost of the product. Embedded systems are often mass-produced, so the cost savings may be multiplied by millions of items. Handheld computers or PDAs are generally considered embedded devices because of the nature of their hardware design, even though they are more expandable in software terms. This line of definition continues to blur as devices expand. Examples of embedded systems
• • • • • • • • • • •
automatic teller machines (ATMs) avionics, such as inertial guidance systems, flight control hardware/software and other integrated systems in aircraft and missiles cellular telephones and telephone switches computer equipment such as routers and printers engine controllers and antilock brake controllers for automobiles home automation products, like thermostats, air conditioners, sprinklers, and security monitoring systems handheld calculators household appliances, including microwave ovens, washing machines, television sets, DVD players/recorders medical equipment handheld computers videogame consoles
The first recognizably modern embedded system was the Apollo Guidance Computer, developed by Charles Stark Draper at the MIT Instrumentation Laboratory. Each flight to the moon had two. They ran the inertial guidance systems of both the command module and LEM. At the project's inception, the Apollo guidance computer was considered the riskiest item in the Apollo project. The use of the then new monolithic integrated circuits, to reduce the size and weight, increased this risk.
The first mass-produced embedded system was the Autonetics D-17 guidance computer for the Minuteman missile, released in 1961. It was built from discrete transistor logic and had a hard disk for main memory. When the Minuteman II went into production in 1966, the D-17 was replaced with a new computer that was the first high-volume use of integrated circuits. This program alone reduced prices on quad nand gate ICs from Characteristics Embedded systems are designed to do some specific task, rather than be a general-purpose computer for multiple tasks. Some also have real-time performance constraints that must be met, for reason such as safety and usability; others may have low or no performance requirements, allowing the system hardware to be simplified to reduce costs. For high volume systems such as portable music players or mobile phones, minimizing cost is usually the primary design consideration. Engineers typically select hardware that is just “good enough” to implement the necessary functions. For example, a digital set-top box for satellite television has to process large amounts of data every second, but most of the processing is done by custom integrated circuits. The embedded CPU "sets up" this process, and displays menu graphics, etc. for the set-top's look and feel. The software written for embedded systems is often called firmware, and is stored in ROM or Flash memory chips rather than a disk drive. It often runs with limited hardware resources: small or no keyboard, screen, and little RAM memory. Embedded systems reside in machines that are expected to run continuously for years without errors and in some cases recover by them if an error occurs. Therefore the Software is usually developed and tested more carefully than that for Personal computers, and unreliable mechanical moving parts such as Disk drives, switches or buttons are avoided. Recovery from errors may be achieved with techniques such as a watchdog timer that resets the computer unless the software periodically notifies the watchdog. User interfaces Embedded systems range from no user interface at all - dedicated only to one task - to full user Interfaces similar to desktop operating systems in devices such as PDAs. In between are devices with small character- or digit-only displays and a few buttons. Therefore usability considerations vary widely. On larger screens, a touch-screen or screen-edge soft buttons also provides good flexibility while minimizing space used. The advantage of this system is that the meaning of the buttons can change with the screen, and selection can be very close to the natural behavior of pointing at what's desired.
Basic Electronic Components
Resistors are components that have a predetermined resistance. Resistance determines how much current will flow through a component. Resistors are used to control voltages and currents. A very high resistance allows very little current to flow. Air has very high resistance. Current almost never flows through air. (Sparks and lightning are brief displays of current flow through air. The light is created as the current burns parts of the air.) A low resistance allows a large amount of current to flow. Metals have very low resistance. That is why wires are made of metal. They allow current to flow from one point to another point without any resistance. Wires are usually covered with rubber or plastic. This keeps the wires from coming in contact with other wires and creating short circuits. High voltage power lines are covered with thick layers of plastic to make them safe, but they become very dangerous when the line breaks and the wire is exposed and is no longer separated from other things by insulation. Resistance is given in units of ohms. (Ohms are named after Mho Ohms who played with electricity as a young boy in Germany.) Common resistor values are from 100 ohms to 100,000 ohms. Each resistor is marked with colored stripes to indicate its resistance. Variable Resistors
Variable resistors are also common components. They have a dial or a knob that allows you to change the resistance. This is very useful for many situations. Volume controls are variable resistors. When you change the volume you are changing the resistance which changes the current. Making the resistance
but with drainage valves opening and closing. In our water analogy. This would cause a system wide voltage drop. some capacitors are polarized. they can also be used for timing circuits.
Capacitors are like electron storage banks. Making the resistance lower will let more current flow so the volume goes up. If a capacitor has a lead that is longer than the other. The value of a variable resistor is given as its highest resistance value. What do you do when batteries cannot supply current as fast as you circuit drains them? How do you prevent sudden current spikes that could fry your robot circuitry? The solution to this is capacitors. Robot motors cause current fluctuations in your circuit which you need to control. Timing circuits can be used to generate signals such as PWM or be used to turn on/off motors in solar powered BEAM robots. the capacitor will make up for it. Quick note. Since capacitors take time to charge. The
. Just a side note. it is bad to use the same power source for both your circuit and your motors. If your circuit is running low. So don't do it. meaning current can only flow one direction through them. Power surge /drainage management The problem with using robot components that drain a large amount of power is sometimes your battery cannot handle the high drain rate. it will deliver electrons to your circuit. Now why would you? Well radio signals require very fast current changes. For example. and time to discharge. A variable resistor may also be called a potentiometer (pot for short). Capacitors
Now suppose you want to control how the current in your circuit changes (or not changes) over time.higher will let less current flow so the volume goes down. Motors and servos being perfect examples. assume the longer lead must always connect to positive. or at least causing it to not work properly. a 500 ohm variable resistor can have a resistance of anywhere between 0 ohms and 500 ohms. often resetting your microcontroller. Or suppose your robot motors are not operating at its full potential because the battery cannot supply enough current. think of this as a water tank with water always flowing in.
For example. When you flip a mechanical switch. So if your robot was counting the number of times a switch is flipped. Usually when current is flowing through a diode. It is also bad to allow a large capacitor to remain fully charged when you turn off your robot. Exactly how much will depend on how often you expect your motor to change speed and direction. It is called the cathode. but note that a microcontroller can take hundreds of readings in a single microsecond. it may take a long time to charge up when you first turn your robot on. Normally this is too small of a time for anyone to care (or even notice). They have a positive side (leg) and a negative side. When the voltage on the positive leg is higher than on the negative leg then current flows through the diode (the resistance is very low). if your 20V motors will use 3 amps. So just make sure your capacitor is rated higher than your highest expected. use a 3mF30mF 50V rated capacitor. Just note that if your capacitor is too large. Fortunately they do not overheat if given excessive amounts of current. Get a capacitor that is rated at least twice the voltage you expect to go through it. it will drain of electrons and your circuit will be left with a deficit. The positive end is called the anode. Have it rated at 1mF-10mF for every amp required. When the voltage is lower on the positive leg than on the negative leg then the current does not flow (the resistance is very high). Next to any on/off switch or anything that that could affect power suddenly should have a capacitor across it? Capacitors can eliminate switch bouncing. Some things could accidentally short and fry.solution is to place a large electrolytic capacitor between the source and ground of your power source. as well as momentum of what you are actuating. the voltage on the positive leg is 0. If it is too small.65 volts higher than on the negative leg. The negative leg of a diode is the one with the line closest to it. So how do you stop this? Use a small ceramic capacitor! Just experiment until you find the power capacitance value. So use a simple power on LED in your motor circuit to drain the capacitor after your robot is turned off. a single flip can count as dozens. Diodes
Diodes are components that allow current to flow in only one direction. Switches 5
. Capacitors can also be used to prevent power spikes that could potentially fry circuitry. then can explode with smoke. If your capacitor is not rated properly for voltage. the switch actually bounces several times within a microsecond range.
Sometimes they are labeled on the flat side of the transistor. The important thing to remember about diodes (including LEDs) is that current can only flow in one direction. Even though they are simple.) When the switch is OFF. and the Emitter leg is on the right. The ones in the Pentium are smaller than the ones we will use but they work the same way. that means there is an open circuit (no current flows. The LED
An LED is the device shown above. For example. Transistor Symbol
.Switches are devices that create a short circuit or an open circuit depending on the position of the switch. and Emitter (E). and lights light up. Besides red. Base (B). they are the most important electrical component. the Collector leg is on the left.5 million transistors. transistors are almost the only components used to build a Pentium processor. The letters LED stand for Light Emitting Diode. the Base leg is in the middle. If the round side is facing you. they can also be yellow. When the switch is OFF there is no connection. ON means short circuit (current flows through the switch. Transistors always have one round side and one flat side. When the switch is ON it looks and acts like a wire. green and blue. For a light switch. lights go out. A single Pentium chip has about 3. Transistors that we will use in projects look like this:
The transistor has three legs.
Transistors are basic components in all of today's electronics. They are just simple switches that we can use to turn things on and off. the Collector (C).
) If there is no current flowing to the Base.
. there will be a path from the Collector (C) to the Emitter (E) where current can flow (The Switch is On. then no current can flow from the Collector to the Emitter.The following symbol is used in circuit drawings (schematics) to represent a transistor. (The Switch is off.
Basic Circuit The Base (B) is the On/Off switch for the transistor.) Below is the basic circuit we will use for all of our transistors. If a current is flowing to the Base.
digital computers and automation systems. They are used in a wide variety of applications throughout industry. When the applied current or voltage exceeds a threshold value. which operates either to close the open contacts or to open the closed contacts. such as in telephone exchanges. which is powered by AC or DC current.
How do relays work?
All relays contain a sensing unit.Relays
A relay is usually an electromechanical device that is actuated by an electrical current. the electric coil. long life. The first circuit is called the control circuit. relaying the action from one circuit to another. and proven high reliability. in effect. The current flowing in one circuit causes the opening or closing of another circuit. The current flowing in one circuit causes the opening or closing of another circuit. The magnetic force is. it generates a magnetic force that actuates the switch mechanism. the second is called the load circuit.
. the coil activates the armature. A relay is usually an electromechanical device that is actuated by an electrical current. Relays are like remote control switches and are used in many applications because of their relative simplicity. When a power is supplied to the coil.
These are found in computers. contactors always have double-make contacts. Time-Delay Relay: The contacts might not open or close until some time interval after the coil has been energized. Electromechanical Relay 2. Electromechanical relays have moving parts. Electromechanical Relays General Purpose Relay: The general-purpose relay is rated by the amount of current its switch contacts can handle. no heat sink is required. Most versions of the general-purpose relay have one to eight poles and can be single or double throw. whereas solid state relays have no moving parts. Advantages of Electromechanical relays include lower cost.
Power Relay: The power relay is capable of handling larger power loads – 1050 amperes or more. Because of these high power requirements. it’s used mainly to control high voltages and currents in industrial electrical applications.Types of Relays
There are two basic classifications of relays: 1. Solid State Relay. and other consumer electronic equipment and appliances. copy machines. and they can switch AC or DC with equal ease. This is called delay-on-operate. They are usually single-pole or double-pole units. multiple poles are available.
Contactor: A special type of high power relay. 1.
The drawback to using a solid state relay is that it can only accomplish single pole switching. and triggers a solid state switch that either opens or closes the circuit under control. and fast response. Advantages of Solid State Relays include low EMI/RFI. long life.
. the light is turned on and shines across an open space. a part of the device senses the presence of the light. or light emitting diode. or adjusted by a knob on the relay itself. no contact bounce.Delay-on-release means that the contacts will remain in their actuated position until some interval after the power has been removed from the coil. The timing of these actions may be a fixed parameter of the relay. Often. or remotely adjusted through an external circuit. On the load side of this space. Solid State Relays
These active semiconductor devices use light instead of magnetism to actuate a switch. A third delay is called interval timing.
2. When control power is applied to the device’s output. Contacts revert to their alternate position at a specific interval of time after the coil has been energized. no moving parts. The light comes from an LED. solid state relays are used where the circuit under control must be protected from the introduction of electrical noises.
there will be two data lines: One transmission and one receive line. Parallel ports are mainly meant for connecting the printer to the PC. all the 8 bits of a byte will be sent to the port at a time and a indication will be sent in another line. Parallel ports are easy to program and faster compared to the serial ports. There will be some data lines. Let us know the basic difference between working of parallel port and serial port. stop bit and parity bit to detect errors. following figures will explain how they are sent to the serial and parallel ports respectively. some control and some handshaking lines in parallel port. To send a data in serial port. We can understand why parallel port communication is faster compared to that of serial.
. ports are used mainly for two reasons: Device control and communication.Parallel port basics: In computers. We can program PC's Parallel ports for both. Because of this reason parallel ports are not used in long distance communications. it has to be sent one bit after another with some extra bits like start bit. In serial ports. But we can program this port for many more applications beyond that. If three bytes of data 01000101 10011100 10110011 is to be sent to the port. But main disadvantage is it needs more number of transmission lines. But in parallel port.
We need these addresses in programming. Register Data register (Base Address + 0) Status register (Base Address + 1) Control register (Base Address + 2) LPT1 0x378 0x379 0x37a LPT2 0x278 0x279 0x27a
Note: All the parallel ports do not have bidirectional capability. bidirectional ports are introduced. By default. But latter. Connecting cable will combine these connecters using following convention. to make parallel port capable of communicating with other devises. we need to set the bit 5 of control register. Earlier parallel ports had only output enabled in data pins since printers only inputs data. data port is output port. there will be a 36-pin Centronics connector. data.
.In the PC there will be D-25 type of female connector having 25 pins and in the printer. control and status registers will have following addresses. Pin structure of D-25 and Centronics connecters are explained bellow. To enable the bidirectional property of the port.
Click Device manager.
Double Click on the ECP Printer Port (LPT1) or any other LPT port if available.
You will get a tree structure of devices. Its pin structures can be found in the connector as follows:
. Make sure that "Use this Port (enable)" is selected. In that Expand "Ports (Com1 & LPT)". follow this procedure:
Right click on My Computer.
Select tab recourses. In that you will get the address range of port.
You will get details of LPT port.
To start programming. go to "Properties". you will need a D-25 type Male connector.
Select the tab Hardware.To know the details of parallel ports available in your computer.
In that. we need to write kernel mode driver. In DOS we have commands to access the port directly. outport() writes the lower byte to PORTID and higher byte to PORTID+1. these programs will not work on the systems based on Windows XP. Function inport() will return a word having lower byte as data at PORTID and higher byte as data at PORTID+2. outport( PORTID. Main bitwise operators that we need are bitwise AND '&' and bitwise OR '|'. write a byte with corresponding bit 1 and all other bits 0. So. we need to input the value of corresponding register as a byte. data). to make particular bit low. inportb() function returns byte at PORTID. data = inport( PORTID). there are following functions used for accessing the port:
• • • •
outportb( PORTID. we can use this function to read status and control registers together. data = inportb( PORTID). outportb() function write the data to PORTID. you need to know basic bitwise operations.
. If you include DOS. To program the parallel port in these systems.Programming the Parallel Port in DOS:
To start programming the port. write a byte with corresponding bit 0 and all other bits 1.H header.
outport() function sends a word to port. But. outportb() sends a byte to port and inportb() reads a byte from the port. otherwise as functions. data). So. In Turbo C. To make a particular bit in a byte high without affecting other bits. For security reasons. So this can be used to write data and control together. Similarly. these functions will be considured as macro. OR it with original byte. we have to find out whether the corresponding bit is high or low using bitwise operators. AND it with original byte. outport() and outportb() returns nothing. We can't access the pins individually. When we want to find out whether particular pin of the port is high or low. inport() reads a word from the port. we will use DOS. Windows NT or higher versions. higher versions of the windows do not allow accessing the port directly.
bit no. Pin 11 (active low) is 0 and all other pins are 1 means it is OK. 7654 3210 data : XXXX 1XXX & with : 0000 1000 (0x08 ) -> 0000 1000 (0x08 -> bit 3 is high ) bit
bit no. To understand bitwise operations: you want to find data in pin 15.Let us start with inputting first. copy it and run in Turbo C or Borland C without anything connected to parallel port. 7654 3210 data : XXXX 0XXX & with : 0000 1000 (0x08 ) -> 0000 0000 (0x00 -> 3 is low)
. Then you should see data available in status register and pin numbers 10. Here is an example program. 0therwise. 11. 12. 13 and 15 of the parallel port. value of (data & 0x08) will be 0x08 if bit 3 of register is high.
Connect the male connector of the parallel port cord to the PC 3. 6 5 19 4 9 3 2 20 7 8
. Now connect the Female Connector of cord with seven segment C-5611 as shown in table. Open windows 98 as OS 2. Parallel Port Connector cord. Jumper Wires Bread Board.
Table: Connection between Seven Segment and Female Connector
Seven Segment Pin No. 1 2 3 4 5 6 7 8 9 10
Female Connector Pin No. Procedure: 1.Interfacing of Seven Segment with Parallel port:Apparatus: Seven segment C-5611.
Segment Display and Hexadecimal Equivalent
Pin Out of seven segment
Relationship of decimal No. .
Variations of the 8051 with clock speeds up to 40MHz and voltage requirements down to 1.085 microseconds).Microcontrollers
The 8051 Microcontroller Overview The 8051 family of micro controllers is based on an architecture which is highly optimized for embedded control systems.5 volts are available. Inverting this will provide the amount of time taken by each instruction cycle (1. The time required for any 8051 instruction can be computed by dividing the clock frequency by 12. Second only to the Motorola 68HC11 in eight bit processors sales. Each of the twelve oscillator periods is used for a special function by the 8051 core such as op code fetches and samples of the interrupt daisy chain for pending interrupts.059MHz clock. inverting that result and multiplying it by the number of processor cycles required by the instruction in question. These manufacturers have added numerous features and peripherals to the 8051 such as I2C interfaces. • • • • • • • an eight bit ALU 32 discrete I/O pins (4 groups of 8) which can be individually accessed two 16 bit timer/counters full duplex UART 6 interrupt sources with 2 priority levels 128 bytes of on board RAM separate 64K byte address spaces for DATA and CODE memory
. if you have a system which is using an 11. Philips. watchdog timers. This wide range of parts based on one core makes the 8051 family an excellent choice as the base architecture for a company's entire line of products since it can perform many functions and developers will only have to learn this one platform. This gives an instruction frequency of 921583 instructions per second. Therefore. The basic architecture consists of the following features: One 8051 processor cycle consists of twelve oscillator periods. the 8051 family of microcontrollers is available in a wide array of variations from manufacturers such as Intel. and Siemens. It is used in a wide variety of applications from military equipment to automobiles to the keyboard on your PC. and pulse width modulated outputs. analog to digital converters. you can compute the number of instructions per second by dividing this value by 12.
Address overlaps are resolved by utilizing instructions which refer specifically to a given address space.Memory Organization The 8051 architecture provides the user with three physically distinct memory spaces which can be seen in Figure A . However. Each memory space consists of contiguous addresses from 0 to the maximum size. of the memory space.1. This segment can be up to 64K (since it is addressed by 16 address lines). This makes upgrades to the product easy to do since new software can be downloaded into the EEPROM rather than having to disassemble it and install a new EPROM.8051 Memory Architecture
The CODE Space
The first memory space is the CODE segment in which the executable program resides.1 . battery backed SRAMs can be used in place of an EPROM. Additionally. The processor treats this segment as read only and will generate signals appropriate to access a memory device such as an EPROM. This method offers the same capability to upload new software to the unit as does an
Figure A . Many embedded systems these days are using EEPROM which allows the memory to be overwritten either by the 8051 itself or by an external device. The three memory spaces function as described below. this does not mean that the CODE segment must be implemented using an EPROM. in bytes.
Register bank switching allows not only for quick parameter passing. The first sub segment consists of the four sets of register banks which compose the first 32 bytes of RAM. and can also help avoid hassles over an in circuit emulator which is usually a rare commodity. The register being used as the memory pointer must contain the address of the byte to be retrieved or altered. Therefore. The DATA Space The second memory space is the 128 bytes of internal RAM on the 8051. In addition to executable code. These two bits combine into a number from 0 to 3 (with RS1 being the most significant bit) which indicates the register bank to be used. Using an SRAM in place of an EPROM in development systems allows for rapid downloading of new code into the target system. To facilitate this. it helps avoid the cycle of programming/testing/erasing with EPROM’s. due to the limited amount of memory in this segment. The selection of register banks is changeable at any time via the RS1 and the RS0 bits in the Processor Status Word (PSW). This access time is much quicker than access to the XDATA segment because memory is addressed directly rather than via a memory pointer such as DPTR which must first be initialized.EEPROM. The DATA segment contains two smaller segments of interest. so does the software in it. These instructions can take one or two processor cycles depending on the source/destination data byte. the 8051 provides instructions which allow rapid access to tables via the data pointer (DPTR) or the program counter with an offset into the table optionally provided by the accumulator. The 8051 contains several single bit instructions which are often very useful in control applications and aid in replacing external
. The 8051 can use any of these four groups of eight bytes as its default register bank. However. when the battery supplying the RAM eventually dies. When this can be done. however. but also opens the door for simplifying task switching on the 8051. This segment is referred to as the BDATA segment. a table's base address can be loaded in DPTR and the element of the table to access can be held in the accumulator. Such allocation must be done with care. frequently used variables and temporary scratch variables are usually assigned to the DATA segment. The RAM locations in this segment are accessed in one or two cycles depending on the instruction. The addition is performed by the 8051 during the execution of the instruction which can save many cycles depending on the situation. This segment is typically referred to as the DATA segment. The second sub-segment in the DATA space is a bit addressable segment in which each bit can be individually accessed. it is common practice with the 8051 to store fixed lookup tables in the CODE segment. or the first 128 bytes of internal RAM on the 8052. Variables stored in the DATA segment can also be accessed indirectly via R0 or R1. and does not have any sort of read/write cycle limitations such as an EEPROM has. This means that oftentimes. The bit addressable segment consists of 16 bytes (128 bits) above the four register banks in memory.
the UART.7. These registers are accessed by the same set of instructions as the bytes and bits in the DATA segment. These registers are referred to as special function registers (or SFRs for short). you can refer to the EA bit of the Interrupt Enable SFR as EA. The bits in the bit addressable SFRs can either be accessed by name.combinatorial logic with software in the 8051 thus reducing parts count on the target system. A memory map of the SFRs indicating the registers which are bit addressable is shown in Table A . The SFRs control things such as the function of the timer/counters. Thus. or 0AFH. index or bit address.1. and the interrupt sources as well as their priorities.
Special Function Registers
Control registers for the interrupt system and the peripherals on the 8051 are contained in internal RAM at locations 80 hex and above. It should be noted that these 16 bytes can also be accessed on a "byte-wide" basis just like any other byte in the DATA space. IE. Many of them are bit addressable.
the DATA segment is a very attractive place to store any frequently used variables. and clear operations on bits as well as moving bit values as one would normally move byte values. loading R0 or R1 will take minimum of one cycle in addition to the two cycles imposed by the memory access itself. Therefore. . complement. It is possible to fill this segment entirely with 64K of RAM if the 8051 does not need to perform any I/O with devices in its bus or if the designer wishes to cycle the RAM on and off when I/O devices are being accessed via the bus. Because of this. . Read or write operations to this segment take a minimum of two processor cycles and are performed using either DPTR. . move the bit value at address 22H to the carry bit or the bit value at address 23H into the carry bit and the carry bit into bit address 24H
. it is easy to see that a typical operation with the XDATA segment will. address conflicts between IDATA RAM and the SFRs are resolved by the type of memory access being performed.The IDATA Space Certain 8051 family members such as the 8052 contain an additional 128 bytes of internal RAM which reside at RAM locations 80 hex and above. 23H 24H. C . in general. Similarly. The XDATA Space The final 8051 memory space is 64K in length and is addressed by the same 16 address lines as the CODE segment. R0. This segment of RAM is typically referred to as the IDATA segment. Bit processing and Boolean logic The 8051 contains a single bit Boolean processor which can be used to perform logical operations on any of the 128 addressable bits in the BIT segment. take a minimum of three processor cycles. This segment usually consists of some sort of RAM (usually an SRAM) and the I/O devices or external peripherals to which the 8051 must interface via its bus. . the 128 addressable bits in the SFRs.
MOV ORL ANL C. This space is typically referred to as the external data memory space (or the XDATA segment for short). Because the IDATA addresses and the SFR addresses overlap. Methods for performing this technique will be discussed in chapters later in this book. 22H C. it usually takes two processor cycles or more to load the desired address in addition to the two cycles required to perform the read or write operation. since the IDATA segment can only be accessed via indirect addressing modes. XOR. set. . In the case of DPTR. The 8051 can perform OR. and any of the 32 I/O lines (port 0 through port 3). AND. or R1.
. set the timeout value check the bit and force P0.0 to logic level 0 if set decrement the timeout counter exit the routine
While the second routine may not offer a huge amount of savings in the code. One such branch which is especially useful is the “jump if bit is set and clear bit” instruction. L2 P0.0.0 . There will be many situations in your use of assembly code on the 8051 controller where this instruction will come in handy. This "branch and clear" can be performed in two processor cycles and saves a cycle or two over splitting the jump and the clear into two separate op codes. exit the routine
Using the JBC instruction. set the timeout value .0 to logic level 0 . . This routine would have to decrement a timeout value and exit the polling loop when this timeout is exceeded. As an example. the same routine would be coded as follows. decrement the timeout counter .0. and sample again . When pin P0. .
MOV L2: JBC DJNZ L1: RET timeout. it does make the code a little simpler and more elegant.There are also conditional branches which use addressed bits as the condition. but could not wait indefinitely. #TO_VAL P0. the routine would look like the following. #TO_VAL P0.
.0 to set. suppose that you had to write a routine which waited for pin P0. .
MOV L2: JB DJNZ L1: CLR RET timeout. L1 timeout. force P0. With normal logic flow. L2 . L1 timeout. check the bit .0 sets. the processor must force it back to 0 and exit the polling loop.
Timer 0 control bit.3
. The TCON register also contains the overflow flags for the timers. The timer/counters are started or stopped by changing the timer run bits (TR0 and TR1) in TCON. If TR1=0. Timer 1 control bit. Interrupt 1 type control bit. If TR0=1. If IT1=0. Timer 0 overflow flag.On-Board Timer/Counters The standard 8051 has two timer/counters (other 8051 family members have varying amounts). and the counter is incremented only when a 1 to 0 transition is detected (which will require two samples). timer 1 stops. timer 1 runs.7. It should be noted that the software can set or clear this flag at any time. Each timer/counter can be function as a free running timer (in which case they count processor cycles) or can be used to count falling edges on the signal applied to their respective I/O pin (either T0 or T1). Cleared by processor upon vectoring to the interrupt service routine. the timer/counters can force a software interrupt when they overflow. External interrupt 1 edge flag. they set their respective flag (TF0 or TF1) in this register.e. If desired. Therefore. Timer Control Register (TCON) . If TR0=0. The TCON SFR is detailed below in Table A .3. Set when timer 1 overflows. When the timers overflow. Set when a valid falling edge is detected at pin P3.Bit Addressable
TF1 TR1 TF0 TR0 IE1 IT1
Timer 1 overflow flag. each of which is a full 16 bits. timer 1 runs. When used as a counter. The TCON (Timer Control) SFR is used to start or stop the timers as well as hold the overflow flags of the timers. The software can freeze the operation of either timer as well as restart the timers simply by changing the TRx bit in the TCON register. Cleared by processor upon vectoring to the interrupt service routine. When the processor detects a 0 to 1 transition in the flag. the input signal must have a frequency equal to or lower than the instruction cycle frequency divided by 2 (i. an interrupt can be prevented as well as forced by the software.3. If IT1=1. Cleared by hardware when the interrupt is serviced. interrupt 1 is triggered by a falling edge on P3. an interrupt occurs if it is enabled. If TR1=1. Set when timer 0 overflows. timer 1 stops.: the oscillator frequency /24) since the incoming signal is sampled every instruction cycle. interrupt 1 is triggered by a low logic level on P3.
When a timer is forced to count processor cycles it can do this either under hardware or software control. In the hardware control mode.
. Set when a valid falling edge is detected at pin P3. Software control is commanded by setting the GATE bit of TMOD to 0. In this case.
The source for the timer can be configured by altering the C/T bit in TMOD. When a low is detected at the INTx pin. The layout of the TMOD register (which is not bit addressable) is shown below. interrupt 1 is triggered by a falling edge on P3. Setting this bit false will force counting of processor cycles.2
IT0 IT0=0. By changing TMOD. the software can control the mode of both timers as well as the source they use to count (the signal at their I/O pin or the processor cycles). This is useful for measuring pulse widths of signals on the INTx pin if one does not mind surrendering an external interrupt source to the incoming signal. If interrupt 0 is triggered by a low logic level on P3.2. Cleared by hardware when the interrupt is serviced. Setting this bit to true will force the timer to count pulses on the I/O pin assigned to it. the timer will count any time its TRx bit in the TCON register is high. The upper nibble of TMOD controls the operation of timer 1 and the low nibble controls the operation of timer 0. Interrupt 0 type control bit.
The timers are configured by altering the value in the TMOD (timer mode) SFR. the timer will stop.IE0
External interrupts 0 edge flag. If IT0=1.2. both the TRx bit and the INTx pin on the chip must be high for the timer to count.
or as a timer/counter which is polled by the software. The low byte of the timer (TL0 or TL1) is used as the counter and the high byte of the timer (TH0 or TH1) holds the reload value for the counter. it can be used for any purpose which will not require the overflow interrupt such as a baud rate generator for the UART. In mode 0. the timer/counter will behave like a 13 bit counter. Both timer 0 and timer 1 operate in the same way for mode 0.
Timer Mode 3
In mode 3. When the counter overflows. however. but the counter in TH0 takes over the control flags in TCON from timer 1. This implies that timer 1 can no longer force interrupts.Timer Mode 0 and Mode 1
The timer/counters can be operated in one of four modes. the timer is set up as an eight bit counter which automatically reloads whenever an overflow condition is detected.
Timer Mode 2
In mode 2. When timer 1 is placed in mode 3 it simply freezes. This is useful when an application must use a UART mode which requires baud rate generation from timer 1 and also requires two timer/counters. Timer 1 is often used in this mode to generate baud rates for the UART. Both timer 0 and timer 1 function identically in mode 2. under software control. timer 0 becomes two eight bit counters which are implemented in TH0 and TL0. the TF0 or TF1 (timer flag) bit in the TCON (timer control) SFR is set. the value in THx is loaded into TLx and the timer continues counting from the reload value. The operation of the timers in mode 1 is the same as it is for mode 0 with the exception that all sixteen bits of the timer are used instead of only thirteen. The counter implemented in TL0 maintains control of all the timer 0 flags.
. This will cause the appropriate timer interrupt (assuming it is enabled). When the timer/counter overflows.
UART Mode 0
In mode 0 the UART acts as an eight bit shift register clocking data in and out at a baud rate of 1/12th of the oscillator frequency.On-Board UART
The 8051 features an on board. The SCON register allows the user to select the UART mode. The baud rate is variable for all modes except the eight bit shift mode and one of the inter processor modes. The UART is configured via the SCON (Serial CONtrol) SFR. However. SCON is illustrated in Table A . full duplex UART which is under software control. This mode is useful for situations in which the micro controller is used to interface to a serial device such as an EEPROM which has a serial eight bit interface format.10. the software must be capable of responding to an incoming byte within one serial byte time. the buffer will be overwritten as the next incoming byte is completed. Therefore. Therefore mode 0 does not support full duplex since the RXD pin is used for all incoming and outgoing data and the TXD pin is used to echo the shift clock. after one byte time. Transmission of a byte begins when the SBUF SFR is the destination register of a move instruction.
The UART features a one byte buffer for incoming data so that another byte can be ringing into the UART before the last byte has been read. and check UART status. The 8051 supports standard ten bit frames as well as an eleven bit frame designed for inter processor communications and a high speed 8 bit shift register mode. Data is sent LSB first and enters and exits the UART via the RXD pin. At
. This is also true for outgoing data assuming that it is required to be back to back. enable reception.
Oftentimes the resultant baud rate may be close enough to allow the system to work. If timer 1 is going to be used to generate the desired baud rate of the UART. RCAP2L]=65536-OscFreq/(32*Baud Rate)
. This evaluation must be made by the developer.216MHz oscillator and you want to generate a baud rate of 9600 baud you must go through these steps. [RCAP2H. The TI and RI interrupt signals are activated halfway through the transmission or reception of the stop bit. Overflow interrupts should be disabled for the timer being used to generate the baud rate. This gives a reload value of 251 or 0FBH for TH1. Reception begins when the REN bit of the SCON register is set true.
UART Mode 1
In mode 1 of the UART. if you have an 8051 which is using a 9. This mode is suitable for communications to most serial devices including personal computers. you must start from the desired baud rate and solve the following equation to obtain the reload values. Dividing these two values gives an answer of 5 which you subtract from 256. this will allow the software time to respond to the interrupt and load SBUF with the next byte in back to back during data block transfers. the numerator becomes 9216000 and the denominator becomes 3686400. Dividing these two values gives a result of 2. From this it is obvious that the reload value given by this function will not be an integer. The SMOD bit in the PCON (power control) SFR can be set high to double the baud rate implemented by the UART. optionally. For an 8052 using timer 2 to generate the baud rate. The RI bit is set when the eighth bit is clocked in. First.this point. the eight bits are clocked out and the TI bit is set when the transmission of the eighth bit is complete.5. Rerunning the equation with K=2 gives a numerator of 18432000 and a denominator of 3686400. by timer 2 in the baud rate generating mode on an 8052. Reload values which are not integers must be very close to the next integer. The amount of processing time available depends on the baud rate in use and the oscillator frequency being used to drive the 8051. you must compute the reload value for TH1 using the following equation: TH1=256-(K*OscFreq)/(384*Baud Rate) K=1 if SMOD=0 K=2 if SMOD=1 Any baud rate which does not give a positive reload value less than 256 can not be generated by the 8051 at the given clock frequency. The baud rate is variable and is controlled by the overflow rate of timer 1 in the auto reload mode or. and one stop bit. Again. run the equation for K=1 then later try it for K=2. Typically. the reload value for RCAP2H and RCAP2L must be computed. 8 data bits are transmitted in a ten bit frame: one start bit. eight data bits. Thus. For K=1.
the UART can be initialized to fire a receive interrupt only when the ninth bit (or stick bit) is set. Mode 3 of the UART is exactly the same as mode two in terms of the data format and the use of the ninth bit. the SM2 bit is cleared to remove the restriction of having the stick bit set.” You end up dividing 9216000 by 307200 and getting an intermediate result of 30. Therefore.Assume that you again have a system with an oscillator at 9. The stick bit is used to lower the amount of unnecessary interrupts during serial communications across a multidrop serial bus. the baud rates in mode 3 are variable and are controlled in the same manner as in mode 1. the resultant 16 bit answer of the above equation must be both positive and “near integer. When SM2 is set. a ninth (or stick) bit. the SM2 bit is left set and the normal processing continues without constantly being disturbed by a string of interrupts for the incoming byte stream. and you want to generate a baud rate of 9600 baud. If it is. To facilitate this. and one stop bit. eight data bits. the ninth data bit must be set for the UART to fire an interrupt. Otherwise.
.216MHz. Subtracting this from 65536 gives an answer of 65506 or FFE2H. However. This feature is referred to as the multiprocessor communication feature by Intel and is controlled by the SM2 bit in the SCON register. the UART will fire a receive interrupt whenever a valid eleven bit frame rings in. When it is cleared. You should then use a reload value of 255 or FFH for RCAP2H and a reload value of 226 or E2H for RCAP2L. The baud rate for mode two is 1/64th of the oscillator frequency when the SMOD bit is cleared and it is 1/32nd of the oscillator frequency when the SMOD bit is set. and the rest of the message is received. The value of the ninth bit is determined by the TB8 bit of SCON for transmissions and the RB8 bit of SCON for receptions. In such situations an address or command byte is sent first with the stick bit set. very high baud rates (over 345K baud) are achievable using this mode and a relatively common oscillator frequency such as 11. The ninth bit is typically used for inter processor communications.059MHz. All processors on the bus are interrupted and check the incoming byte to see if it is necessary for them to receive the message. For this to be possible.
UART Mode 2
Mode 2 of the UART causes and eleven bit frame to be transmitted: one start bit.
Robots are typically used to do the tasks that are too dirty. Ask a number of people to describe a robot and most of them will answer they look like a human. mining.
. The action may take the form of electro-magnetic motors or actuators (also called effectors) that move an arm. form and function. It is usually a waste of time and not the most sensible thing to model a robot after a human being. A robot may include a feedback-driven connection between sense and action. difficult. is able to move or nailed to the ground. Recently however. or propel the robot.Robotics
Introduction to Robotics In practical usage. a robot needs to be designed with the task in mind. vacuum cleaning. a pre-defined program. Other applications include toxic waste cleanup. small. although it may have a human override function. open and close grips. search and rescue. This usually takes the form of industrial robots used in manufacturing lines. either according to direct human supervision. By this definition. dangerous. It depends on the task at hand whether the robot is big. Interestingly a robot that looks like a human is probably the most difficult robot to make. or a set of general guidelines using artificial intelligence techniques. Each and every task means different qualities. a Robot is a mechanical device which performs automated physical tasks. repetitive or dull for humans. robots are finding their way into the consumer market with uses in entertainment. a robot may include nearly all automated devices. and lawn mowing. and mine finding. not under direct human control. underwater and space exploration. The step by step control and feedback is provided by a computer program run on either an external or embedded computer or a microcontroller. A robot needs to be above all functional and designed with qualities that suit its primary tasks.
These are the type of robots that can quickly and easily search move around. usually they perform task such as search areas. Mobile robots are a great help to such collapsed building for survivors Mobile robots are used for task where people cannot go. Either because it is too dangerous of because people cannot reach the area that needs to be searched. Flat terrains are their territory. Robots have a hard time shifting balance and keep them from tumbling. Development of legged robots is often modeled after insects or crawfish.
Mars Explorer image
Mobile robots can be divided in two categories:
Rolling Robots : Rolling robots have wheels to move around.Mobile Robots Mobile robots are able to move.
. A prime example is the Mars Explorer. Even when they lift one or more legs they still keep their balance.. usually they have 6 legs or more. specifically designed to roam the mars surface. However they are only useful in flat areas. rocky terrains give them a hard time. That’s why most robots with have at least 4 of them. Walking Robots : Robots on legs are usually brought in when the terrain is rocky and difficult to enter with wheels.
Autonomous robots can learn to walk or avoid obstacles they find in their way. Autonomous robots run a program that give them the opportunity to decide on the action to perform depending on their surroundings. Autonomous Robots Autonomous robots are self supporting or in other words self contained. Especially dull and repeating tasks are suitable for robots. They start out with a short routine and adapt this routine to be more successful at the task they perform. A robot never grows tired.
. In a way they rely on their own ‘brains’. it will perform its duty day and night without ever complaining. the robots will be reprogrammed to perform other tasks.. Think about a six legged robot.Stationary Robots Robots are not only used to explore areas or imitate a human being. at first the legs move ad random. In case the tasks at hand are done. The most successful routine will be repeated as such their behavior is shaped. after a little while the robot adjust its program and performs a pattern which enables it to move in a direction. At times these robots even learn new behavior. Most robots perform repeating tasks without ever moving an inch. Most robots are ‘working’ in industry settings.
Assembly language were really interesting and healthy to learn the industrial trends. I am thankful to all the faculty members and R&D in charge for supporting my work and for providing a right track. We learned how to make the people learn.Conclusion An engineer must have a good practical as well as theoretical knowledge.
. Technical lectures presented by the professional technicians related to topics like Robotics. It made us learn about the importance of teamwork. Research and Development center is a true platform to initiate the step towards professionalism in an engineer’s life. The technical training was an educative as well as interactive. The additional activities such as a session on Aptitude questions and presentations related to the topics provided the chance for overall development of an engineer. He must be technically sound as book knowledge is incomplete.
com • Embedded Systems – Muhammad Ali Mazidi
• • •
http://www.com http://www.epanorma.net • http://www.electronicsteacher.wikipedia.