You are on page 1of 46

CHAPTER-1

1.1 SOFTWARE USED


The Keil 8051 Development Tools are designed to solve the complex problems facing embedded software developers. you use from the Device Database and the Vision IDE sets all compiler, assembler, linker When starting a new project, simply select the microcontroller, and memory options for you. Numerous example programs are included to help you get started with the most popular embedded 8051 devices. The Keil Vision Debugger accurately simulates on-chip peripherals (IC, CAN, UART, SPI, Interrupts, I/O Ports, A/D Converter, D/A Converter, and PWM Modules) of your 8051 device. Simulation helps you understand hardware configurations and avoids time wasted on setup problems. Additionally, with simulation, you can write and test applications before target hardware is available.

Fig: 1.1 Keil

1.2 VARIOUS STEPS TO USE THE KEIL COMPILER


Open keil from the start menu.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 1

Select a new project from the project menu. Make a new folder in any drive. Name the project as ABC and then click save. Right click on target, then options for the target, then choose the device, set the crystal frequency, click on the create hex file option to create hex file at the output. Then create a new file from the file menu and save it with the same name of project using extension .c or .asm. Right clicks on the source group, then click on add files option to add the files and then click on close.

1.3 HOW TO DEBUG THE PROGRAM


After writing the code, click on file menu and select save. Click on project menu and rebuild all target files. In build window, it should report as 0 Error(s), 0 Warning(s). Click on debug menu and select start/stop debug session. Click on peripherals, select I/O ports like as port 1. A new window will pop up, which represents the port and pins.

Fig: 1.2 parallel port Now to execute the program stepwise click on F10 key. To exit out click on debug menu and select start/stop debug session.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 2

1.4 STUDY OF VARIOUS MODULES 1.4.1 INTERFACING OF LEDs WITH THE MICROCONTROLLER

The LED is based on the semiconductor diode. When a diode is forward biased (switched on), electrons are able to recombine with holes within the device, releasing energy in the form of photons. This effect is called electroluminescence and the color of the light (corresponding to the energy of the photon) is determined by the energy gap of the semiconductor. LEDs present many advantages over incandescent light sources including lower energy consumption, longer lifetime, improved robustness, smaller size, faster switching, and greater durability and reliability.

1.4.2CIRCUIT DIAGRAM:

Fig: 1.3 Interfacing with LED

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 3

1.4.3 STEPS TO DESIGN THE HARDWARE: 1.4.3.1 COMPONENT REQUIRED


LEDs (8). 470 resistor (1). Switches (3). Connecting wires. Zero PCB.

1.4.3.2 STEPS:
Take 8 LEDs, solder them on PCB and connect their positive terminal to the +5 V supply through 470 resistor. Connect their negative terminal to the 8 pins of microcontroller (say port 1). Write code for different patters of LEDs using KEIL software and burn the HEX file of these codes in microcontroller.

1.4.4 PROGRAM: To shift the 8 LEDs one by one on right hand side.
#include<reg51.h> #include<intrins.h> void ms_delay(unsigned char a) {unsigned char i,j; for(i=0;i<a;i++) {for(j=0;j<223;j++) {_nop_( );} }} void s_delay(unsigned char a) {unsigned char i; unsigned int j; for(i=0;i<a;i++)

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 4

{for(j=0;j<1000;j++) {ms_delay(1); }}} void main( ) { int i,j; while(1) {P1=0xff; j=P1; for(i=0;i<=7;i++) {j=j>>1; if(i>0) {j=(0x80) | j; } s_delay(1); P1=j; } } }

1.5 INTERFACING OF SWITCHES WITH MICROCONTROLLER


Take 2 pin three switches and connect their one pin to the GND. Now connect the other pin of switches to three pins of microcontroller (say P3.0, P3.1, P3.2). Now burn the code for the three patterns of LEDs using switches.

1.5.1 PROGRAM: Write a code that performs following operations.


P3.0 = right shift operation. P3.1 = left shift operation. P3.2 = even/odd LEDs

#include<reg51.h> #include<intrins.h> void ms_delay(unsigned char a) { unsigned char i,j; for(i=0;i<a;i++) {for(j=0;j<223;j++)

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 5

{_nop_( );} } } void s_delay(unsigned char a) {unsigned char i; unsigned int j; for(i=0;i<a;i++) {for(j=0;j<1000;j++) { ms_delay(1);} } } void main( ) { int i,j; if(P30==0) {while(1) {P1=0xff; j=P1; for(i=0;i<=7;i++) {j=j>>1; if(i>0) {j=(0x80) | j;} s_delay(1); P1=j;} }} else if(P31==0) {int i,j; while(1) {P1=0xff; j=P1; for(i=0;i<=7;i++) {j=j<<1; if(i>0) {j=(0x01)| j; } s_delay(1);

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 6

P1=j;} } } else if(P32==0) {while(1) {P1=0x55; s_delay(1); P1=0xAA; s_delay(1); } } }

1.6 INTERFACING OF SEVEN SEGMENT DISPLAY WITH THE MICROCONTROLLER

Fig: 1.4 Seven Segment Display Single seven segment display. Double seven segment display.

A seven-segment display (abbreviation: "7-segment) display"), less commonly known as a sevensegment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot-matrix displays. Seven-segment displays are widely used in digital clocks, electronic meters, and other electronic devices for displaying numerical information.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 7

In addition to the ten numerals, seven segment displays can be used to show letters of the Latin, Cyrillic and Greek alphabets including punctuation, but only few representations are unambiguous and intuitive at the same time: uppercase A, B, C, E, F, G, H, I, J, L, O, P, S, U, Y, Z, and lowercase a, b, c, d, g, h, i, n, o, q, r, t, u.

1.6.1 TYPES OF SEVEN SEGMENT:


Common anode. Common cathode.

