KEMBAR78
CA Lab Manual | PDF | Embedded System | Input/Output
0% found this document useful (0 votes)
9 views38 pages

CA Lab Manual

The computer applications lab in the Electronics and Communication Engineering department provides students with practical skills and theoretical knowledge through hands-on experiments, particularly in Embedded C programming for microcontrollers. It covers various topics including embedded system programming, interfacing with hardware, and using software tools like Keil and Proteus for simulation. The lab also emphasizes industrial applications of Embedded C and includes detailed instructions for implementing logic gates and interfacing with LCDs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views38 pages

CA Lab Manual

The computer applications lab in the Electronics and Communication Engineering department provides students with practical skills and theoretical knowledge through hands-on experiments, particularly in Embedded C programming for microcontrollers. It covers various topics including embedded system programming, interfacing with hardware, and using software tools like Keil and Proteus for simulation. The lab also emphasizes industrial applications of Embedded C and includes detailed instructions for implementing logic gates and interfacing with LCDs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Introduction to computer applications lab:

The computer applications lab in the Electronics and Communication Engineering


department serves as a vital resource for students to acquire practical skills, explore concepts,
conduct experiments, and apply theoretical knowledge in a real-world context. It enhances their
learning experience, supports their academic and research endeavors, and prepares them for
professional careers in the field.
The lab is an advanced computer center focusing on scientific computing with
advanced software for scientific and research curriculum. Students can use this space to
work and seek support from higher level Electronics and communications engineering students
experienced with the Embedded Systems lab.

Embedded C for Microcontrollers

Embedded C Programming – Presently, many embedded applications were generated using


assembly level programming. However, they did not provide portability. Embedded C
programming plays a crucial role to make the microcontroller run & perform the fancied
actions. At present, we usually utilize several electronic devices like mobile phones, washing
machines, security systems, refrigerators, digital cameras, etc. The managing of these
embedded devices can be done with the help of an embedded C program.

Embedded C programming strengthens with functions where every function is a set of


statements utilized to complete specific tasks. The embedded C and C languages are equivalent
and implemented through significant components like a variable, character set, keywords, data
types, declaration of variables, expressions, statements. All features play a significant role
while writing an embedded C program.

Embedded System Programming

As we discussed earlier, the drafting of an embedded system can be done using Hardware &
Software. For example, in a simple embedded system, the processor is the main module that
works like the system’s heart. A processor is nothing but a microprocessor, DSP,
microcontroller, CPLD & FPGA. All these processors are programmable so that it recognizes
the working of the device.

1
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
An Embedded system program provides the hardware to check the inputs & control outputs,
respectively. In this procedure, the embedded program may have to command the processor’s
internal architecture directly like Timers, Interrupt Handling, I/O Ports, serial communications
interface, etc.

Benefits of Embedded C

 It is effortless to understand.
 It executes a similar task continually, so there is no requirement for changing hardware
like additional memory, otherwise storage space.
 It performs merely a single task at once
 The cost of the hardware used in the embedded c is typically so much low.
 The applications of embedded are incredibly appropriate in industries.
 It takes less time to develop an application program.
 Embedded C can run pre-defined programming.
 Embedded C is the speed of entering code which provides more accelerated results.

Industrial Applications of Embedded C

 Embedded C programming is used in industries for different purposes


 The programming language used in the applications is speed controller on the highway,
commanding of traffic lights, controlling of street lights, pursuing the vehicle, artificial
intelligence, home automation, and auto intensity control.

AT89S52 Microcontroller
FEATURES
 8051 based architecture
 8-Kbytes of on-chip Reprogrammable Flash Memory
 256 x 8 RAM
 Two 16-bit Timer/Counters
 Full duplex serial channel
 Four 8-bit I/O ports, 32 I/O lines
 Memory addressing capability
– 64K ROM and 64K RAM
 Power save modes:

2
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
– Idle and power-down
– Six interrupt sources
 Most instructions execute in 0.3 us
 CMOS and TTL compatible
 Maximum speed: 40 MHz @ Vcc = 5V
 Industrial temperature available
 Packages available: 40-pin DIP
PIN DIAGRAM

Fig. PIN DIAGRAM OF 8052

