You are on page 1of 51

NIT KURUKSHETRA

Summer Training Report On

Embedded Systems

Submitted By:
Gagan Anand Roll No - 107162 EC-2

(2)

Preface
In this growing age of technology, the extent of correctness is a major point. This correctness and pin pointed guess is achieved only through hard work, experience and well-guided practice. As a new comer to this field we required to have practical knowledge that will help in improving our skills and efficiency. As a matter of fact, summer training is included as a regular course in our curriculum for the 4th semester. So to fulfil this aspect, I did my training in EMTECH FOUNDATION on Embedded Systems for a period of 6 weeks which commenced from 04/06/2009 till 10/07/2009. It included the last one week of our training period on project development on Guide a PC using a TV remote as well. Today is the era of technology and embedded systems are an integral part of it. We are heading for the future that is full of automation and it cannot even be imagined without the use of embedded systems. We all can think of a million of possibilities they can make true, and while having just a glimpse of todays world they truly show their worth. These were the factors that encouraged me to go for this training in embedded systems under EMTECH FOUNDATION. To conclude, those six weeks of training were completely enthralled with the essential learning accompanied with informative sessions and full of knowledge from the guide that will pave the path for advancement of technology and betterment of society.

(3)

Acknowledgement
The project work in this report is an outcome of continuous work over a period and drew intellectual support from various sources. Obligations thus incurred in completing this report. It is therefore almost impossible to express adequately the debts to many persons who have been instrumental in imparting this work a successful status. I would like to express my gratitude to Mr. Naveen Kumar(CEO, EMTECH FOUNDATION) and Ms. Nirmala Pradhan(Program Manager, EMTECH FOUNDATION) for allocating the project and extending full support and cooperation and their invaluable guidance and frequent suggestions during the training period. Their suggestions helped me maintain a good quality of work. I express my deep gratitude to them. Finally, I thank my friends for their constant support and encouragement. Their unobtrusive support and suggestions bolstered my confidence as usual. Their inspiring words will always be a guiding force in all my endeavours to attain greater heights. Gagan Anand

(4)

Contents
Organisations Profile Introduction to Embedded Systems o Characteristics of embedded products o Embedded Processors o Embedded systems v/s general computing systems o Embedded products in todays world Microcontrollers o Internal Structure o Microprocessors v/s Microcontrollers o Brief history of 8051 o Block Diagram of 8051 o Features of 8051 Family o Pin Diagram of 8051 o Registers in 8051 o Stack Pointer o Interrupts Introduction to Project

(5)

o Idea o Block Diagram o Transmission from TV Remote


o

RC-5

o IR Receivers o Processing By MCU o MAX232 o Software Requirements o Circuit Diagram Conclusion

Organisations Profile
EMTECH FOUNDATION is an ISO 9001:2001 certified Embedded Systems/ Microcontroller Training and Consultancy Company, powered by a passion to provide the best of services in the industry. Being In IT business for a couple of years, today Emtech is a leading solution provider for embedded system designs across the globe. It also deals with providing self-developed circuits and kits to the industries in addition to assisting them in the case of any problems related to the embedded systems electronics (hardware and software). With the enthusiastic team of highly skilled engineers, Emtech is headquartered in New Delhi, the capital of India. Emtech is serving to a large number of professionals. We offer solutions to corporate clients, (6)

train budding engineers and recruit skilled professionals. Emtech foundation is leader in Embedded training which impart training to engineering students either pursuing studies or graduated through its various training programs. Emtech has been providing technical training in various areas such as Embedded Systems, Robotics, Industrial Automation and various Microcontrollers like 805l, PIC, ARM, AVR. Emtech also deals with providing self-developed circuits and kits to the industries in addition to assisting them in the case of any problems related to the embedded systems electronics (hardware and software).

Introduction to Embedded Systems


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 pre-defined 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. An embedded system is a combination of hardware and software, design to meet a specific need with required performance in a given time frame. (7)

Characteristics of Embedded Products


1). Embedded systems are designed to do some specific task, rather than be a general-purpose computer for multiple tasks. 2). Embedded systems are not always separate devices. Most often they are physically built-in to the devices they control. 3). The software written for embedded systems is often called firmware, and is stored in read-only memory or Flash memory chips rather than a disk drive. It often runs with limited computer hardware resources: small or no keyboard, screen, and little memory. 4). The majority of computer systems in use today are embedded in other machinery, such as telephones, clocks, appliances, and vehicles. 5). An embedded system may have minimal requirements for memory and program length. Input and output devices may be discrete switches, relays, or solenoids. 6). An embedded controller may lack any human-readable interface devices at all. 7). An embedded system works in time constrained environment

Embedded Processor
Every embedded system has an embedded processor encapsulated in it which controls all the activities of the system. It is a well known fact that PC microprocessors are responsible for less than 1% of the processors sold. Embedded processors outsell PC processors by more than 99%. In general, most of the embedded systems use a (8)

microcontroller as its control/data processing unit. We will discuss more about microcontroller later.

Embedded Systems vs. General Computing Systems:


An embedded system will have very few resources compared to general purpose computing systems like a desktop computer. The memory capacity and processing power in an embedded system is limited. It is more challenging to develop an application in embedded system due to its constricted environment as compare to developing the same for a desktop system. Embedded systems can be implemented using a wide variety of processors.

Embedded Products in todays world