Seven segment displays can be divided into 2 types of connection. One is called common anode of which all the anodes of the LEDs are connected together, leaving the cathodes open for connection. The other one is called common cathode of which all the cathodes of the LEDs are connected together, leaving the anodes open for connection.

Fig: 1.5 internal structures of seven segments

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 8

1.6.2 SINGLE SEVEN SEGMENT:

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 9

1.6.2.1 CIRCUIT

fig: 1.6 interfacing with seven segment

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 10

1.6.2.2 STEPS TO DESIGN THE HARDWARE: 1.6.2.2.1 COMPONENT REQUIRED:


Seven segment display (2). 1 K resistor (2). BC 557 transistor (2). Switches (3). Connecting wires. Zero PCB. 20 pin IC Base.

1.6.2.2.2 STEPS:
Solder IC base on the zero PCB and then insert seven segment displays in it. Now connect the seven segment display to the controller port 2 by taking (a) as LSB segment and (h) as MSB segment. Connect the pins according to the figure shown above.

TABLE: 1.1 HEXADECIMAL CODES


Digit 0 1 h 1 1 G 1 1 f 0 1 e 0 1 d 0 1 C 0 0 b 0 0 a 0 1 Hex code 0xC0 0xF9

1.6.2.3 PROGRAM: To display 0 to 9 digits on seven segment display.


#include<reg51.h> #include<intrins.h> void ms_delay(unsigned char a) { unsigned char i,j; for(i=0;i<a;i++) {for(j=0;j<223;j++)

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 11

{_nop_( );} } } void s_delay(unsigned char a) {unsigned char i; unsigned int j; for(i=0;i<a;i++) {for(j=0;j<1000;j++) {ms_delay(1);} } } void main( ) { int a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98}, int i; while(1) { P1=0xff; for(i=0;i<=9;i++) {s_delay(1); P1=a[i]; } } }

1.7 INTERFACING OF DC MOTOR WITH MICROCONTROLLER


This section begins with an overview of the basic operation of DC motors. Then we describe how to interface a DC motor to the 8051. Finally, we use C language programs to demonstrate the concept of pulse width modulation (PWM) and show how to control the speed and direction of a DC motor. DC MOTOR: A direct current (DC) motor is another widely used device that translates electrical pulses into mechanical movement. In the DC motor we have only + and - leads. Connecting them to a DC voltage source moves the motor in one direction. By reversing the polarity, the DC motor will move in the opposite direction. One can easily experiment with the DC motor. For example, small fans used in many motherboards to cool the CPU are run by DC motors. By connecting their leads to the + and - voltage source, the DC motor moves. While a stepper motor moves in steps of 1 to 15 degrees, the DC motor moves continuously. In a stepper motor, if we know the starting position we can easily count the number of steps the motor has moved and calculate the final position of the motor. This is not possible in a DC motor. The maximum speed of a DC motor is indicated in rpm and is given in the data sheet. The DC motor has two rpms: no-load and loaded. The manufacturer's data sheet gives the noload rpm. The no-load rpm can be from a few thousand to tens of thousands. The rpm is reduced when moving a load and it decreases as the load is increased. For example, a drill turning a screw has a much lower rpm speed than when it is in the no-load situation. DC motors also have voltage and current

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 12

ratings. The nominal voltage is the voltage for that motor under normal conditions, and can be from 1 to 150V, depending on the motor. As we increase the voltage, the rpm goes up. The current rating is the current consumption when the nominal voltage is applied with no load, and can be from 25mA to a few amps. As the load increases, the rpm is decreased, unless the current or voltage provided to the motor is increased, which in turn increases the torque. With a fixed voltage, as the load increases, the current (power) consumption of a DC motor is increased. If we overload the motor it will stall, and that can damage the motor due to the heat generated by high current consumption.

1.7.1 UNIDIRECTIONAL CONTROL:


Figure shows the DC motor rotation for clockwise (CW) and counterclockwise (CCW) rotations.

Fig.1.7 DC MOTER

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 13

1.7.2 CIRCUIT DIAGRAM:

Fig: 1.8 interfacing with DC motor

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 14

1.7.3 STEPS TO DESIGN THE HARDWARE: 1.7.3.1 COMPONENT REQUIRED:

Fig: 1.9 Optocoupler 4n35 Optocoupler (6). 470 resistor (6). 1 K resistor (6). BC 369 transistors (6). IN4007 diodes (6). 12 V relay (1). 6 pin IC Base (6). Connecting wires. 12 V DC motor (1). Zero PCB (3). Switches (2).

How to drive the motor unidirectional? HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 15

1.7.3.2STEPS
Solder IC Base on the Zero PCB. Then connect first pin of 4n35 to +5V supply through 470 resistor. Connect second pin to controller P0.2. Connect base pin of BC369 to pin 5 through a 1K resistor. Connect 4 pin and collector of transistor to ground. Connect a diode and 12V supply to emitter as shown in the circuit diagram. s

1.7.4 PROGRAM: Write a code that performs following operations.


P3.0 = switch ON the motor. P3.1 = switch OFF the motor.

#include<reg51.h> #include<intrins.h> void main( ) { if((P30==1)&&(P31==1)) {goto label2;} label1: if(P30==0) {while(1) {P02=0; if((P31==0)&&(P30==1)) {goto label2;} } } label2: {while(1) {P02=1; if((P30==0)&&(P31==1)) {goto label1;} } } }

1.8STEPPER MOTOR
Stepper motor based on speed, distance, load, inertia or a Motion Control, in electronic terms, means to accurately control the movement of an object combination of all these factors. There are numerous types of motion control systems, including; Stepper Motor, Linear Step Motor, DC Brush, Brushless, Servo, Brushless Servo and more.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 16