3
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
STEPS TO WRITE AND COMPILE EMBEDDED C PROGRAM IN KEIL
1. Install the Keil3 Software in the PC in any of the drives.
2. After installation, an icon will be created with the name “Keil uVision3”. Just drag this
icon onto the desktop so that it becomes easy whenever you try to write programs in
keil3.
3. Double click on this icon to start the keil3 compiler.
4. A page opens with different options in it showing the project workspace at the leftmost
corner side, output window in the bottom and an ash coloured space for the program to
be written.
5. Now to start using the keil3, click on the option “project”.
6. A small window opens showing the options like new project, import project, open
project etc. Click on “New project”.
7. A small window with the title bar “Create new project” opens. The window asks the
user to give the project name with which it should be created and the destination
location. The project can be created in any of the drives available. You can create a new
folder and then a new file or can create directly a new file.
8. After the file is saved in the given destination location, a window opens where a list of
vendors will be displayed and you have to select the device for the target you have
created.
9. The most widely used vendor is Atmel. So click on Atmel and now the family of
microcontrollers manufactured by Atmel opens. You can select any one of the
microcontrollers according to the requirement.
10. When you click on any one of the microcontrollers, the features of that particular
microcontroller will be displayed on the right side of the page. The most appropriate
microcontroller with which most of the projects can be implemented is the AT89S52.
Click on this microcontroller and have a look at its features. Now click on “OK” to
select this microcontroller.
11. A small window opens asking whether to copy the start-up code into the file you have
created just now. Just click on “No” to proceed further.
12. Now you can see the TARGET and SOURCE GROUP created in the project
workspace.
13. Now click on “File” and in that “New”. A new page opens and you can start writing
program in it.

4
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
14. After the program is completed, save it with any name but with the .c extension. Save
the program in the file you have created earlier.
15. You can notice that after you save the program, the predefined keywords will be
highlighted in bold letters.
16. Now add this file to the target by giving a right click on the source group. A list of
options open and in that select “Add files to the source group”. Check for this file where
you have saved and add it.
17. Right click on the target and select the first option “Options for target”. A window
opens with different options like device, target, output etc. First click on “target”.
18. Since the set frequency of the microcontroller is 11.0592 MHz to interface with the PC,
just enter this frequency value in the Xtal (MHz) text area and put a tick on the Use on-
chip ROM. This is because the program what we write here in the keil3 will later be
dumped into the microcontroller and will be stored in the inbuilt ROM in the
microcontroller.
19. Now click the option “Output” and give any name to the hex file to be created in the
“Name of executable” text area and put a tick to the “Create HEX file” option present
in the same window. The hex file can be created in any of the drives.
20. The hex file created as shown earlier will be dumped into the microcontroller with the
help of another Proteus 7.6 software for simulation.

5
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
1. I/O INTERFACING
Aim: To perform IO Interfacing by connecting input at P2.2 and output at P2.1
Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Theoretical Concept of IO Interfacing:
A switch is an electrical component that can break an electrical circuit, interrupting the current
or diverting it from one conductor to another. A switch may be directly manipulated by a
human as a control signal to a system, or to control power flow in a circuit. Led will be
connected as output device.

Code:

#include<reg52.h>
sbit led=P2^1;
sbit sw=P2^2;
main()
{
P2=0x00;
if(sw==0)
led=0;
else
led=1;
}

6
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
SCHEMATIC CIRCUIT DIAGRAM

Result:
IO Interfacing is implemented and verified through above simulation circuit .

7
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
2. Implementation of Logic Gates

Aim: to Implement AND, OR logic gates by interfacing input switches and output led at port.

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Theoretical Concept of AND, OR logic

A HIGH output (1) results only if all the inputs to the AND gate are HIGH (1).

Program:

a) AND Gate
#include<reg52.h>
sbit sw1=P2^1;
sbit sw2=P2^2;
sbit led=P2^7;
main()
{
P2=0x00;
if(sw1==1&&sw2==1)
{

8
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
led=1;
}
else
{
led=0;
}
}

SCHEMATIC CIRCUIT DIAGRAM:

9
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
b) OR Gate:

The gate will output a '1' for any combination of inputs in a high state, and '0' only when
all inputs are '0'.
Program:
#include<reg52.h>
sbit sw1=P2^1;
sbit sw2=P2^2;
sbit led=P2^7;
main()
{
P2=0x00;
if(sw1==0&&sw2==0)
{
led=0;
}
else
{
led=1;
}

10
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
SCHEMATIC CIRCUIT DIAGRAM:

Result: AND, OR logic gates are implemented and verified through above simulation circuit.

11
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
3. Port Toggling at P2 with 10ms delay
Aim: To observe port toggling by interfacing input switch and output led at port2.

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Theoretical Concept of toggling:

Toggling refers to switch between two different states of output in digital circuits. Here in this
experiment toggling is implemented by adding led as output device at entire 8pins of P2.
Toggling can be observed by adding delay with the concept of for loop.
Code:
#include<reg51.h> // header file
#define port P2 // user defined macro
delay(unsigned int) // global function declaration
void main()
{
P2=0X00; // port initialization
while(1)
{
P2=0x00;
delay(10); // function call
P2=0xff;
delay(10); // function call
P2=0x00;
}
}
delay(unsigned int t) // function call
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<1275;j++); // repeating j loop for 1275 times to provide 1ms delay
}

12
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
SCHEMATIC DIAGRAM:

Result: Port toggling is observed and verified at port2 using above simulation circuit.

13
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
LIQUID CRYSTAL DISPLAY (LCD)

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications. A 16x2 LCD display is very basic module and is very commonly used
in various devices and circuits. These modules are preferred over seven segments and other
multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no
limitation of displaying special & even custom characters (unlike in seven segments),
animations and so on.

A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD
each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command
and Data.

The command register stores the command instructions given to the LCD. A command is an
instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting
the cursor position, controlling display etc. The data register stores the data to be displayed on
the LCD. The data is the ASCII value of the character to be displayed on the LCD.

Fig. 16x2 LCD

Introduction

The most commonly used Character based LCDs are based on Hitachi's HD44780
controller or other which are compatible with HD44580.

Pin Description

Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two
pins are extra in both for back-light LED connections). Pin description is shown in the table
below.

14
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
Pin Configuration table for a 16X2 LCD character display:-
Pin Symbol Function
Number
1 Vss Ground Terminal
2 Vcc Positive Supply
3 Vdd Contrast adjustment
4 RS Register Select; 0→Instruction Register, 1→Data Register
5 R/W Read/write Signal; 1→Read, 0→ Write
6 E Enable; Falling edge
7 DB0
8 DB1
9 DB2 Bi-directional data bus, data transfer is performed once, thru
10 DB3 DB0 to DB7, in the case of interface data length is 8-bits; and
11 DB4 twice, through DB4 to DB7 in the case of interface data
12 DB5 length is 4-bits. Upper four bits first then lower four bits.
13 DB6
14 DB7
15 LED-(K) Back light LED cathode terminal
16 LED+(A) Back Light LED anode terminal
Table Pin Description of LCD

Data/Signals/Execution of LCD

Coming to data, signals and execution.

LCD accepts two types of signals, one is data, and another is control. These signals are
recognized by the LCD module from status of the RS pin. Now data can be read also from the
LCD display, by pulling the R/W pin high. As soon as the E pin is pulsed, LCD display reads
data at the falling edge of the pulse and executes it, same for the case of transmission.

LCD display takes a time of 39-43µS to place a character or execute a command.


Except for clearing display and to seek cursor to home position it takes 1.53ms to 1.64ms. Any
attempt to send any data before this interval may lead to failure to read data or execution of the
current data in some devices. Some devices compensate the speed by storing the incoming data
to some temporary registers.

15
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
Instruction Register (IR) and Data Register (DR)

There are two 8-bit registers in HD44780 controller Instruction and Data register.
Instruction register corresponds to the register where you send commands to LCD e.g LCD
shift command, LCD clear, LCD address etc. and Data register is used for storing data which
is to be displayed on LCD. when send the enable signal of the LCD is asserted, the data on the
pins is latched in to the data register and data is then moved automatically to the DDRAM and
hence is displayed on the LCD. Data Register is not only used for sending data to DDRAM
but also for CGRAM, the address where you want to send the data, is decided by the instruction
you send to LCD. We will discuss more on LCD instruction set further in this tutorial.