Today is the era of technology and embedded systems are an integral part of it. We are heading for the future that is full of automation and it cannot even be imagined without the use of embedded systems. We all can think of a million of possibilities they can make true, and while having just a glimpse of todays world they truly show their worth. We can cite innumerable fields where these systems are being used currently. Some of them are:

Telecom 1. Mobile Phones 2. Modems 3. Routers

Automobiles 1. Breaking Systems (9)

2. Airbag release systems 3. Engine management unit

Domestic Appliances 1. Televisions 2. Washing machines 3. Calculators 4. Remote Controls 5. Security systems

Robotics 1. Firefighting Robots 2. Robotic Arm

Aerospace Applications 1. Flight control systems 2. Engine controllers

Medical Equipment 1. Pace Makers 2. ECG Monitors

Defence Systems 1. Radar Systems 2. Radio Systems

And Many More

(10)

Microcontrollers
A microcontroller (or MCU) is a computer-on-a-chip. It is a type of microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast to a general-purpose microprocessor (the kind used in a PC). In addition to all arithmetic and logic elements of a general purpose microprocessor, the microcontroller usually also integrates additional elements such as read-only and read-write memory, and input/output interfaces.

Microcontrollers are frequently used in automatically controlled products and devices, such as automobile engine control systems, office machines, appliances, power tools, and toys. By reducing the size, cost, and power consumption compared to a design using a separate microprocessor, memory, and input/output devices, (11)

microcontrollers make it economical to electronically control many more processes. A system designer using a general-purpose microprocessor such as the Pentium or the 68040 must add RAM, ROM, I/O ports, and timers externally to make them functional. Although the addition of external RAM, ROM, and I/O ports make these systems bulkier and much more expensive, they have the advantage of versatility such that the designer can decide on the amount of RAM, ROM and I/O ports needed to fit the task at hand. But in the case of microcontrollers, we have a CPU (microprocessor) in addition to a fixed amount of RAM, ROM, I/O ports and timer on a single chip, which makes them ideal for any applications in which cost and space are critical. Recently, microcontrollers are coming with integrated ADC and other peripherals onto a single chip.

A microcontroller is a single integrated circuit, commonly with the following features:


1. Central Processing Unit - ranging from small and simple 4-bit

processors to complex 32- or 64-bit processors.


2. Central Processing Unit - ranging from small and simple 4-bit

processors to complex 32- or 64-bit processors. 3. Discrete input and output bits allowing control or detection of the logic state of an individual package pin.
4. Serial input/output such as serial ports (UARTs). 5. Peripherals such as timers and counters. 6. Volatile memory (RAM) for data storage. 7. ROM, EPROM [EEPROM] or Flash memory for program and

operating parameter storage.


8. Clock generator - often an oscillator for a quartz timing crystal. 9. Many include analog-to-digital converters (ADC).

This integration drastically reduces the number of chips and the amount of wiring and PCB space that would be needed to produce equivalent systems using separate chips. (12)

Internal Structure of

Microcontrollers

Embedded processors can be broken down into two distinct categories, microprocessors (P) and microcontrollers (C).

(13)

Microcontroller v/s general-purpose Microprocessor


Microprocessor Microcontroller

(14)

CPU is stand alone; RAM, ROM, I/O, timer are separate Designer can decide the amount of RAM, ROM and I/O ports Bulkier but expansive system Versatility General purpose Supports byte-manipulation

CPU, RAM, ROM, I/O and timer are all on a single chip Fixed amount of on-chip RAM, ROM, I/O ports For applications in which cost, power and space are critical Dedicated to specific task Single purpose Supports bit-manipulation also

Criteria for choosing a microcontroller


Meeting the computing needs of the task at hand, efficiently and cost effectively. Speed. Packaging : 40-pin DIP, QFP, etc. Power consumption. The amount of RAM, ROM on chip. The number of I/O pins and the timer on the chip. Cost per unit. Availability of software development tools such as compilers, assemblers and debuggers. Wide availability and reliable sources of the microcontroller.

Brief History of the 8051


In 1981, Intel Corporation introduced an 8-bit microcontroller called the 8051. This microcontroller had 128 bytes of RAM, 4K bytes of on-chip ROM, two timers, one serial port, and four input/output ports (each 8bits wide) all on a single chip. At the time it was also referred to as a system on a chip. The 8051 is an 8-bit processor, meaning that the (15)

CPU can work on only 8 bits of data at a time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU.

The 8051 became widely popular after Intel allowed other manufacturers to make and market any flavor of the 8051 they please with the condition that they remain code compatible with the 8051. This has led to many versions of the 8051 with different speeds and amounts of on-chip ROM marketed by more than half a dozen manufacturers. Although there are different flavors of the 8051, they are all compatible with the original 8051 as far as the instructions are concerned. This means that if we write our program for one, it will run on any one of them regardless of the manufacturer.

Block Diagram of 8051 Microcontroller

TIMER0 INTERRUPT CONTROL ON CHIP ROM FOR PROGRAM CODE ON CHIP RAM TIMER1 TIMER2 (8052 ONLY)

CRYSTAL

OSCILLATOR

BUS CONTROL

4 I/O
PORTS

SERIAL
PORT

(16)

Various 8051 Microcontrollers (Key manufacturers)


Although the 8051 is the most popular member of the 8051 family, we will not see 8051 in the part number. This is because the 8051 is available in different memory types, such as UV-EPROM, flash, and NVRAM, all of which have different part numbers. The UV-EPROM version of the 8051 is the 8751 by Intel. The flash ROM version is marketed by many companies including Atmel Corp. The Atmel Flash 8051 is called AT89C51. The NV-RAM version of the 8051 made by Dallas Semiconductor is called DS5000. There is also OTP (one-time programmable) version of the 8051 made by various manufacturers.

