You are on page 1of 41

COMPANY PROFILE HCL: Overview

Hindustan Computers Ltd., one of the Indias largest electronics, computing and information technology company. Founded in 1976 by Mr. Shiv Nadar, Ajai Chawdhary and four other colleagues Based in Noida, its a $ 5 billion company with over 60,000 employees and is working in 26 countries

VISION
A global corporation enriching lives and enabling business transformation for our customers, with leadership in chosen technologies and markets. Be the first choice for employees and partners, with commitment to sustainability

MANAGEMENT OBJECTIVES
To fuel initiative and foster activity by allowing individuals freedom ofaction and innovation in attaining defined objectives.

STRENTHS OF HCL
1. Industry Experience of 32 years 2. True Corporate Exposure 3. Contemporary Knowledge and World class experience

IMPORTANCE OF MANAGEMENT TRAINING


To improve knowledge and efficiency for the job Provide useful tools to improve the leadership and management ability. Understand the roles and responsibilities as a manager

CHAPTER-1 INTRODUCTION INTRODUCTION TO THE DEPARTMENT


An embedded system is a computer system designed to perform one or a few dedicated functions often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems control many devices in common use today. Embedded systems are controlled by one or more main processing cores that is typically either a microcontroller or a digital signal processor (DSP). The key characteristic is however being dedicated to handle a particular task, which may require very powerful processors. Since the embedded system is dedicated to specific tasks, design engineers can optimize it reducing the size and cost of the product and increasing the reliability and performance.

CHARACTERISTICS
1. Embedded systems are designed to do some specific task, rather than

be a general-purpose computer for multiple tasks. Some also have real-time performance constraints that must be met, for reasons such

as safety and usability; others may have low or no performance requirements, allowing the system hardware to be simplified to reduce costs. 2. Embedded systems are not always standalone devices. Many embedded systems consist of small, computerized parts within a larger device that serves a more general purpose.
3. The program instructions written for embedded systems are referred

to as firmware, and are stored in read-only memory or Flash memory chips. They run with limited computer hardware resources: little memory, small or non-existent keyboard and/or screen.

Peripherals
Embedded Systems talk with the outside world via peripherals such as:

Serial Communication Interfaces (SCI): RS-232, RS-422, RS-485 etc. Synchronous Serial Communication Interface: I2C, SPI, SSC and ESSI (Enhanced Synchronous Serial Interface). Universal Serial Bus (USB). Multi Media Cards (SD Cards, Compact Flash etc). Networks: Ethernet, Controller Area Network, LAN Works, etc. Timers: PLL(s), Capture/Compare and Time Processing Units. Discrete IO: like as General Purpose Input/Output (GPIO). Analog to Digital/Digital to Analog (ADC/DAC). Debugging: JTAG, ISP, ICSP, BDM Port, BITP DP9 port.

CHAPTER-2 SOFTWARE USED


The Keil 8051 Development Tools are designed to solve the complex problems facing embedded software developers. When starting a new project, simply select the microcontroller you use from the Device Database and the Vision IDE sets all compiler, assembler, linker, 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.

VARIOUS STEPS TO USE THE KEIL COMPILER:


Open keil from the start menu. 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.

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.

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

CHAPTER-3. STUDY OF VARIOUS MODULES


3.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. 3.1.1CIRCUIT DIAGRAM:

3.1.2 STEPS TO DESIGN THE HARDWARE:


3.1.2.1 COMPONENT REQUIRED: LEDs (8). 470 resistor (1). Switches (3). Connecting wires. Zero PCB. 3.1.2.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.

3.1.3 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++) {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; } } }

3.2 INTERFACING OF SWITCHES WITH THE 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. 3.2.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++) {_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); P1=j;} }

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

3.3 INTERFACING OF SEVEN SEGMENT DISPLAY WITH THE MICROCONTROLLER

Single seven segment display. Double seven segment display.

A seven-segment display (abbreviation: "7-seg(ment) display"), less commonly known as a seven-segment 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. 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.

3.3.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.

3.3.2 SINGLE SEVEN SEGMENT: 3.3.2.1 CIRCUIT DIAGRAM:

3.3.2.2 STEPS TO DESIGN THE HARDWARE:


3.3.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. 3.3.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. How to make a code for a digit:

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

3.3.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++) {_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]; } } }

3.4 INTERFACING OF DC MOTOR WITH THE 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 no-load 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 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. 3.4.1 Unidirection Control: Figure shows the DC motor rotation for clockwise (CW) and counterclockwise (CCW) rotations.

3.4.4 CIRCUIT DIAGRAM:

3.4.5 STEPS TO DESIGN THE HARDWARE:

3.4.5.1 COMPONENT REQUIRED:

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? 3.4.5.2 STEPS: 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. Connect motor across the emitter and 12V supply. 3.4.6 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;} } } }

STEPPER MOTOR

Motion Control, in electronic terms, means to accurately control the movement of an object based on either speed, distance, load, inertia or a combination of all these factors. There are numerous Brushless, Servo, Brushless Servo and more. 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. types of motion control systems, including; Stepper Motor, Linear Step Motor, DC Brush,

A stepper motor differs from a conventional motor (CM) as under:

a. Input to SM is in the form of electric pulses whereas input to a CM is invariably from a constant voltage source. b. A CM has a free running shaft whereas shaft of SM moves through angular steps. c. In control system applications, no feedback loop is required when SM is used but a feedback loop is required when CM is used. d. A SM is a digital electromechanical device whereas a CM is an analog electromechanical device [40]. 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 [39]. 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 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. This repeatable

Rotor Alignment

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

Stator Windings Configuration Step 1 2 3 4 Winding A 0 1 1 1 Winding B 1 0 1 1 Winding C 1 1 0 1 Winding D 1 1 1 0

Input Sequence to the Windings

Since the stepper motor is not an ordinary motor and has four separate coils which have to be energised 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. 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 collectorat 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 phototransisitor which is now being forwarded to the collector . But the output current of the phototransistor is very low to energise the coil of the stepper motor . So we feed the output of the stepper motor to a current amplyfying transistor (369) at its base and its emitter is connected to positive supply . Now the current output will be sufficient to energise 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: 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 pim number 1 will output a high signal and rest all output pins willprovide 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 tf 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 pinsa 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. Now when the output pin of the printer port becomes high ,the corresponding LED glows and the phototransistors base gets activated becauese 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 pase\ses 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 assenbly 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.

STEP ANGLE AND STEPS PER REVOLUTION

Movement associated with a single step, depends on the internal construction of the motor, in particular the number of teeth on the stator and the rotor. The step angle is the minimum degree of rotation associated with a single step. Step per revolution is the total number of steps needed to rotate one complete rotation or 360 degrees (e.g., 180 steps * 2 degree = 360) [31]. Since the stepper motor is not 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 energizing 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 that will perform this operation. Here we are using a PC to perform this function.

3.7-Liquid Crystal Display

LCD 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 Hitatchi 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 2s t c d
1

Fig 3.21 LCD Pin Description Diagram

VCC, VSS, VEE 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.

3.7.2 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 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 databus). 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 sould 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 psuedo-schematic of how the LCD will be connected to the 8051.

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 EQU EQU EQU EQU EQU EQU P1.0 P1.1 P1.2 P1.3 P1.4 P1.5

DB6 DB7 EN RS RW

EQU EQU EQU EQU EQU

P1.6 P1.7 P3.7 P3.6 P3.5

3.7.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

3.7.4 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; } 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(); ACC='_'; display(); ACC='g'; display(); ACC='y'; display(); ACC='a'; display(); }

You might also like