A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. Stepper motor is a form of ac. motor .The shaft or spindle of a stepper motor rotates in discrete step increments when electrical command pulses are applied to it in the proper sequence. The motors rotation has several direct relationships to these applied input pulses. The sequence of the applied pulses is directly related to the direction of motor shafts rotation. The speed of the motor shafts rotation is directly related to the frequency of the input pulses and the length of rotation is directly related to the number of input pulses applied [39]. For every input pulse, the motor shaft turns through a specified number of degrees, called a step. Its working principle is one step rotation for one input pulse. The range of step size may vary from 0.72 degree to 90 degree. In position control application, if the number of input pulses sent to the motor is known, the actual position of the driven job can be obtained. A stepper motor differs from a conventional motor (CM) as under: 1. Input to SM is in the form of electric pulses whereas input to a CM is invariably from a constant voltage source. 2. A CM has a free running shaft whereas shaft of SM moves through angular steps. 3. In control system applications, no feedback loop is required when SM is used but a feedback loop is required when CM is used. 4. A SM is a digital electromechanical device whereas a CM is an analog electromechanical device.

1.8.1 OPEN LOOP OPERATION


One of the most significant advantages of a stepper motor is its ability to be accurately controlled in an open loop system. Open loop control means no feedback information about position is needed. This type of control eliminates the need for expensive sensing and feedback devices such as optical encoders. Control position is known simply by keeping track of the input step pulses. Every stepper motor has a permanent magnet rotor (shaft) surrounded by a stator. The most common stepper motor has four stator windings that are paired with a center-tapped common. This type of stepper motor is commonly referred to as a four- phase stepper motor. The center tap allows a change

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 17

of current direction in each of two coils when a winding is grounded, thereby resulting in a polarity change of the stator. Notice that while a Conventional motor shaft runs freely, the stepper motor shaft moves in a fixed repeatable increment which allows one to move it to a precise position.

Fig: 1.10 Rotor Alignment This repeatable fixed movement is possible as a result of basic magnetic theory where poles of the same polarity repel and opposite poles attract. The direction of the rotation is dictated by the stator poles. The stator poles are determined by the current sent through the wire coils. As the direction of the current is changed, the polarity is also changed causing the reverse motion of the rotor. The stepper motor used here has a total of 5 leads: 4 leads representing the four stator windings and 1 common for the center tapped leads. As the sequence of power is applied to each stator winding, the rotor will rotate. There are several widely used sequences where each has a different degree of precision. Table shows the normal 4-step sequence. For clockwise go for step 1 to 4 & for counter clockwise go for step 4 to 1.

W i n d i n g W i n d i n g

A1 2 3 B

W i n d i n g

6 W Ci n d i n g

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 18

TABLE: 1.2 STATOR WINDINGS CONFIGURATION Step 1 2 3 4 Winding A 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 Winding B Winding C Winding D

1.8.2 INPUT SEQUENCE TO THE WINDINGS


Since the stepper motor is not an ordinary motor and has four separate coils which have to be energized one by one in a stepwise fashion. We term them as coil A, B, C and D. At a particular instant the coil a should get supply and then after some delay the coil B should get a supply and then coil C and then coil D and so on the cycle continues. The more the delay is introduced between the energisation of the coils the lesser is the speed of the stepper motor and vice versa. For such a complex requirement of alternate supplies to the coil of stepper motor we need a special unit which will perform this operation. Here we are using a PC to perform this function. How we perform it is explained below: At the printer port we have 25 pins and out of these 25 pins pin number 2 to 9 are the output pins which can be used to control any hardware circuit .The pin number 10,12,13 and 15 are input pins which can be used get any input signal from an external hardware. The pin numbers 18to 25 are the ground pins. Since the stepper motor has five wires; four out of them corresponding to four coils and one is ground reference, we will be using four output pins (2, 3, 4, and 5) of the printer port and any pin out of 18 to 25 for the stepper motor.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 19

What we have done is that we connected each of the output pin of the printer port to the pin number 1 of a different I.C. (817) known as the optocoupler. It is a four pin I.C. .Its pin number 2 is connected to the ground reference form the printer port. Internally at pin number 1 of the optocoupler the p- portion of an LED is connected and its n- side is connected to the pin number 2. Now when we want to provide supply to the coil A of the stepper motor, we activate the pin number 2 of the printer port. This will make the LED inside the Optocoupler (connected to pin number 2) to glow and its light falls on the base of a phototransistor which is also mounted inside the optocoupler with its emitter at pin number 3 and the collector at its pin number 4. The falling of light ensures that the base of the phototransistor starts conducting and the emitter and the collector are virtually short circuited. We have connected +9 V supply to the emitter of the phototransistor which is now being forwarded to the collector. But the output current of the phototransistor is very low to energize the coil of the stepper motor. So we feed the output of the stepper motor to a current amplifying transistor (369) at its base and its emitter is connected to positive supply. Now the current output will be sufficient to energies the coil. This output is now fed to the coil A of the stepper motor. Now after a certain delay we activate the pin number 3 of the printer port. This will make the LED inside the optocoupler, to which pin number 3 is connected, to glow and accordingly the amplified output will fed to coil B for its energisation .This process continues for all the four coils and after that we can say that the motor has taken a step. If we continue this cycle the motor keeps on rotating. As we know that the stepper motor comprises of four coils A, B, C, and D. These coils must be given the supply in the form of steps i.e. firstly coil a should get the supply, then after a delay coil B gets a supply , then coil C and then coil D. The more delay you introduce between the passing on of supply from one coil to another the speed of the motor will be that much slow. Now at the printer port of the computer we have 25 pins and out of them pin number 2 to 9 are output pins which can supply an input to an external hardware, which in yours case is a stepper motor. As we need to pass on stepwise input only to four coils we will be using just pin numbers 2, 3, 4 and 5 of the printer port. The method of using the output pins of the printer port is as follows: If you write a statement:

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 20