8751 Microcontroller
This 8751 chip has only 4K bytes of on-chip UV-EPROM. To use this chip for development requires access to a PROM burner, as well as a UVEPROM eraser to erase the contents of UV-EPROM inside the 8751 chip, which takes around 20 minutes, before we can program it again.

AT89C51 from Atmel Corporation


This popular 8051 chip has an on-chip ROM in the form of flash memory. This is ideal for fast development since flash memory can be erased in seconds compared to the 20 minutes or more needed for the 8751. For this reason, the AT89C51 is used in place of the 8751 to eliminate the waiting time needed to erase the chip and thereby speed up the development time. To use the AT89C51 to develop a microcontroller-based system requires a ROM burner that supports flash memory; however, a separate ROM eraser is not required; the erasing being done by the PROM burner itself.

DS5000 from Dallas Semiconductor


Another popular version of the 8051 is the DS5000 chip from Dallas Semiconductor. The on-chip ROM for the DS5000 chip from Dallas Semiconductor. The on-chip ROM for the DS5000 is in the form of NVRAM. The read/write capability of NV-RAM allows the program to be loaded into the on-chip ROM while it is in the system. This can be done even via the serial port of a PC, which makes it an ideal home (17)

development system. Another advantage of NV-RAM is the ability to change the ROM contents one byte at a time. It also contains real-time clock (RTC) which generates and keeps the time of day (hr-min-sec) and date (yr-mon-day) even when the power is off.

OTP version of the 8051


There are also OTP (one-time-programmable) versions of the 8051 available from different sources. Flash and NV-RAM versions are typically used for product development. When a product is designed for mass production since it is much cheaper in terms of price per unit.

8051 family from Philips


Another major producer of the 8051 family is Philips Corporation. Indeed, they have one of the largest selections of 8051 microcontrollers. Many of their products include features such as A-toD converters, D-to-A converters, extended I/O, and both OTP and flash.

Features of 8051 family

Feature ROM RAM Timers/counters I/O pins Serial port Interrupt sources Vcc Packaging

Intel 8051 4 KB 128 B 2 32 1 6 5V 40

Atmel AT89C52 8 KB 128 B 3 32 1 8 5V 40

Dallas DS5000 8 KB 128 B 2 32 1 6 5V 40

(18)

Pin Diagram of 8051

Pin Description of 8051


18: Port 1; Each of these pins can be used as either input or output according to your needs. Also, pins 1 and 2 (P1.0 and P1.1) have special functions associated with Timer 2.

(19)

9: Reset Signal; High logical state on this input halts the MCU and clears all the registers. Bringing this pin back to logical state zero starts the program anew as if the power had just been turned on. In another words, positive voltage impulse on this pin resets the MCU. It is utilized in situations when power fails to reach its optimal voltage.

10-17: Port 3; As with Port 1, each of these pins can be used as universal input or output. However, each pin of Port 3 has an alternative function: o Pin 10: RXD - serial input for asynchronous communication or serial output for synchronous communication. o Pin 11: TXD - serial output for asynchronous communication or clock output for synchronous communication o Pin 12: INT0 - input for interrupt 0 o Pin 13: INT1 - input for interrupt 1 o Pin 14: T0 - clock input of counter 0 o Pin 15: T1 - clock input of counter 1 o Pin 16: WR - signal for writing to external (add-on) RAM memory o Pin 17: RD - signal for reading from external RAM memory

18-19: X2 and X1; Input and output of internal oscillator. Quartz crystal controlling the frequency commonly connects to these pins. Capacitances within the oscillator mechanism are normally about 30pF. New MCUs work at frequencies from 0 Hz to 50 MHz+.

20: GND; Ground.

21- 28: Port 2; If external memory is not present, pins of Port 2 act as universal input/output. If external memory is present, this is the location of the higher address byte, i.e. addresses A8 A15.

29: PSEN; MCU activates this bit (brings to low state) upon each reading of byte (instruction) from program memory. If external ROM is used for storing the program, PSEN is directly connected to its control pins.

(20)

30: ALE; Before each reading of the external memory, MCU sends the lower byte of the address register (addresses A0 A7) to port P0 and activates the output ALE. External register memorizes the state of port P0 upon receiving a signal from ALE pin, and uses it as part of the address for memory chip. During the second part of the mechanical MCU cycle, signal on ALE is off, and port P0 is used as Data Bus. In this way, by adding only one cheap integrated circuit, data from port can be multiplexed and the port simultaneously used for transferring both addresses and data. 31: EA; Bringing this pin to the logical state zero designates the ports P2 and P3 for transferring addresses regardless of the presence of the internal memory. This means that even if there is a program loaded in the MCU it will not be executed, but the one from the external ROM will be used instead. Conversely, bringing the pin to the high logical state causes the controller to use both memories, first the internal, and then the external (if present).

32-39: Port 0; Similar to Port 2, pins of Port 0 can be used as universal input/output, if external memory is not used. If external memory is used, P0 behaves as address output (A0 A7) when ALE pin is at high logical level, or as data output (Data Bus) when ALE pin is at low logical level.

40: VCC; Power +5V.

Registers Inside The 8051


