Documente Academic
Documente Profesional
Documente Cultură
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING ANSAL INSTITUTE OF TECHNOLOGY, GURGAON, HARYANA AFFILIATED TO GGSIP UNIVERSITY, NEW DELHI Session- 2012- 2013
ACKNOWLEDGEMENT
A formal statement of acknowledgment is hardly sufficient to express my gratitude towards the personalities who have helped me to undertake and complete this project.
Training in an organization like which is fuelled by the individuals with so much zest and energy, teaming up to form a formidable force, was in itself a true learning experience which is going to help me immensely in my career. I hereby convey my thanks to all those who have rendered their valuable help, support and guidance. Firstly I would thank Director of Appin Technology Lab, Noida for granting me the permission to work as a Trainee in this esteemed company and for providing me all the facilities. I am highly thankful to Mr. Vikas Sharma (Trainer and Guider) for helping me to undertake a project in Embedded Systems at this esteem corporate and providing highly valuable technical acumen, constructive criticism and moral support. Lastly, I bow before the almighty with folded hands.
ABSTRACT
We are living in the Embedded World. We are surrounded with many embedded products and our daily life largely depends on the proper functioning of these gadgets. Television, Radio, CD player, Washing Machine or Microwave Oven in our kitchen, Card readers, Access Controllers, Palm devices of our work space enable us to do many of our tasks very effectively. Apart from all these, many controllers embedded in our car take care of car operations between the bumpers. All kinds of magazines and journals regularly dish out details about latest technologies, new devices; fast applications which make us believe that our basic survival is controlled by these embedded products. Now we can agree to the fact that these embedded products have successfully invaded into our world. What is this Embedded System? Theoretically, an embedded controller is a combination of piece of microprocessor based hardware and the suitable software to undertake a specific task.
I have made a Project based on Microcontroller that is GESTURE CONTROLLED ROBOT. Inspired from Dr. Pranav Mistrys Sixth sense technology, this project makes use of the hand gestures to control the movement of a simple robot. It actually is a small demonstration of the scope of this technology to control the digital devices around us using the natural gestures and help bridge the gap between digital and physical world. Although the miniaturization of computer devices allows us to carry computers in our pockets, keeping us continually connected to the digital world, there is no link between our digital devices and interactions with physical world. There is a need to come over the monotonous digital routines and this project is a small application of such physical world interaction. This training report covers all about the microcontroller and project description.
CONTENTS
1. Overview of Embedded Systems 1.1 Introduction 1.2 Characteristics of Embedded Products 1.3 Common Embedded Systems in todays world 2. 8051 MICROCONTROLLER 2.1 Introduction 2.2 Definition of a Microcontroller 2.3 Difference between Microprocessor and Microcontroller 2.4 8051 Architecture 2.5 Pin Configuration of 8051 2.6 Reset and Oscillator Clock Circuit 2.7 RAM Architecture 2.8 Central Processing Unit 2.9 Bus 2.10 Input-output unit 3. Interfacing components with 8051 3.1 LIQUID CRYSTAL DISPLAY INTERFACING 3.1.1 Pin Configuration 3.1.2 DDRAM - Display Data RAM 3.1.3 BF - Busy Flag 3.1.4 Instruction Register (IR) and Data Register (DR) 3.1.5 Interfacing LCD to 8051 3.1.6 LCD Commands 3.2 7- SEGMENT DISPLAY 3.2.1 Introduction 3.2.2 Creating Digit Pattern 3.2.3 Multi 7 Segment interfacing 3.3 KEYPAD 3.3.1 Introduction 3.3.2 Constructing a Matrix keypad 3.3.3 Scanning a Matrix Keypad 3.3.4 Interfacing Matrix keypad
4. PROJECT DESCRIPTION
4.1 Introduction 4.1.1 Problem Statement 4.1.2 Basic Idea and Principle of The System 4.2 Block Diagram 4.3 Flow Chart 4.4 Components Description 3
4.5 Circuit Diagram 4.6 Working of the Circuit 4.7 C Coding of the project
5. Conclusion 6. References
Input
Output
Microcontrollers often use EEPROM or EPROM as their storage device to allow field programmability so they are flexible to use. Once the program is tested to be correct then large quantities of microcontrollers can be programmed to be used in embedded systems. Easy to Use Assembly language is often used in microcontrollers and since they usually follow RISC architecture, the instruction set is small. The development package of microcontrollers often includes an assembler, a simulator, a programmer to "burn" the chip and a demonstration board. Some packages include a high level language compiler such as a C compiler and more sophisticated libraries.
A Timer module to allow the microcontroller to perform tasks for certain time periods. A serial I/O port to allow data to flow between the microcontroller and other devices such as a PC or another microcontroller. An ADC to allow the microcontroller to accept analogue input data for processing.
Fig 2.2:
A Microprocessor has many support devices like Read only memory, Read-Write memory, Serial interface, Timer, Input/output ports etc. All these support devices are interfaced to microprocessor via a system bus. All support devices in a microprocessor based system are external. The system bus is composed of an address bus, data bus and control bus.
Fig 2.3:
In Microcontroller, all the support devices like Read only memory, Read Write memory, Timer, Serial interface, I/O ports are internal. There is no need of interfacing these support devices and this saves a lot of time for the individual who creates the system .A microcontroller is nothing but a microprocessor system with all support devices integrated inside a single chip. There is no need of any external interfacing in a micro controller unless you desire to create something beyond the limit, like interfacing an external memory or DAC/ADC unit etc. Support devices are external in a microprocessor based system where as support devices are internal for a micro controller. Microcontrollers offer software protection where as microprocessor base system fails to offer a protection system. This is made possible in microcontrollers by locking the on-chip program memory which makes it impossible to read using an external circuit.
The Intel MCS-51 (commonly referred to as 8051) is a Harvard architecture, single chip microcontroller (C) series which was developed by Intel in 1980 for use in embedded systems. It is a high performance single chip computer intended for use in sophisticated real time applications such as instrumentation, industrial control and computer peripherals. It provides extra features like interrupts, bit address ability and an enhanced set of instructions, which makes the chip very powerful and cost effective The 8051 architecture provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer, etc.) in a single package 10
8-bit ALU, Accumulator and 8-bit Registers; hence it is an 8-bit microcontroller 8-bit data bus It can access 8 bits of data in one operation 16-bit address bus It can access 216 memory locations 64 KB (65536 locations) each of RAM and ROM On-chip RAM 128 bytes (data memory) On-chip ROM 4 kByte (program memory) Four byte bi-directional input/output port UART (serial port) Two 16-bit Counter/timers Two-level interrupt priority Power saving mode (on some derivatives)
11
Pin Description
Port 0 (pin 32-39) Dual purpose I/O port. In min. component design, it is used as a general purpose I/O port. In larger designs with external memory, it becomes a multiplexed data bus: Low byte of address bus, strobed by ALE. 8-bit instruction bus, strobed by PSEN. 8-bit data bus, strobed by WR and RD. Port 1 (pin 1-8) As an I/O port: Standard bi-directional port for interfacing to external devices as required for I/O. Port 2 (pin 21-28) Dual purpose I/O port. As an I/O port: Standard bi-directional general purpose I/O port. Alternate functions: High byte of address bus for external program and data memory accesses Port 3 (pin 10-17) It is an 8-bit bi-directional I/O port with internal pull-ups. It also serves the functions of various special features of the 80C51 Table of alternate uses of Port- 3 pins: PINS P3.0 RXD P3.1 TXD P3.2 INT0 P3.3 INT1 P3.4 T0 P3.5 T1 P3.6 WR P3.7 RD ALTERNATE USE Serial data input Serial data output External Interrupt 0 External Interrupt 1 External Timer 0 I/P External Timer 1 I/P External Memory write pulse External Memory read pulse SFR SBUF SBUF TCON.1 TCON.3 TMOD TMOD -
Reset (pin 9): It resets total 8051 micro controller. XTAL1 & XTAL2 (pin 19 and 18): To connect the crystal oscillator. For 8051 oscillator of 11.0592 MHZ is connected between these pins. ALE (pin 30): Address latch enable which is used to access the address locations from external memory. 12
PSEN (pin 31): Program store enable which is used for storing programming code into the external memory. EA (pin 29): External Access: 64 KB of ROM is the limit for external memory. If we are not connecting any external memory to micro controller, EA is connected to VCC in case of 8051. Supply and Ground pins: Pin 40 is for +5V VCC and pin 20 is for GND.
Reset circuit is employed at pin 9. In order for the RESET input to be effective, it must have a minimum duration of two machine cycles.
13
Capacitor is storing charge permanently until we use it. Crystal Oscillator is used to generate a carrier signal with stable frequency. With the help of this oscillator we will deduce the execution speed in terms of bytes/ sec. It generates 12 clock pulses /machine cycle. Capacitors provide charge for crystal oscillator. XTAL1 is at pin 19 and XTAL2 at pin 18. It uses a quartz crystal oscillator. We can observe the frequency on the XTAL2 pin. The crystal frequency is the basic internal frequency of the microcontroller. The internal counters must divide the basic clock rate to yield standard communication bit per second (baud) rates. An 11.0592 megahertz crystal, although seemingly an odd value, yields a crystal frequency of 921.6 kilohertz, which can be divided evenly by the standard communication baud rates of 19200, 9600, 4800, 2400, 1200, and 300 hertz.
14
The 8051 has a bank of 128 bytes of Internal RAM. This Internal RAM is found on-chip on the 8051 so it is the fastest RAM available, and it is also the most flexible in terms of reading, writing, and modifying its contents. Internal RAM is volatile, so when the 8051 is reset this memory is cleared. The 128 bytes of internal ram is subdivided as shown on the memory map. The first 8 bytes (00h - 07h) are "register bank 0". Three alternative register banks are located in internal RAM in addresses 08h through 1Fh. Bit memory actually resides in internal RAM, from addresses 20h through 2Fh. The 80 bytes remaining of Internal RAM, from addresses 30h through 7Fh, may be used by user variables that need to be accessed frequently or at high-speed. This area is also utilized by the microcontroller as a storage area for the operating stack.
Register Banks The 8051 uses 8 "R" registers which are used in many of its instructions. These "R" registers are numbered from 0 through 7 (R0, R1, R2, R3, R4, R5, R6, and R7).These registers are generally used to assist in manipulating values and moving data from one memory location to another. The concept of register banks adds a great level of flexibility to the 8051.
Bit Memory The 8051, being a communication oriented microcontroller, gives user the ability to access a number of bit variables. These variables may be either 1 or 0. There are 128 bit variables available to the user, numbered 00h through 7Fh. The user may make use of these variables with commands such as SETB and CLR. It is important to note that Bit Memory is really a part of Internal RAM. In fact, the 128 bit variables occupy the 16 bytes of Internal RAM from 20h through 2Fh.
Special Function Register (SFR) Memory Special Function Registers (SFRs) are areas of memory that control specific functionality of the 8051 processor. For example, four SFRs permit access to the 8051s 32 input/output lines. Another SFR allows a program to read or write to the 8051s serial port .SFR is a part of Internal Memory. This is not the case. When using this method of memory access (its called direct address), any instruction that has an address of 00h through 7Fh refers to an Internal RAM memory address; any instruction with an address of 80h through FFh refers to an SFR control register.
15
more important, functions are not done. Hence the better option is to use interrupts & the two 16-bit count-up timers. The microcontroller can be programmed for either of the following: 1. Count internal - acting as timer 2. Count external - acting as counter All counter action is controlled by the TMOD (Timer Mode) and the TCON (Timer/Counter Control) registers. TCON Timer control SFR contains timer 1& 2 overflow flags, external interrupt flags, timer control bits, falling edge/low level selector bit etc. TMOD timer mode SFR comprises two four-bit registers (timer-1, timer-0) used to specify the timer/counter mode and operation. The timer may operate in any one of four modes that are determined by modes bits M1 and M0 in the TMOD register: Timer mode-0: Setting timer mode bits to 00b in the TMOD register results in using the TH register as an 8-bit counter and TL as a 5-bit counter. Therefore mode0 is a 13- bit counter. Timer mode-1: Mode-1 is similar to mode-0 except TL is configured as a full 8-bit counter when the mode bits are set to 01b in TMOD. Timer mode-2: Setting the mode bits to 10b in TMOD configures the timer to use only the TL counter as an 8-bit counter. TH is used to hold a value that is loaded into TL every time TL overflows from FFh to 00h. The timer flag is also set when TL overflows. Timer mode-3: In mode-3, timer-1 simply holds its count, where as timer 0 registers TL0 and TH0 are used as two separate 8-bit counters. TL0 uses the Timer-0 control bits. TH0 counts machine cycles and takes over the use of TR1 and TF1 from Timer-1.
Interrupts
A computer has only two ways to determine the conditions that exist in internal and external circuits. One method uses software instructions that jump to subroutines on the states of flags and port pins. The second method responds to hardware signals, called interrupts that force the program to call a subroutine. The Philips 8051 has a total of six interrupt vectors: two external interrupts (INT0 and INT1), three timer interrupts (Timers 0, 1, and 2), and the serial port interrupt. Each of these interrupt sources can be individually enabled or disabled by setting or clearing a bit in Special Function Register IE. IE also contains a global disable bit, EA, which disables all interrupts at once. Each interrupt forces the processor to jump at the interrupt location in the memory. The interrupted program must resume operation at the instruction where the 17
interrupt took place. Program resumption is done by storing the interrupted PC address on to stack. RETI instruction at the end of ISR will restore the PC address. An interrupt is a special feature which allows the 8051 to provide the illusion of "multitasking," although in reality the 8051 is only doing one thing at a time.
Addressing Modes
An "addressing mode" refers to how you are addressing a given memory location. The addressing modes are as follows, With an example of each: Immediate Addressing MOV A, #20h Direct Addressing MOV A, #30h Indirect Addressing MOV A, @R0 External Direct MOVX A, @DPTR Code Indirect MOVC A, @A+DPTR Each of these addressing modes provides important flexibility.
18
Registers are therefore memory locations whose role is to help with performing various mathematical operations or any other operations with data wherever data can be found. Look at the current situation. We have two independent entities (memory and CPU) which are interconnected, and thus any exchange of data is hindered, as well as its functionality. If, for example, we wish to add the contents of two memory locations and return the result again back to memory, we would need a connection between memory and CPU. Simply stated, we must have some "way" through data goes from one block to another.
2.9Bus
That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires. There are two types of buses: address and data bus. The first one consists of as many lines as the amount of memory we wish to address and the other one is as wide as data, in our case 8 bits or the connection line. First one serves to transmit address from CPU memory, and the second to connect all blocks inside the microcontroller.
Fig 2.9: Showing connection between memory and central unit using buses
As far as functionality, the situation has improved, but a new problem has also appeared: we have a unit that's capable of working by itself, but which does not have any contact with the outside world, or with us! In order to remove this deficiency, let's add a block which contains several memory locations whose one end is connected to the data bus, and the other has connection with the output lines on the microcontroller which can be seen as pins on the electronic component.
19
When working with it the port acts like a memory location. Something is simply being written into or read from it, and it could be noticed on the pins of the microcontroller. 8051 has bidirectional I/0 ports. To specify a port as input port set all the 8 bits of that port high. Eg: to make P1 as input port, MOV P1, #11111111b or P1=0x0ff; To specify a port as output port set all the 8 bits of that port as low. Eg: to make P2 as output port, MOV P2, #00000000b or P2=0x00;
20
LCD stands for Liquid Crystal Display. The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDs which have only 1 controller and support at most of 80 characters 8 data pins D7:D0 Bi-directional data/command pins. Alphanumeric characters are sent in ASCII format. RS: Register Select RS = 0 Command Register is selected R/W: Read or Write 0 Write, 1 Read E: Enable (Latch data) Used to latch the data present on the data pins. A high-to-low edge is needed to latch the data. VEE: contrast control. RS = 1 Data Register is selected
(DDRAM) that is not used for display can be used as general data RAM. So whatever you send on the DDRAM is actually displayed on the LCD.
Following are the steps: 1. Move data to LCD port 2. Select command register 3. Select write operation 4. Send enable signal 5. Wait for LCD to process the command
23
7-SEG Display is available in two types Common anode & Common cathode, but common anode display are most suitable for interfacing with 8051 since 8051 port pins can sink current better than sourcing it.
24
Digit 0 1 2 3 4
Seg. h 1 1 1 1 1
Seg. g 1 1 0 0 0
Seg. f 0 1 1 1 0
Seg. e 0 1 0 1 1
Seg. d 0 1 0 0 1
Seg. c 0 0 1 0 0
Seg. b 0 0 0 0 0
Seg. a 0 1 0 0 1
HEX C0 F9 A4 B0 99
25
26
So keeping this outline we can construct a keypad using simple SPST Switches as shown below:
27
28
So ultimately the project transforms the hand gestures into movement of the robot.
30
Transmitter Section:
Hand movements
RF Transmitter
Accelerometer
Comparator IC LM 324
Encoder IC HT 12E
Receiver Section:
RF Receiver
Motors
Decoder IC HT 12D
8051 Microcontroller
31
Convert the hand movement into 4 bit parallel data using Comparator IC
Feed the data into microcontroller and take decision based on input. Drive the motors
Stop
32
In the Transmitter section, following major components are used: 1. Power Supply Circuit 2. Accelerometer 3. LM 324 - Comparator IC 4. HT12E Encoder IC 5. RF Transmitter
33
34
LM 324 Comparator IC
Comparator is a device which compares two input voltages and gives output as high or low.
Properties of comparator: If V+ > V- , then Vo= Vsat (Digital High 1 output) If V+ < V- , then Vo=0 (Digital Low 0 output)
Examples:
35
HT12E Encoder IC
HT 12E is an encoder which encodes the data applied on it It has 8 address and 4 data /address pins
Pin Name A0-A7 GND VCC ~TE AD8- AD11 OSC2 and OSC1 DOUT
Table 4.1: Pin description of HT12E IC
Description Address bits Supply Ground +5V supply for IC Transmission enable, active low The 4 bit input is applied here Connected by an oscillator resistor 1.1 M ohm The encoded output.
RF Transmitter
An RF transmitter receives serial data and transmits it wirelessly through RF through its antenna connected at pin4. The transmission occurs at the rate of 1Kbps - 10Kbps. It operates at a frequency of 434 MHz.
Table 4.2: Pin description of RF transmitter. Fig 4.8: RF transmitter pin diagram 37
In the Receiver section, following major components are used: 1. Power Supply Circuit 2. RF Receiver 3. HT12D Decoder IC 4. 8051 Microcontroller (P89v51RD2) 5. L293D Motor Driver IC
RF Receiver
It receives the data transmitted by the RF transmitter.
Description Supply ground Serial Data Output. Data is received here. +5V supply
38
HT12D Decoder IC
HT12D converts serial data received to parallel data. The input data is decoded when no error or unmatched codes are found. A valid transmission in indicated by a high signal at VT (pin 17).
Pin Name
Description
Address bits Supply Ground +5V supply for IC Data IN. Serial Input pin The 4 bit output data is received here. Connected by an oscillator resistor 51K ohm
17
VT
It is the valid transmission pin. It will high when the transmission is error-free.
39
The pin diagram and other specifications have been discussed earlier in Chapter 2.
40
41
Pin Number Pin Name 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Enable1,2 Input 1 Output 1 GND GND Output2 Input 2
Description Enable pin for Motor 1; active high Input 1 for Motor 1 Output 1 for Motor 1 Ground Ground Output2 for Motor 1 Input 2 for Motor 1
Motor Supply(VCC2) Supply voltage for Motors; 12V Enable 3,4 Input 3 Output 3 GND GND Output 4 Input 4 VCC1 Enable pin for Motor 2; active high Input 3 for Motor 2 Output 3 for Motor 2 Ground Ground Output 4 for Motor 2 Input 4 for Motor 2 Supply voltage; +5V
42
43
2. Receiver Section:
44
4.6 Working of the Circuit The Accelerometer gives analog voltage proportional to the movement related to
the data. This voltage is fed to LM 324IC. The X pin output is fed to pin 3 and 6 and Y output voltage to pin 12 and 9. Reference Voltages are set in such a way that only one comparator output is one during one hand movement. In stable position, outputs of both X and Y pins of ADLX335 are 1.6V. Vref1 = 1.7 V , Vref2=1.5 V , Vref3= 1.7 V , Vref4=1.5 V. The 4 bit data generated is fed to the Encoder IC HT12E at pins 10 to 13, 10 being the MSB. The serial output is obtained at pin 17. This serial data from pin 17 of encoder is fed to DATA pin of the RF transmitter. The data at receiver side is received by RF receiver and fed to pin 14 of HT12D; decoder IC. The parallel data from HT12D is obtained at pins 10 to 13, 13 being the MSB. The parallel data is sent to the controller P89v51RD2. Port 1 of the controller is made the input port. Port 2 is made the output port. The controller takes the input, and makes the decision accordingly, sending data to port2. The port2 output is connected to actuator L293D IC which derives the motor accordingly.
45
while(1) { if(P1==0xf8) P2=0x0a; else if(P1==0xf4) P2=0x05; else if(P1==0xf2) P2=0x02; else if(P1==0xf1) P2=0x08; else P2=0x00; } }
//forward
//backward
//left
//right
//stop
46
5. Conclusion
With the completion of this training, I am now aware of the Microcontroller 8051. I have worked for six complete weeks in the Embedded systems. I have worked almost as an engineer to the extent of my technical capabilities. Doing all these, I have acquired a lot of knowledge about the working of Microcontroller with Embedded C Programming and its Softwares (Keil and Flash Magic). I was the part of one of the most happening and demanding field of electronics i.e. 8051 Microcontroller started by Intel and spending six weeks into it really proved very useful to me and I have gained a lot out of it : 1 2 3 4 5 I got the knowledge of uC 8051 I worked practically on the softwares Keil Uvision, Flash Magic, Topview Simulator. I worked practically which helped me in being more familiar to the interfacing of different display devices which I am supposed to do in the long run. I learned basic concepts of electronics which helped me to understand more. Training helped me increasing my working skills and the knowledge in this field and also showed me the atmosphere that we have to join after completion of the degree program.
Finally, the main advantage of this training was that it has now enabled me to explore myself in the giant Robotic industry. The project overtaken inspires me to research more in this technology and work on similar projects involving the use of gestures. Although the miniaturization of computer devices allows us to carry computers in our pockets, keeping us continually connected to the digital world, there is no link between our digital devices and interactions with physical world. There is a need to come over the monotonous digital routines and this project is a small application of such physical world interaction.
47
REFERENCES
Books: Muhammed Ali Mazidi, Janice Gillispie Mazidi and Rolin D.McKinlay
48