Outportb (0x378, 1); When this statement will be executed it will send the binary equivalent of the value written after the comma (i.e. 1) in the form of a byte i.e. 00000001 at the output pins of the printer port. The parameter 0X378 is the address of the output pins of the printer port and the value in send to these pins starting from pin number 2 .i.e. when this statement will be executed pin number 1 will output a high signal and rest all output pins will provide a low signal. Similarly if your statement is: Outportb (0X378, 4); The execution of this statement will send its binary equivalent i.e., 00000100 at the output pins. It means that pin number 4 will be getting a signal and will output this to the external circuit and rest all pins will be low. Thus we connected coils A,B,C,D to the pins 2,3,4,5 and pass supply to them in a stepwise fashion i.e. we execute the following set if statements: Outportb (0x378, 1); Delay (100); Outportb (0x378, 2); Delay (100); Outportb (0x378, 4); Delay (100); Outportb (0x378, 8); Delay (100); This cycle keeps on continuing. But these output pins are not connected directly to the stepper motor. We always need to isolate any hardware operating from the Computer. So we connect these each of the output pins to an optocoupler IC. Its pin number 1 is connected to the output pins from the PC and pin number 2 is connected to the ground reference form the PC i.e. any of the pin numbers 18 to 25.When the Pc activates any output pin the pin number 1 of that particular optocoupler get a +5 V supply. Inside the IC at pin number we have the p- side of an LED and its n-side is connected at pin number 2. Its pin 3 and 6 are not connected. Across its pin numbers 4 & 5 a phototransistor is mounted internally whose base is photosensitive.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 21

Now when the output pin of the printer port becomes high, the corresponding LED glows and the phototransistors base gets activated because the light is made to fall on its base. The emitter of the phototransistor is at pin number 4 of the IC which is connected to negative supply. The activation of the base passes on the ve supply from the emitter to the collector which is at the pin number 5 .So now we get a low signal . This signal is then inverted using hex inverter 4049.But its output is not sufficient to drive the stepper motor .Hence we need to use a Darlington pair assembly of two transistors(BC 547) in which the emitter of first drives the base of the second transistor. Their output is now provided to the stepper motor. Accordingly 4 Darlington pairs are required for 4 coils which will operate in a stepwise manner to pass supply to the coils of stepper motor in a stepwise manner.

1.8.3 LIQUID CRYSTAL DISPLAY


Liquid crystal displays (LCD) are widely used in recent years as compares to LEDs. This is due to the declining prices of LCD, the ability to display numbers, characters and graphics, incorporation of a refreshing controller into the LCD, their by relieving the CPU of the task of refreshing the LCD and also the ease of programming for characters and graphics. HD 44780 based LCDs are most commonly used. The LCD discuss in this section has the most common connector used for the Hitachi 44780 based LCD is 14 pins in a row and modes of operation and how to program and interface with microcontroller is describes in this section.

1 1 1 1 1 1 1

9 8 7 6 5 4 3 2 1

6 5 4 3 2 1 0

1 1 1 1 1 1 1 9 8 7 6 5 4 3 2 1

6 5 4 3 2 1 0

G V D D D D D D D D E R R C V G

n d c c 7 6 5 4 3 2 1 0 / S o c n W n t r a s t c d
2

Fig: 1.11 LCD Pin Description Diagram

VCC, VSS, VEE

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 22

The voltage VCC and VSS provided by +5V and ground respectively while VEE is used for controlling LCD contrast. Variable voltage between Ground and Vcc is used to specify the contrast (or "darkness") of the characters on the LCD screen. RS (register select) There are two important registers inside the LCD. The RS pin is used for their selection as follows. If RS=0, the instruction command code register is selected, then allowing to user to send a command such as clear display, cursor at home etc.. If RS=1, the data register is selected, allowing the user to send data to be displayed on the LCD. R/W (read/write) The R/W (read/write) input allowing the user to write information from it. R/W=1, when it read and R/W=0, when it writing. EN (enable) The enable pin is used by the LCD to latch information presented to its data pins. When data is supplied to data pins, a high power, a high-to-low pulse must be applied to this pin in order to for the LCD to latch in the data presented at the data pins. D0-D7 (data lines) The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of the LCDs internal registers. To displays the letters and numbers, we send ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS =1. There are also command codes that can be sent to clear the display or force the cursor to the home position or blink the cursor. We also use RS =0 to check the busy flag bit to see if the LCD is ready to receive the information. The busy flag is D7 and can be read when R/W =1 and RS =0, as follows: if R/W =1 and RS =0, when D7 =1(busy flag =1), the LCD is busy taking care of internal operations and will not accept any information. When D7 =0, the LCD is ready to receive new information.

1.9 LCD INTERFACING WITH 8051 MICROCONTROLLER


Frequently, an 8051 program must interact with the outside world using input and output devices that communicate directly with a human being. One of the most common devices attached to an 8051 is an LCD display. Some of the most common LCDs connected to the 8051 are 16x2 and 20x2 displays. This means 16 characters per line by 2 lines and 20 characters per line by 2 lines, respectively. Fortunately, a very popular standard exists which allows us to communicate with the vast majority of LCDs regardless of their manufacturer. The standard is referred to as HD44780U, which refers to the

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 23

controller chip which receives data from an external source (in this case, the 8051) and communicates directly with the LCD. The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. If a 4-bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for the data bus). If an 8-bit data bus is used the LCD will require a total of 11 data lines (3 control lines plus the 8 lines for the data bus). The three control lines are referred to as EN, RS, and RW. The EN line is called "Enable." This control line is used to tell the LCD that you are sending it data. To send data to the LCD, your program should make sure this line is low (0) and then set the other two control lines and/or put data on the data bus. When the other lines are completely ready, bring EN high (1) and wait for the minimum amount of time required by the LCD datasheet (this varies from LCD to LCD), and end by bringing it low (0) again. The RS line is the "Register Select" line. When RS is low (0), the data is to betreated as a command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1), the data being sent is text data which should be displayed on the screen. For example, to display the letter "T" on the screen you would set RS high. The RW line is the "Read/Write" control line. When RW is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or reading) the LCD. Only one instruction ("Get LCD status") is a read command. All others are write commands--so RW will almost always be low. Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation selected by the user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2, DB3, DB4, DB5, DB6, and DB7. As we've mentioned, the LCD requires either 8 or 11 I/O lines to communicate with. For the sake of this tutorial, we are going to use an 8-bit data bus--so we'll be using 11 of the 8051's I/O pins to interface with the LCD. Let's draw a sample pseudo-schematic of how the LCD will be connected to the 8051.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 24