Inside the CPU, registers are used to store information temporarily. That information could be a byte of data to be processed or an address pointing to the data to be fetched. In the 8051, there is only one data type : 8 bits. The 8 bits of a register are shown in the diagram from the MSB (most significant bit) D7 to the LSB (least significant bit) D0. With an 8-bit type, any data larger than 8 bits must be broken before it is processed.

D7

D6

D5

D4

D3

D2

D1

D0

(21)

The general purpose registers of the 8051 are A (accumulator), B, R0, R1, R2, R3, R4, R5, R6, R7, DPTR (data pointer), & PC (program counter). All of the above registers are 8-bits, except DPTR and PC, which are 16-bit registers. The accumulator, register A, is used for all arithmetic and logic instructions.

The Accumulator
The Accumulator, as its name suggests, is used as a general register to accumulate the results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most versatile register the 8051 has due to the shear number of instructions that make use of the accumulator. More than half of the 8051s 255 instructions manipulate or use the accumulator in some way. For example, if we want to add the numbers 10 and 20, the result 30 will be stored in the Accumulator. Once we have a value in the Accumulator, we may continue processing the value or we may store it in another register or in memory.

(22)

The R registers
These registers are a set of eight registers that are named R0, R1, etc. up to and including R7. These registers are used as auxiliary registers in many operations. To continue with the above example, let us add 10 and 20. The original number 10 may be stored in the Accumulator whereas the value 20 may be stored in, say, register R4. To process the addition we would execute the command: ADD A, R4 After executing this instruction the Accumulator will contain the value 30. We may think of the "R" registers as very important auxiliary, or "helper", registers. The Accumulator alone would not be very useful if it were not for these "R" registers. The "R" registers are also used to temporarily store values. For example, lets say we want to add the values in R1 and R2 together and then subtract the values of R3 and R4. One way to do this would be: MOV A, R3 accumulator ADD A, R4 accumulator MOV R5, A R5 MOV A, R1 accumulator ADD A, R2 SUB A, R5 R3 + R4) ; Move the value of R3 into the

; Add the value of R4 & store the result in ; Store the resulting value temporarily in ; Move the value of R1 into the

; Add the value of R2 ; Subtract the value of R5 (which now contains

As we can see, R5 was used to temporarily hold the sum of R3 and R4. Though this isnt the most efficient way to calculate (R1+R2) - (R3 +R4) but it does illustrate the use of the "R" registers as a way to store values temporarily.

The B register

(23)

It is very similar to the Accumulator in the sense that it may hold an 8-bit (1-byte) value but is mainly used by two 8051 instructions: MUL AB and DIV AB Thus, if we want to quickly and easily multiply or divide A by another number, we may store the other number in "B" and make use of these two instructions. Aside from the MUL and DIV instructions, the "B" register is often used as yet another temporary storage register much like a ninth "R" register.

The Data Pointer (DPTR)


DPTR is the 8051s only user-accessible 16-bit (2-byte) register, while the Accumulator, "R" registers, and "B" register are all 1-byte values. DPTR, as the name suggests, is used to point to data. It is used by a number of commands which allow the 8051 to access external memory. When the 8051 accesses external memory, it will access external memory at the address indicated by DPTR. While DPTR is most often used to point to data in external memory, many programmers often take advantage of the fact that its the only true 16-bit register available, so it is often used to store 2-byte values which have nothing to do with memory locations.

The Program Counter (PC)


PC is a 2-byte address which tells the 8051 where the next instruction to be executed is found in memory. When the 8051 is initialized, PC always starts at 0000H and is incremented each time an instruction is executed. It is important to note that PC isnt always incremented by one. Since some instructions require 2 or 3 bytes, the PC will be incremented by 2 or 3 in these cases. The Program Counter is special in that there is no way to directly modify its value. That is, we cant do something like PC = 2430H. On the other hand, if we execute AJMP 2430H, weve effectively accomplished the same thing. It is also interesting to note that while we may change the value of PC (by executing a jump instruction, etc.), there is no way to read the value of PC.

(24)

The Stack Pointer (SP)


The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte) value. The Stack Pointer is used to indicate where the next value to be removed from the stack should be taken from. When we push a value onto the stack, the 8051 first increments the value of SP and then stores the value at the resulting memory location. When we pop a value off the stack, the 8051 returns the value from the memory location indicated by SP and then decrements the value of SP. This order of operation is important. When the 8051 is initialized, SP will be initialized to 07h. If we immediately push a value onto the stack, the value will be stored in internal RAM address 08h.Thus, first the 8051 will increment the value of SP (from 07h to 08h) and then will store the pushed value at that memory address (08h). SP is modified directly by the 8051 by six instructions: PUSH, POP, ACALL, LCALL, RET, and RETI. It is also used intrinsically whenever an interrupt is triggered.

PROGRAM STATUS WORD(PSW) REGISTER


This is a special function register that is used to select a memory bank and ever bit holds special significance.
PSW.7 PSW.7PSW.6 PWS.5 PSW.4 PSW.6 PSW.5 CARRY FLAG AUXILLARY CARRY USER DEFINED BIT REGISTER BANK SELECT BIT 1 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0

(25)

PSW.3 PSW.2 PSW.1 PSW.0

REGISTER BANK SELECT BIT 0 OVERFLOW FLAG USER DEFIND BIT PARITY FLAG

CARRY FLAG:-Carry flag is raised when the data in the 8 bit register exceeds 8 bit. AUXILLARY CARRY:-This flag is raised when there is a carry from D3 to D4 bit