Commands and Instruction set

Only the instruction register (IR) and the data register (DR) of the LCD can be
controlled by the MCU. Before starting the internal operation of the LCD, control information
is temporarily stored into these registers to allow interfacing with various MCUs, which operate
at different speeds, or various peripheral control devices. The internal operation of the LCD is
determined by signals sent from the MCU. These signals, which include register selection
signal (RS), read/write signal (R/W), and the data bus (DB0 to DB7), make up the LCD
instructions (Table 3). There are four categories of instructions that:

 Designate LCD functions, such as display format, data length, etc.


 Set internal RAM addresses
 Perform data transfer with internal RAM
 Perform miscellaneous functions

16
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
List of Commands in Hexa Decimal format

0X38 // Function Set: 8-bit, 2 Line, 5x7 Dot matrix mode (DMM)

0X01 // clear if any previous data

0X0C // cursor on

0X06 // shift cursor position to next cell after printing one character

0X80 // force the cursor to start printing from 1st row 1st column

0XC0 // force the cursor to start printing from 2nd row 1st column

0X18 // Shift entire display left

0X1C // Shift entire display right

Liquid crystal displays interfacing with Controller

The LCD standard requires 3 control lines and 8 I/O lines for the data bus.

• 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
RS = 1 -> Data 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.

17
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
4. LCD INTERFACING WITH AT89S52 TO PRINT A
CHARACTER
Aim: Interface 16x2 LCD at port 2 and RS, RW, E pins at Port 3.5, 3.6, 3.7 of AT89S52
respectively to print a character in output display.

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Program:
#include<reg52.h>
#define lcd P2
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^7;
cmd_lcd(unsigned char );
data_lcd(unsigned char );
delay(unsigned int t);
void main()
{
P2=0X00;
P3=0X00;
cmd_lcd(0x38);
cmd_lcd(0x01);
cmd_lcd(0x0C);
cmd_lcd(0x06);
cmd_lcd(0x80);
data_lcd(‘A’);
}
Cmd_lcd(unsigned char a)
{
P2=a;
RS=0;
RW=0;
E=1;
delay(20);
E=0;
}
data_lcd(unsigned char b)
{
P2=b;

18
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
RS=1;
RW=0;
E=1;
delay(20);
E=0;
}
delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<1275;j++);
}

SCHEMATIC CIRCUIT DIAGRAM:

Result:
LCD Interfacing with AT89S52 at P2 to print a character is implemented and
verified using simulation circuit.

19
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
5. LCD INTERFACING WITH AT89S52 TO PRINT A
STRING
Aim: Interface 16x2 LCD at port 2 and RS, RW, E pins at Port 3.5, 3.6, 3.7 of AT89S52
respectively to print a string in output display.

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Program:
#include<reg52.h>
#define lcd P2
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^7;
cmd_lcd(unsigned char);
data_lcd(unsigned char);
delay(unsigned int);
display(unsigned *s);
main()
{
P2=0X00;
P3=0X00;
cmd_lcd(0X38);
cmd_lcd(0X01);
cmd_lcd(0X0C);
cmd_lcd(0X06);
cmd_lcd(0X80);
display(“WELCOME”);
}
delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)

20
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
for(j=0;j<1275;j++);
}
cmd_lcd(unsigned char a)
{
P2=a;
RS=0;
RW=0;
E=1;
delay(10);
E=0;
}
data_lcd(unsigned char b)
{
P2=b;
RS=1;
RW=0;
E=1;
delay(10);
E=0;
}
display(unsigned char *S)
{
while(*S)
data_lcd(*S++);
}

21
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
SCHEMATIC CIRCUIT DIAGRAM:

Result:
LCD Interfacing with AT89S52 at P2 to print a string is implemented and verified
using simulation circuit.

22
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
6. SEVEN SEGMENT LED INTERFACING WITH
MICROCONTROLLER
Aim: Write an Embedded C Program to interface 7 segment display at port 3 to print
hexadecimal numbers (0-9) and letters(A-F).

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation

Program:
#include<reg52.h>
#define seg P3
void main()
{
unsigned int i,j;
unsigned char a[ ]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,
0X77,0X39,0X7C,0X39};
for(i=0;i<t;i++)
{
P3=0X00;
Seg=a[i];
for(j=0;j<1275;j++);
}
}

23
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
SCHEMATIC CIRCUIT DIAGRAM:

Result:
7 segment LED interfacing with microcontroller has been implemented and
verified using simulation circuit.

24
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
7. SENSOR INTERFACING WITH
MICROCONTROLLER
Aim: Write an Embedded C Program to display the sensor status in 16X2 LCD by interfacing
a sensor at Port 1 & LCD at Port 2 and RS, RW, E at Port3.5, Port3.6, Port3.7 respectively.

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation

Program:
#include<reg52.h>
#define lcd P2
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^7;
sbit S1=P1^0;
sbit S2=P1^1;
cmd_lcd(unsigned char);
data_lcd(unsigned char);
delay(unsigned int);
display(unsigned *s);
main()
{
P2=0X00;
P3=0X00;
cmd_lcd(0X38);
cmd_lcd(0X01);
cmd_lcd(0X0C);
cmd_lcd(0X06);
if(S1==0 & S2==0)
{
cmd_lcd(0X80);
display(“BOTH THE SENSORS ARE ACTIVATED”);
25
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
}
else
{
cmd_lcd(0X01);
cmd_lcd(0XC0);
display(“1 SENSOR IS ACTIVATED”);
}
}
cmd_lcd(unsigned char a)
{
P2=a;
RS=0;
RW=0;
E=1;
delay(20);
E=0;
}
data_lcd(unsigned char b)
{
P2=b;
RS=1;
RW=0;
E=1;
delay(20);
E=0;
}
delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<1275;j++);
}

26
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
display(unsigned char *S)
{
while(*S)
data_lcd(*S++);
}

SCHEMATIC CIRCUIT DIAGRAM:

Result:
Sensor status has been verified by interfacing sensor along with microcontroller
by verifying using simulation circuit.

27
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
DC MOTOR
A DC motor in simple words is a device that converts direct current(electrical energy)
into mechanical energy. It’s of vital importance for the industry today.
A DC motor is designed to run on DC electric power. Two examples of pure DC designs
are Michael Faraday's homo-polar motor (which is uncommon), and the ball bearing motor,
which is (so far) a novelty.

By far the most common DC motor types are the brushed and brushless types, which
use internal and external commutation respectively to create an oscillating AC current from the
DC source—so they are not purely DC machines in a strict sense.

We in our project are using brushed DC Motor, which will operate in the ratings of 12v
DC 0.6A.
The speed of a DC motor can be controlled by changing the voltage applied to the
armature or by changing the field current. The introduction of variable resistance in the
armature circuit or field circuit allowed speed control. Modern DC motors are often controlled
by power electronics systems called DC drives.

Fig. Motor
Usage
The DC motor or Direct Current Motor to give it its full title, is the most commonly used
actuator for producing continuous movement and whose speed of rotation can easily be
controlled, making them ideal for use in applications were speed control, servo type control,
and/or positioning is required. A DC motor consists of two parts, a "Stator" which is the
stationary part and a "Rotor" which is the rotating part. The result is that there are basically
three types of DC Motor available.

28
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
8. DC MOTOR INTERFACING WITH MICROCONTROLLER
Aim: Write an Embedded C Program for Sensor, DC Motor, Buzzer interfacing & displaying
Status in LCD by interfacing LCD at Port 0, RS, RW, E at Port 3, Sensors at Port 0&1, Motor
at Port 1.6, Buzzer at Port 2.0.

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Program:
#include<reg52.h>
#define lcd P0
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^7;
sbit M=P1^6;
sbit BZ=P2^0;
sbit S1=P1^0;
sbit S2=P1^1;
cmd_lcd(unsigned char);
data_lcd(unsigned char);
delay(unsigned int);
display(unsigned char *s);
main()
{
P0=0X00;
P1=0X00;
P2=0X00;
P3=0X00;
cmd_lcd(0X38);
cmd_lcd(0X01);
cmd_lcd(0X06);
cmd_lcd(0X0C);

29
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
if(S1==0 & S2==0)
{
M=0;
cmd_lcd(0X80);
display("DOOR IS CLOSED");
BZ=0;
cmd_lcd(0XC0);
display("MOTOR OFF");
delay(30);
}
else
{
M=1;
cmd_lcd(0X01);
cmd_lcd(0X80);
display("DOOR IS OPEN");
cmd_lcd(0XC0);
display("MOTOR ON");
BZ=1;
delay(30);
}
}
cmd_lcd(unsigned char a)
{
P0=a;
RS=0;
RW=0;
E=1;
delay(20);
E=0;
}
data_lcd(unsigned char b)
{
P0=b;
30
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
RS=1;
RW=0;
E=1;
delay(30);
E=0;
}
delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<1275;j++);
}
display(unsigned char *S)
{
while(*S)
data_lcd(*S++);
}