Fig: 1.12 interfacing with LCD As you can see, we've established a 1-to-1 relation between a pin on the 8051 and a line on the 44780 LCD. Thus as we write our assembly program to access the LCD, we are going to equate constants to the 8051 ports so that we can refer to the lines by their 44780 name as opposed to P0.1, P0.2, etc. Let's go ahead and write our initial equates: DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 EN RS RW EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 P3.7 P3.6 P3.5

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 25

TABLE: 1.3 LCD PIN DESCRIPTION

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

Symbol VSS VCC VEE RS R/W E PB0 PB1 DB2 DB3 DB4 DB5 DB6 DB7

I/O I I I/O I/O I/O I/O I/O I/O I/O I/O I/O

Description Ground +5V power supply Power supply to control contrast RS=0 to select command register, RS=1 to select data register. R/W=0 for write, R/W=1 for read Enable The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 26

1.9.1 PROGRAMME
#include<reg51.h> #include<intrins.h> #define data P1 #define RS P33 #define RW P34 #define E P35 void ms_delay(unsigned char a) { unsigned char i,j; for(i=0;i<a;i++) { for(j=0;j<224;j++) { _nop_(); } } } void cmd() { data=ACC; RS=0; RW=0; E=1; ms_delay(10); E=0; }

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 27

void display() { data=ACC; RS=1; RW=0; E=1; ms_delay(10); E=0; } void lcd_init() { ACC=0x38; cmd(); ACC=0x80; cmd(); ACC=0x06; cmd(); ACC=0x0c; cmd(); ACC=0x01; cmd(); } void main() { lcd_init(); ACC='c'; display(); ACC='h'; display(); ACC='a'; display(); ACC='l'; display();

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 28

ACC='_'; display(); ACC='g'; display(); ACC='y'; display(); ACC='a'; display(); }

1.10 8051 REGISTOR


8051 Microcontrollers have 2 types of registers. They are: General Purpose Registers. Special Purpose Registers.

1.10.1 GENERAL PURPOSE REGISTERS: 1.10.1.1 REGISTERS (R0 R7):


It is the set 8 auxiliary registers namely R0, R1...R7. There are 4 such banks in lower RAM. This is a common name for the total 8 general purpose registers (R0, R1, R2 ...R7). Even they are not true SFRs;

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 29

they deserve to be discussed here because of their purpose. The bank is active when the R registers it includes are in use. Similar to the accumulator, they are used for temporary storing variables and intermediate results. Which of the banks will be active depends on two bits included in the PSW Register. These registers are stored in four banks in the scope of RAM. The following example best illustrates the useful purpose of these registers. Suppose that mathematical operations on numbers previously stored in the R registers should be performed: (R1+R2) - (R3+R4). Obviously, a register for temporary storing results of addition is needed. Everything is quite simple and the program is as follows: MOV A,R3; Means: move number from R3 into accumulator ADD A,R4; Means: add number from R4 to accumulator (result remains in accumulator) MOV R5,A; Means: temporarily move the result from accumulator into R5 MOV A,R1; Means: move number from R1 into accumulator ADD A,R2; Means: add number from R2 to accumulator SUBB A,R5; Means: subtract number from R5 ( there are R3+R4 )

Fig.1.13. Register R0-R7

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 30

1.10.1.2 DATA POINTER (DPTR):


It is made of 16-bit register further composed of two 8 bit registers, namely DPH and DPL used to furnish memory addresses for internal and external code access and external data access. DPTR

DPH

DPL

These registers are not true ones because they do not physically exist. They consist of two separate registers: DPH (Data Pointer High) and (Data Pointer Low). Their 16 bits are used for external memory addressing. They may be handled as a 16-bit register or as two independent 8-bit registers. Besides, the DPTR Register is usually used for storing data and intermediate results which have nothing to do with memory locations.

Fig: 1.14 Data Pointers

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 31

1.10.1.3 PROGRAM COUNTER (PC):


It is a 16 bit register and it hold the address of the next program instruction to be executed and automatically gets incremented after each instruction is fetched.

1.10.1.4 STACK POINTER (SP):


It is an 8 bit register and is used to hold an internal RAM address called the Top of the Stack. As the data is pushed in the stack, firstly the pointer is incremented and then data is pushed and when the data is to be popped off then firstly the data is popped off and then stack pointer gets decremented

Fig: 1.15 Stack Pointers A value of the Stack Pointer ensures that the Stack Pointer will point to valid RAM and permits Stack availability. By starting each subprogram, the value in the Stack Pointer is incremented by 1. In the same manner, by ending subprogram, this value is decremented by 1. After any reset, the value 7 is written to the Stack Pointer, which means that the space of RAM reserved for the Stack starts from this location. If another value is written to this register then the entire Stack is moved to a new location in the memory.

1.10.2 SPECIAL PURPOSE REGISTERS:


SFRs are a kind of control table used for running and monitoring microcontrollers operating. Each of these registers, even each bit they include, has its name, address in the scope of RAM and clearly defined purpose ( for example: timer control, interrupt, serial connection etc.). Even though there are 128 free memory locations intended for their storage, the basic core, shared by all types of 8051 controllers, has only 21 such registers. Rests of locations are intentionally left free in order to enable the producers to further improved models keeping at the same time compatibility with the previous versions. It also enables the use of programs written a long time ago for the microcontrollers which are out of production now.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 32

1.10.2.1 CPU REGISTERS:


ACCUMULATOR: - It is an 8 bit register and used as working register for the Arithmetic, Logical instructions. All the calculations are performed using this register. It can also be used as General purpose register. It is very necessary for some instructions. It is denoted by A. A number (an operand) should be added to the accumulator prior to execute an instruction upon it. Once an arithmetical operation is performed by the ALU, the result is placed into the accumulator. If a data should be transferred from one register to another, it must go through accumulator. For such universal purpose, this is the most commonly used register that none microcontroller can be imagined without (more than a half 8051 microcontroller's instructions used use the accumulator in some way).

B REGISTER: - It also an 8 bit register and can be used as General Purpose register. It is very necessary for the multiplication and division operations which can be performed only upon numbers stored in the A and B registers, without it the operations are not accomplished. All other instructions in the program can use this register as a spare accumulator (A).

1.10.2.2 PSW: PROGRAM STATUS WORD (bit Addressable):

Fig: 1.16 Program Status Word. This is one of the most important SFRs. The Program Status Word (PSW) contains several status bits that reflect the current state of the CPU. This register contains: Carry bit, Auxiliary Carry, two register bank select bits, Overflow flag, parity bit, and user-definable status flag. The ALU automatically changes some of registers bits, which is usually used in regulation of the program performing. P - Parity bit: If a number in accumulator is even then this bit will be automatically set (1), otherwise it will be cleared (0). It is mainly used during data transmission and receiving via serial communication. Bit 1:

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 33

This bit is intended for the future versions of the microcontrollers, so it is not supposed to be here. OV Overflow: Sets when the result of arithmetical operation is greater than 255 (decimal), so that it cannot be stored in one register. In that case, this bit will be set (1). If there is no overflow, this bit will be cleared (0). RS0, RS1 - Register bank select bits: These two bits are used to select one of the four register banks in RAM. By writing zeroes and ones to these bits, a group of registers R0-R7 is stored in one of four banks in RAM.

TABLE: 1.4 DIFFERENT COMBINATIONS OF RS0 AND RS1


RS1 0 0 1 1 F0 - Flag 0: This is a general-purpose bit available to the user. AC - Auxiliary Carry Flag: It is used for BCD operations only. CY - Carry Flag: It is the (ninth) auxiliary bit used for all arithmetical operations and shift instructions. The above table shows that RS0 and RS1 are responsible for selecting the particular Register bank i.e. by using the different combinations of RS0 and RS1 the Register Banks are selected. RS2 0 1 0 1 SPACE IN RAM Bank 0 (00h-07h) Bank 1 (08h-0Fh) Bank 2 (10h-17h) Bank 3 (18h-1Fh)

1.10.2.3 TIMER MODE REGISTERS:


This register selects mode of the timers T0 and T1. As illustrated in the following picture, the lower 4 bits (bit0 - bit3) refer to the timer 0, while the higher 4 bits (bit4 - bit7) refer to the timer 1. There are in total of 4 modes.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 34

Fig: 1.17 Timer Mode Registers Modes: The Timer Counter function is selected by the control bits C/T in the Special function register TMOD. These two timers have four operating modes selected by the bit pairs (M1, M0) in TMOD. GATE:-Gating control when set. Timer/Counter x is enabled only while INT pin is high and TRx control pin is set. When cleared, Timer x is enabled whenever TRx control bit is set. C/T: - Timer or Counter selector: When the Timer operation is to be performed then it gets reset and gets set for Counter operation. TIM0:- Timer 1 Mode 0: These two bits select the Timer 1 operating mode.

TABLE: 1.5 DESCRIPTION OF TIMER 1 IN MODE 0 AND MODE 1.


T1M1 0 0 1 1 T1M0 0 1 0 1 MODE 0 1 2 3 DESCRIPTION 13-bit timer 16-bit timer 8-bit auto-reload Split mode

T0M1, T0M0:- Timer 0 Mode 1, Timer 0Mode 0: These two bits select the Timer 0 operating mode.

TABLE: 1.6 DESCRIPTION OF TIMER 0 IN MODE 0 AND MODE 1.


T0M1 0 0 1 T0M0 0 1 0 Mode 0 1 2 Description 13-bit timer 16-bit timer 8-bit auto-reload

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 35

Split mode

T0M0:- Timer 0 in MODE 0: This is one of the rarities being kept only for compatibility with the previous versions of the microcontrollers. When using this mode, the higher byte TH0 and only the first 5 bits of the lower byte TL0 are in use. Being configured in this way, the Timer 0 uses only 13 of all 16 bits. How does it operate? With each new pulse coming, the state of the lower register (that one with 5 bits) is changed. After 32 pulses received it becomes full and automatically is reset, while the higher byte TH0 is incremented by 1. This action will be repeated until registers count up 8192 pulses. After that, both registers are reset and counting starts from 0. T0M1:- Timer 0 in Mode 1(16-bit Timer): All bits from the registers TH0 and TL0 are used in this mode. That is why for this mode is being more commonly used. Counting is performed in the same way as in mode 0, with difference that the timer counts up to 65 536, i.e. as far as the use of 16 bits allows. T0M2:- Timer 0 in Mode 2(Auto-Reload Timer): What does auto-reload mean? Simply, it means that such timer uses only one 8-bit register for counting, but it never counts from 0 but from an arbitrary chosen value (0- 255) saved in another register. The advantages of this way of counting are described in the following example: suppose that for any reason it is continuously needed to count up 55 pulses at a time from the clock generator. When using mode 1 or mode 0, it is needed to write number 200 to the timer registers and check constantly afterwards whether overflow occurred, i.e. whether the value 255 is reached by counting. When it has occurred, it is microcontroller performs the same procedure in mode 2 automatically. Namely, in this mode it is only register TL0 operating as a timer (normally 8-bit), while the value from which counting should start is saved in the TH0 register. Referring to the previous example, in order to register each 55th pulse, it is needed to write the number 200 to the register and configure the timer to operate in mode 2. T0M3:- Timer 0 in Mode 3(Split Timer): By configuring Timer 0 to operate in Mode 3, the 16-bit counter consisting of two registers TH0 and TL0 is split into two independent 8-bit timers. In addition, all control bits which belonged to the initial

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 36

Timer 1 (consisting of the registers TH1 and TL1), now control newly created Timer 1. This means that even though the initial Timer 1 still can be configured to operate in any mode ( mode 1, 2 or 3 ), it is no longer able to stop, simply because there is no bit to do that. Therefore, in this mode, it will uninterruptedly operate in the background .The only application of this mode is in case two independent 'quick' timers are used and the initial Timer 1 whose operating is out of control is used as baud rate generator.

1.10.2.4 TCON: TIMER CONTROL REGISTER:


This is also one of the registers whose bits directly control timer operating. Only 4 of all 8 bits this register has are used for timer control, while others are used for interrupt control.

Fig: 1.18 Timer Control Registers TF1, TF0:- These are the Over flow flags for timer 1 and timer 0. TR1, TR0:- It runs the control bits from Timer 1 and Timer 0. Set to run reset to hold. IE1, IE0:-It is the Edge flag for the external interrupts 1 and 0. It is set by the interrupt edge and cleared when the interrupt is processed. These are not related to counter/timer operation. IT1, IT0:- It is a type bit for external interrupts and gets set for falling edge interrupts and reset for 0 level interrupts. These are also not related to counter/timer operation.

1.10.2.5 SCON: SERIAL CONTROL REGISTER:


This register is an 8-bit register and is used to control the various pins which are responsible for transmitting and receiving the data i.e. for the serial transmission.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 37

Fig: 1.19 Serial Control Registers SM0 - Bit select mode. SM1 - Bit select mode. SM2 - Bit is used in case that several microcontrollers share the same interface. In normal circumstances this bit must be cleared in order to enable connection to function normally. REN - Bit enables data receiving via serial communication and must be set in order to enable it. TB8 - Since all registers in microcontroller are 8-bit registers, this bit solves the problem of sending the 9th bit in modes 2 and 3. Simply, bits content is sent as the 9th bit. RB8 - Bit has the same purpose as the bit TB8 but this time on the receiver side. This means that on receiving data in 9-bit format, the value of the last (ninth) appears on its location. TI - Bit is automatically set at the moment the last bit of one byte is sent when the USART operates as a transmitter. In that way processor knows that the line is available for sending a new byte. Bit must be clear from within the program! RI - Bit is automatically set once one byte has been received. Everything functions in the similar way as in the previous case but on the receive side. This is like a doorbell which announces that a byte has been received via serial communication. It should be read quickly prior to a new data takes its place. This bit must also be also cleared from within the program! As seen, serial port mode is selected by combining the bits SM0 and SM2: TABLE: 1.7 MODES AND DESCRIPTION OF SCON REGISTER. SM0 0 0 1 1 SM1 0 1 0 1 Mode 0 1 2 3 Description 8-bit Shift Register 8-bit UART 9-bit UART 9-bit UART Baud Rate 1/12 the quartz frequency Determined by the timer 1 1/32 the quartz frequency (1/64 the quartz frequency) Determined by the timer 1

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 38

In mode 0, the data are transferred through the RXD pin, while clock pulses appear on the TXD pin. The bout rate is fixed at 1/12 the quartz oscillator frequency. On transmit, the least significant bit (LSB bit) is being sent/received first. (received). TRANSMIT - Data transmission in form of pulse train automatically starts on the pin RXD at the moment the data has been written to the SBUF register. In fact, this process starts after any instruction being performed on this register. Upon all 8 bits have been sent, the bit TI in the SCON register is automatically set. RECEIVE - Starts data receiving through the pin RXD once two necessary conditions are met: bit REN=1 and RI=0 (both bits reside in the SCON register). Upon 8 bits have been received, the bit RI (register SCON) is automatically set, which indicates that one byte is received. Since, there are no START and STOP bits or any other bit except data from the SBUF register, this mode is mainly used on shorter distance where the noise level is minimal and where operating rate is important. A typical example for this is I/O port extension by adding cheap IC circuit (shift registers 74HC595, 74HC597 and similar).

1.10.2.5.1 MODE 1:
In Mode1 10 bits are transmitted through TXD or received through RXD in the following manner: a START bit (always 0), 8 data bits (LSB first) and a STOP bit (always 1) last. The START bit is not registered in this pulse train. Its purpose is to start data receiving mechanism. On receive the STOP bit is automatically written to the RB8 bit in the SCON register. TRANSMIT - A sequence for data transmission via serial communication is automatically started upon the data has been written to the SBUF register. End of 1 byte transmission is indicated by setting the TI bit in the SCON register. RECEIVE - Receiving starts as soon as the START bit (logic zero (0)) appears on the pin RXD. The condition is that bit REN=1and bit RI=0. Both of them are stored in the SCON register. The RI bit is automatically set upon receiving has been completed. The Baud rate in this mode is determined by the timer 1 overflow time.

1.10.2.5.2 MODE 2:
In mode 2, 11 bits are sent through TXD or received through RXD: a START bit (always 0), 8 data bits (LSB first), additional 9th data bit and a STOP bit (always 1) last. On transmit; the 9th data bit is

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 39

actually the TB8 bit from the SCON register. This bit commonly has the purpose of parity bit. Upon transmission, the 9th data bit is copied to the RB8 bit in the same register (SCON).The baud rate is either 1/32 or 1/64 the quartz oscillator frequency. TRANSMIT - A sequence for data transmission via serial communication is automatically started upon the data has been written to the SBUF register. End of 1 byte transmission is indicated by setting the TI bit in the SCON register. RECEIVE - Receiving starts as soon as the START bit (logic zero (0)) appears on the pin RXD. The condition is that bit REN=1and bit RI=0. Both of them are stored in the SCON register. The RI bit is automatically set upon receiving has been completed.

1.10.2.5.3 MODE 3:
Mode 3 is the same as Mode 2 except the baud rate. In Mode 3 is variable and can be selected.

1.10.2.6 SBUF: SERIAL BUFFER:


The serial port is full duplex i.e. it can transmit and receive simultaneously. It can also receive buffer which means that it can begin receiving a second byte before the previously received byte has been read from the receive register. The serial port receive and transmit registers are both accessed by the Special Function Register SBUF i.e. SERIAL BUFFER. Writing to the SBUF register loads the transmit register, and reading. SBUF accesses a physically separate receive register. 1.10.2.7IE: INTERRUPT ENABLED:

Fig: 1.20 Interrupt enable. EA - bit enables or disables all other interrupt sources (globally)

0 - (when cleared) any interrupt request is ignored (even if it is enabled) 1 - (when set to 1) enables all interrupts requests which are individually enabled 0 - UART System cannot generate interrupt

ES - bit enables or disables serial communication interrupt (UART)

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 40

1 - UART System enables interrupt 0 - Timer 1 cannot generate interrupt 1 - Timer 1 enables interrupt 0 - change of the pin INT0 logic state cannot generate interrupt 1 - enables external interrupt at the moment of changing the pin INT0 state 0 - Timer 0 cannot generate interrupt 1 - enables timer 0 interrupt 0 - change of the INT1 pin logic state cannot cause interrupt 1 - enables external interrupt at the moment of changing the pin INT1 state

ET1 - bit enables or disables Timer 1 interrupt


EX1 - bit enables or disables INT 0 pin external interrupt


ET0 - bit enables or disables timer 0 interrupt 0 -- Disabled 1 Enabled Whenever the timer and external interrupt is to be enabled then EX1 and ET1 is used and whenever the timer and external interrupt is to be disabled then EX0 and ET0 is used.

EX0 - bit enables or disables INT1 pin external interrupt

1.10.2.8 IP: INTERRUPT PRIORITY REGISTER:


INTERRUPT PRIORITIES: It is not possible to predict when an interrupt will be required. For that reason, if several interrupt are enabled. It can easily occur that while one of them is in progress, another one is requested. In such situation, there is a priority list making the microcontroller know whether to continue operating or meet a new interrupt request. The priority list consists of 3 l Reset! The absolute master of the situation. If an request for Reset omits, stopped and the microcontroller starts operating from the beginning. Interrupt priority 1 can be stopped by Reset only. Interrupt priority 0 can be stopped by both Reset and interrupt priority 1. Which one of these existing interrupt sources has higher and which one has lower priority is defined in the IP Register (Interrupt Priority Register). It is usually done at the beginning of the program. According to that, there are several possibilities: everything is

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 41

Once an interrupt service begins. It cannot be interrupted by another interrupt at the same or lower priority level, but only by a higher priority interrupt. If two interrupt requests, at different priority levels, arrive at the same time then the higher priority interrupt is serviced first. If the both interrupt requests, at the same priority level, occur one after another, the one who came later has to wait until routine being in progress ends. If two interrupts of equal priority requests arrive at the same time then the interrupt to be serviced is selected according to the following priority list :

1. External interrupt INT0 2. Timer 0 interrupt 3. External Interrupt INT1 4. Timer 1 interrupt 5. Serial Communication Interrupt 0- Low Priority 1- High Priority IP REGISTER: The IP register bits specify the priority level of each interrupt (high or low priority).

Fig: 1.21 Interrupt priority register. PS - Serial Port Interrupt priority bit Priority 0 Priority 1 Priority 0 Priority 1 Priority 0 Priority 1

PT1 - Timer 1 interrupt priority

PX1 - External Interrupt INT1 priority

PT0 - Timer 0 Interrupt Priority

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 42

Priority 0 Priority 1 Priority 0 Priority 1

PX0 - External Interrupt INT0 Priority

CHAPTER-2
2.1 RESULT
Microcontrollers producers have been struggling for a long time for attracting more and more choosy customers. Every couple of days a new chip with a higher operating frequency, more memory and more high-quality A/D converters comes on the market. Nevertheless, by analyzing their structure it is concluded that most of them have the same (or at least very similar) architecture known in the product catalogs as 8051 compatible. What is all this about? The whole story began in the far 80s when Intel launched its series of the microcontrollers labeled with MCS 051. Although, several circuits belonging to this series had quite modest features in comparison to the new ones, they took over the world very fast and became a standard for what nowadays is meant by a word microcontroller. The reason for success and such a big popularity is a skillfully chosen configuration which satisfies needs of a great number of the users allowing at the same time stable expanding (refers to the new types of the microcontrollers). Besides, since a great deal of software has been developed in the meantime, it simply was not profitable to change anything in the microcontrollers basic core. That is

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 43

the reason for having a great number of various microcontrollers which actually are solely upgraded versions of the 8051 family. What is it what makes this microcontroller so special and universal so that almost all the world producers manufacture it today under different name?

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 44

CHAPTER-3
3.1 CONCLUSION
The training in the DUCAT CAREER DEVELOPMENT CENTRE gave a thorough knowledge about micro controllers. This training increased my knowledge in how micro controllers are useful as well as used in the real world. I am sure that this training would help me a lot in future.

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 45

REFERENCES
Books
Microcontrollers Microcontrollers Linear Integrated Circuit Electronics Devices & Circuits Electronics For You -By Muhammad Mazidi -By U.S.Shah -By Gayakwad -By J. Boylstead - Monthly Magazine

Various Websites are:


www.google.com www.downloaddatasheets.com www.atmel.com www.discovercircuits.com www.howstuffworks.com www.analog.com

HARYANA INSTITUTE OF ENGG. AND TECHNOLOGY ,KAITHAL DEPARTMENT OF ELECTRONICS & COMMUNICATION
Page 46

You might also like