PSW.4 AND PSW.3 are used to select the bank and following codes are used. PSW.4 0 0 1 1 PSW.3 0 1 0 1 BANK 0 1 2 3

INTERRUPTS
(26)

A single microcontroller can serve many devices. There are two ways to do that: 1. Interrupt method 2. Polling method In interrupt handler method, when ever device needs its service, the device notifies the microcontroller by sending it an interrupt signal. Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and serves the device. The program associated with interrupt is called the interrupt service routine (ISR) or interrupt handler. In case of Polling, microcontroller continuously monitors the status of given device; when the status condition met, it perform the service. For ever interrupt; there must be an interrupt service routine (ISR) or interrupt handler. When an interrupt is invoked, the microcontroller runs the interrupt service routine. For every interrupt, there is a fixed memory location that holds the address of its ISR. The group of memory locations set asides to hold the address of ISRs is called the interrupt vector table.

Steps in executing an interrupt


Upon activation of an interrupt, the microcontroller goes through the following steps. 1. It finishes the instruction it is executing and saves the address of next instruction (PC) on stack. 2. It also saves the current status of all the interrupts internally (i.e., not in stack). 3. It jumps to a fixed location in the memory called the interrupt vector table that holds the address of the interrupt service routine. 4. The microcontroller gets the address of the ISR from the interrupt vector table and jumps to it. It starts to execute the interrupt service subroutine until it reaches the last instruction of the subroutine, which is RETI (return from interrupt). 5. Upon executing the RETI instruction, the microcontroller returns to the place where it was interrupted. First, it gets the program counter (PC) address from the stack by popping the top two byte of the stack into the PC. Then it starts to execute from that address.

Interrupts in 8051:
There are mainly five interrupt available to user in 8051, but many manufacturers data sheets stated that there are six interrupts since they include reset. (27)

1. Reset: when the reset pin is activated, the 8051 jumps to address location 0000. 2. Two interrupts are set asides for timer: one for timer 0 and other for time 1. 3. Two interrupts are set aside for hardware external interrupts. 4. Serial communication has a single interrupts that belongs to receive and transmit. The various memory addresses for the interrupts are given below.

Interrupt Vector Table:


Interrupt ROM location Pin (Hex) Reset 0000 9 External Hardware 0003 P3.2 interrupt 0 (INT0) (12) Timer 0 interrupt (TF0) 000B External Hardware 0013 P3.3 interrupt 1 (INT1) (13) Timer 1 interrupt (TF1) 001B Serial COM interrupt (RI 0023 and TI) Flag clearing Auto Auto Auto Auto Auto Programmer it

clears

Enabling and disabling an Interrupt


Upon Reset, all interrupts are disabled (masked), meaning that none will be responded to by the microcontroller if the are activated. The interrupts must be enable by software in order for microcontroller to responf to them. There is a register called IE (interrupt enable) that is responsible for enabling (unmasking) and disabling (masking) the interrupts.

Steps in Enabling an interrupt


To enable an interrupt, we take the following steps: 1. Bit D7 of the IE register (EA) must be set to high to allow the rest to take effect. 2. If EA=1, interrupts are enabled and will be responded to if their corresponding bits in IE are high. If EA=0, no interrupt will be responded to, even if the associated bits in the IE register is high. Interrupt Enable register: EA -ET2 ES D7

ET1

EX1

ET0

EX0 D0

(28)

EA

Disables all interrupts. If EA=0, no interrupts is acknowledged. If EA=1, each interrupt source is individually enabled or disabled by setting or clearing its enable bit. -IE.6 Not implemented. ET2 IE.5 Enables or disables Timer 2 overflow or capture interrupt (8052 only). ES IE.4 Enables or disables the serial port interrupt. ET1 IE.3 Enables or disables Timer 1 overflow interrupt. EX1 IE.2 Enables or disables external interrupt 1. ET0 IE.1 Enables or disables Timer 0 overflow interrupt. EX0 IE.0 Enables or disables external interrupt0.

IE.7

Timer Interrupts
Roll-over time flag and interrupt In this type of interrupts if the timer interrupt in the IE register is enabled, whenever the timer rolls over, TF is raised and microcontroller is interrupted in whatever it is doing, and jumps to the interrupt vector table to service the ISR. In this way microcontroller can do other things until it is notified that timer has rolled over which is not possible in case of polling.

HARDWARE INTERRUPTS External interrupts INT0 and INT1 There are only two external hardware interrupts in 8051: INT0 and INT1. They are located on pins P3.2 and P3.3 of port 3, respectively. The interrupt vector table locations 0003H and 0013H are set aside for INT0 and INT1, respectively. As mentioned in section 11.1, they are enabled and disabled using all IE register. There are two types of activation for the external hardware interrupts: 1. Level triggered 2. Edge triggered

In the level triggered mode, INT0 and INT1 pins are normally high and if a low level signal is applied to them, it triggers and interrupt. Then the microcontroller stops whatever it is doing and jumps to the interrupt vector table to service that interrupt. This is called a leveltriggered or level-activated interrupt and is the default mode upon reset of 8051. The low-level signal at the INT pin must be removed (29)

before the execution of the last instruction of the ISR, RETI; otherwise, another interrupt will be generated. In other words, if the low-level signal is not removed before the ISR is finished it is interrupted as another interrupt and the 8051 jumps to the vector table to execute the ISR again.

Level-triggered INT0 0003 1 Edge triggered 0 IT0 (Pin


IE0 (TCON. 1)

3.2)