31
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
SCHEMATIC CIRCUIT DIAGRAM:

Result:
DC Motor interfacing with microcontroller has been implemented and verified
using simulation circuit.

32
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
9. DELAY GENERATION USING TIMER
Aim: Write an Embedded C Program to program a timer for 10µs delay by using TIMER 1
MODE 1 & TIMER 0 MODE 0.

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Program:
TIMER 1 & MODE 1:
#include<reg52.h>
main()
{
TMOD=0X10;
TH1=0XFF;
TL1=0XF5;
TR1=1;
while(TF1==0)
TF1=0;
TR1=0;
}

33
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
TIMER 0 & MODE 0:
#include<reg52.h>
main()
{
TMOD=0X00;
TH0=0X1F;
TL0=0X69;
TR0=1;
while(TF0==0)
TF0=0;
TR0=0;
}

34
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
SERIAL COMMUNICATION IN MICRO CONTROLLER

For Serial Transmission:

The following are the steps to send the data serially in serial port communication:

1. Set baud rate by loading TMOD register with the value 20H; this indicates timer 1 in mode
2 (8-bit auto-reload) to set baud rate.

2. The TH1 is loaded with proper values to set baud rate for serial data transfer.

3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-bit
data is framed with start and stop bits.

4. TR1 is set to 1 to start timer 1.

5. Transmit Interrupt (TI) is cleared by CLR TI instruction.

6. The character byte to be transferred serially is written into SBUF register.

7. The TI flag bit is monitored to see if the character has been transferred completely.

8. To transfer the next byte, go to step 5.

35
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
For Receiving Data:

The following are the steps to receive the data serially in the serial port communication:

1. Set baud rate by loading TMOD register with the value 20H; this indicates setting of timer
1 in mode 2 (8-bit auto-reload) to set baud rate.

2. The TH1 is loaded with proper values to set baud rate.

3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-bit
data is framed with start and stop bits.

4. TR1 is set to 1 to start timer 1.

5. Receive Interrupt(RI) is cleared by CLR RI instruction.

6. The RI flag bit is monitored to see if an entire character has been received yet.

7. When RI is raised, SBUF has the byte, its contents are moved into a safe place.

8. To receive next character, go to step 5.

36
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
10 A. SERIAL TRANSMISSION IN MICRO CONTROLLER
Aim: Write a C program for 8051 to transfer the letter “A” serially at 4800 baud continuously.
(Use 8-bit data and 1 stop bit).

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Program:
#include <reg51.h>
void main(void)
{
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFA; //4800 baud rate
SCON=0x50;
TR1=1;
while (1)
{
SBUF=‘A’; //place value in buffer
while (TI==0);
TI=0;
}
}

37
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).
10B. RECEIVING SERIAL DATA IN MICRO CONTROLLER
Aim: Write an 8051 C program to transfer the message “YES” serially at 9600 baud, 8-bit
data, 1 stop bit. Do this continuously.

Apparatus:
1. Computer System
2. Keil3 micro vision software
3. Proteus professional 7.6 software for simulation
Program:
#include <reg51.h>
void SerTx(unsigned char);
void main(void)
{
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1; //start timer
while (1)
{
SerTx(‘Y’);
SerTx(‘E’);
SerTx(‘S’);
}
}
void SerTx(unsigned char x){
SBUF=x; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}

38
COMPUTER APPLICATIONS LAB Dept. of ECE, LIET (A).

You might also like