Level-triggered INT1 0013 1 Edge triggered 0 IT1 (Pin


IE0 (TCON. 3)

3.3)

Fig: Activation of INT0 and int1

(30)

GUIDE A PC USING A TV REMOTE

(31)

INTRODUCTION TO THE PROJECT


Idea
The basic idea of this project is to control any appliance using a simple TV remote to control its functions which can be as simple as switching on or off, or some complicated tasks like controlling it altogether. Here I have used a PC as a typical example. I am going to control some of the functions of a PC with the help of an ordinary TV remote.

Implementation
The Implementation of this project can be thought as a 3 step process. The 3 steps are mentioned below. The data, sent by the remote in the form of IR rays, is received using an IR receiver which in turn is interfaced with a microcontroller. The data is processed in the controller and sent to the serial port of the computer via a line driver IC. A VB or C interface (program) receives the data sent by the controller and accordingly executes the corresponding function.

Project Requirements
An IR remote control

An IR receiver

A Microcontroller A Line Driver IC

(32)

BLOCK

DIAGRAM

The above block diagram specifies the components which I used so as to implement the above mentioned steps.

I used an RC-5 protocol (discussed later) based TV remote .The data, sent by the TV remote in the form of IR waves, having a carrier frequency of 36 kHz. It is received using TSOP 1136 (an IR receiver). The receiver is interfaced with AT89S52 (8051 based microcontroller). Data received is processed in the controller and sent to the serial port of the computer via MAX 232 IC (a line driver IC).

(33)

A VB or C interface (program) receives the data sent by the controller and accordingly executes the corresponding function.

Now as we have discussed the outline of the project, we can divide the projects in various sub-units or atomic processes each of which contributes to the project. In the end, these atomic processes will add up and produce the net result. Now we can discuss each process, related hardware and technology in detail. We shall be discussing these processes in sequence so that in the last we can just integrate them together to build up the whole project. The processes that will attract the attention will be: Transmission from remote Reception by receiver Processing by microcontroller Microcontroller to PC
Software Requirements

These processes are explained first one by one in detail. And then after we have discussed each one of them individually as separate processes, we will merge them together. The individual components and circuitry is displayed as needed under each module, and then finally the final circuit is displayed. Final diagram contains the circuit that is required to operate the complete configuration.

(34)

CIRCUIT DIAGRAM

From the circuit diagram, we can see that the sensor is connected to P3.3 of the microcontroller. Microcontroller on receiving the data sends it serially from its TXD pin to MAX 232 IC. In response, MAX 232 sends the data to receive data pin (RD) of DB9 connector of PC. After receiving the data, PC program processes it and performs the desired function. (35)

TRANSMISSION FROM A TV REMOTE

All TV remotes send data in the form of IR waves. IR is an electromagnetic radiation with a wavelength in the range of 10-4 - 10-6 m. Infra-Red actually is normal light with a particular colour. We humans can't see this colour because its wavelength is below the visible spectrum. That's one of the reasons why IR is chosen for remote control purposes, we want to use it but we're not interested in seeing it. Another reason is because IR LEDs are quite easy to make, and therefore can be very cheap. The data is transmitted according to a standard protocol. Some of the important protocols are Philips RC5, NEC, Nokia NRC 17, and Sony SIRC. Data is sent in the frequency band of 30 to 56 kHz. These protocols are based on some standard data formats. There are three commonly used representations of one bit in remote control systems which are described in the following diagrams. The Bi Phase Coding has one rising or falling edge in the centre of each time slot (figure 1).

In the Pulse Distance Coding, all bursts have the same length but the time between the bursts is different depending on the value of the bit (figure 2).

(36)

In the Pulse Length Code, there are two kinds of burst lengths depending on the bit value (figure 3).

RC-5
The remote that I used in my project was based on Philips RC-5 protocol. The RC-5 protocol was developed by Philips in the late 1980s as a semi-proprietary consumer IR (infrared) remote control communication protocol for consumer electronics. The RC-5 code from Philips is possibly the most used protocol by hobbyists, probably because of the wide availability of cheap remote controls. The protocol is well defined for different device types ensuring compatibility with your whole entertainment system. Lately Philips started using a new protocol called RC-6 which has more features. The protocol uses bi-phase coding (or so-called Manchester coding) at a 36 kHz IR carrier frequency. All bits are of equal length of 1.778ms in this protocol, with half of the bit time filled with a burst of the 36 kHz carrier and the other half being idle. A logical zero is represented by a burst in the first half of the bit time. A logical one is represented by a burst in the second half of the bit time. The pulse/pause ratio of the 36 kHz carrier frequency is 1/3 or 1/4 which reduces power consumption.

(37)

Features:
Uses Bi-phase coding Carrier frequency 36 khz Constant bit time of 1.778 ms 14 bit code There is a 14 bit code assigned to every key corresponding to a device. The description of these bits, as each of them has its special functions, is as follows:

2 start bits First 2 bits are called start bits. These are always logic 1. These represent the initiation of data transfer. 1 toggle bit The 3rd bit is called toggle bit. It inverts every new key press. If a key is pressed, the 14 bit code will be transmitted consecutively but the toggle bit will remain same. It will change only when the key is released and pressed again. 5 address bits These address bits represent the address of the device which is being controlled by this remote. These address bits are described later in detail. 6 command bits These represent the key which is pressed. For a different key, there is a different 6 bit code for it. Command bit list is given later. Manufacturer Philips Pulse /pause ratio of 1/3 or 1/4

The logic 1 and logic 0 in RC-5 can be shown as (38)

Example of RC-5 Transmission

Showing Transmission of command 35H to address 05H

The first two pulses are the start pulses, and are both logical "1". Please note that half a bit time is elapsed before the receiver will notice the real start of the message. Extended RC-5 uses only one start bit. Bit S2 is transformed to command bit 6, providing for a total of 7 command bits. The value of S2 must be inverted to get the 7th command bit though.

(39)

The 3rd bit is a toggle bit. This bit is inverted every time a key is released and pressed again. This way the receiver can distinguish between a key that remains down, or is pressed repeatedly. The next 5 bits represent the IR device address, which is sent with MSB first. The address is followed by a 6 bit command, again sent with MSB first. A message consists of a total of 14 bits, which adds up to a total duration of 25 ms. Sometimes a message may appear to be shorter because the first half of the start bit S1 remains idle. And if the last bit of the message is a logic "0" the last half bit of the message is idle too. As long as a key remains down the message will be repeated every 114ms. The toggle bit will retain the same logical level during all of these repeated messages. It is up to the receiver software to interpret this auto repeat feature.

Philips has created a beautiful list of "standardized" commands. This ensures the compatibility between devices from the same brand. A very nice feature, often to be missed with other brands, is the fact that most devices are available twice in the table allowing you to have 2 VCRs stacked on top of each other without having trouble addressing only one of them with your remote control.
RC-5 Address $00 - 0 $01 - 1 $02 - 2 $03 - 3 $04 - 4 $05 - 5 $06 - 6 $07 - 7 $08 - 8 $09 - 9 $0A - 10 $0B - 11 $0C - 12 CDV Device TV1 TV2 Teletext Video LV1 VCR1 VCR2 Experimental Sat1 Camera Sat2 RC-5 Comma TV Command VCR Command nd $00 - 0 $01 - 1 $02 - 2 $03 - 3 $04 - 4 $05 - 5 $06 - 6 $07 - 7 $08 - 8 $09 - 9 $0A - 10 $0C - 12 0 1 2 3 4 5 6 7 8 9 -/-Standby 0 1 2 3 4 5 6 7 8 9 -/-Standby

(40)

$0D - 13 $0E - 14 $0F - 15 $10 - 16 $11 - 17 $12 - 18 $13 - 19 $14 - 20 $15 - 21 $16 - 22 $17 - 23 $18 - 24 $19 - 25 $1A - 26 $1B - 27 $1C - 28 $1D - 29 $1E - 30 $1F 31

Camcorder

$0D - 13 $10 - 16 $11 - 17

Mute Volume + Volume Brightness + Brightness Program + Program Program + Program Fast Rewind Fast Forward Play Stop Recording

Pre-amp Tuner Recorder1 Pre-amp CD Player Phono SatA Recorder2

$12 - 18 $13 - 19 $20 - 32 $21 - 33 $32 - 50 $34 - 52 $35 - 53 $36 - 54 $37 - 55

CDR

Lighting Lighting Phone

Reception by Receiver

Choosing an IR receiver for a remote control mainly depends upon The protocol in the transmission system.
Working conditions.

Here, I used an IR receiver from VISHAY. Vishay is the worlds leading supplier of infrared (IR) receivers. They have a wide range of IR receivers. The one I used in the project was TSOP 1136. (41)

The main features of TSOP receivers are TTL and CMOS compatibility Low power consumption Small size package Active low output High immunity against ambient light Improved shielding against electrical field disturbance Available for a wide carrier frequency range(30kHz-56kHz)

Block Diagram of TSOP Receiver

The infrared signal generates a current in the photodiode. The AC part of the signal is passed to a transimpedance amplifier, then to an automatic gain control circuit and on to a band pass filter. A comparator, integrator, and Schmitt trigger perform the final signal (42)

conditioning. The output of the receiver is an open collector transistor with an internal pull-up resistor. The AGC circuitry utilizes some inherent differences to distinguish data from noise. But because there are so many different possible noise sources and coding schemes, no single AGC algorithm can completely suppress all noise and pass encoded data signals. To solve this problem, Vishay has developed four different AGC response algorithms based on coding schemes and ambient noise conditions. These AGC algorithms allow developers to choose the most appropriate receiver for their expected operating environment. No single automatic gain control (AGC) algorithm can completely suppress all noise and pass data signals. Vishay has developed four different AGC response algorithms based on coding schemes and ambient noise conditions. These AGC algorithms allow developers to choose the most appropriate receiver. AGC1 for compatibility with any coding scheme and data transmission up to 4kbit/sec in standard environments. AGC2 for typical remote control coding schemes and good noise suppression. AGC3 for operation with fast coding schemes and better noise suppression. AGC4 for best noise suppression including plasma displays and dimmed backlighting for LCD displays. The receiver(TSOP 1136) used by me in the project is based on AGC1 algorithm.

PROCESSING BY MICROCONTROLLER
As the process of transmission was being carried out by the remote, the receiver and microprocessor, interfaced together, were also working simultaneously to receive and store the input data. Here for this part we can assume IR receiver to be working as a phototransistor. So the output of the IR receiver will be complement (inverse) of message/data sent by the remote. I have used AT89S52 in my project which is 8051 architecture based microcontroller. We have discussed complete theory regarding the 8051 microcontroller earlier. The same concepts hold for AT89S52 also. At the time of reception of data, microcontroller is sampling the pin to which the output of IR receiver is connected. At proper instant of time, input data is sampled and saved in the microcontroller memory. I have used the concept of polling to receive the data. The code used in the (43)

microcontroller to program it to receive the input data and send it to PC via line driver MAX-232 is given below.

CODE
INPUT BIT P3.3 TOGGLE BIT 00H TEMP BIT 01H COUNT0 EQU 00H COUNT1 EQU 01H COUNT2 EQU 02H ADDR EQU 08H COMD EQU 09H TEMPREG EQU 10H ; input pin

ORG 00H MAIN: MOV SP, #60H HERE: JB INPUT, HERE ;polling for data

; FIRST DELAY FUNCTION: TIME DELAY=3.027ms MOV COUNT1, #6 FIRST1: MOV COUNT2, #231 SECOND1: DJNZ COUNT2, SECOND1 DJNZ COUNT1, FIRST1

(44)

NOP NOP MOV TOGGLE, INPUT

; INPUT FUNCTION FOR ADDRESS BITS CLR A CLR C MOV COUNT0, #5H TAKEADDRESS: ; SECOND DELAY FUNCTION: TIME DELAY=1.778ms MOV COUNT1, #4 FIRSTADDR: MOV COUNT2, #201 SECONDADDR: DJNZ COUNT2, SECONDADDR DJNZ COUNT1, FIRSTADDR NOP NOP MOV C, INPUT RLC A DJNZ COUNT0, TAKEADDRESS ;saving the address bits

MOV ADDR, A MOV R7, ADDR CJNE R7, #00H, EXIT

(45)

; INPUT FUNCTION FOR COMMAND BITS CLR A CLR C MOV COUNT0, #6H TAKECOMMAND: ; SECOND DELAY FUNCTION: TIME DELAY=1.778ms MOV COUNT1, #4 FIRSTCOMD: MOV COUNT2, #201 SECONDCOMD: DJNZ COUNT2, SECONDCOMD DJNZ COUNT1, FIRSTCOMD NOP NOP NOP MOV C, INPUT RLC A DJNZ COUNT0, TAKECOMMAND ;saving the data bits

MOV COMD, A

; for sending data to PC MOV TMOD, #20H MOV TH1, #0FAH MOV SCON, #50H SETB TR1 (46)

MOV SBUF, COMD ONE: JNB TI, ONE CLR TI

EXIT: LJMP MAIN END

MAX 232
Microcontroller is a TTL or CMOS based device. But the serial port of PC is based on RS-232 standard. According to this standard, the logic 1 is (-3 V to -25 V) and logic 0 is (3 V to 25V). So to make the communication possible between a microcontroller and a PC possible, we need a line driver IC which makes the two different voltage levels logically compatible. I have used MAX 232 from MAXIM Corporation which is designed for this purpose. One advantage of MAX 232 chip is that it uses +5V power source which is the same as source voltage for microcontroller. MAX 232 converts the RS 232s signals to TTL voltage level that will be acceptable to microcontroller. MAX-232 requires four capacitors ranging from 1F to 22F. The most widely used value is 22F. As shown in the following circuit, I have used four capacitors or 10F.

Working Circuit Of MAX-232


(47)

SOFTWARE REQUIREMENTS
After the processed data is sent serially to the computer, I used a VB program on the computer that receives this data from DB9 port. It receives this data in a serial order and stores this information in computer. There is a proper mapping from key to code i.e. corresponding to every key there is a fix code as per the encoding protocol used in remote (In this case RC5). This program is coded so as to perform different actions as per the key code received. The program can be written in many languages e.g. C or VB. What I used was a VB program. This program is responsible for redirecting the serial data from the serial port to proper system commands in the computer after processing it. The processing is done in order to make the microprocessor data compatible to computer. The Following functions can be done with PC Remote control: All Numerical Keys (0 - 9) (48)

Arithmetic Keys (+, -, /, *) Enter, Escape, Help, Refresh, Caps lock, Tab, Back space, delete, Left, Right, Up, down arrows, Page up, Page down, Window keys. Calculator, Notepad CD drive Open/Close Control panel Computer log off, reboot or shutdown Volume Up, down, Mute 5 User defined Programs

Conclusion
After working with this project and having encountered with the problems faced, now Im ready to work with IR/TV remotes in a better way. I am able to interface a TV remote with many simple devices that can be helpful in even betterment of this project and also can unfold many new paths. In this project, a TV remote is used to perform some desired functions that can be governed by the keyboard. This project can simply be extended to use the same TV remote as mouse for the computer. Also this same concept can be used to extend the scope to control many household devices that are generally used. A PC was taken as a typical example because it includes computations that are harder to perform than just simply controlling a device. So if we just interface some of these devices with the remote, these devices can be easily controlled by using this remote.

(49)

When we sit in a room and have 5-6 remotes in our hands; one for controlling Air Conditioner, one for TV, one for electric tube and so on; we just think of something that can get our hands free. Same is possible by extending this idea to control many devices with the same remote, each interfaced with its microcontroller and programmed correspondingly. In short, we can build a universal remote using this idea. These are very close observations that I could just think of while working with this project. If proper attention is spared to the ideas, many new practical uses will rise and many new paths, that are still to be treading, shall unfold.

(50)

Bibliography

8051projects.info vishay.com atmel.com sbprojects.com Embedded Systems by Mazidi and Mazidi

(51)

You might also like