Iare Mtech Eslab Manual
Iare Mtech Eslab Manual
LAB MANUAL
Prepared By
1
INDEX
1 Lab Objective 3
3 LAB CODE 5
6 Programs List 13
7 References 82
2
Lab Objective:
An embedded system is some combination of computer hardware and software, either fixed in
capability or programmable, that is specifically designed for a particular kind of application device.
Industrial machines, automobiles, medical equipment, cameras, household appliances, airplanes, vending
machines, and toys (as well as the more obvious cellular phone and PDA) are among the myriad possible
hosts of an embedded system. Embedded systems that are programmable are provided with a
programming interface, and embedded systems programming is a specialized occupation.
Since the embedded system is dedicated to specific tasks, design engineers can optimize it, reducing the
size and cost of the product, or increasing the reliability and performance. Some embedded systems are
mass-produced, benefiting from economies of scale.
3
INTRODUCTION ABOUT LAB
There are 30 systems (Dell) installed in this Lab. Their configurations are as follows:
Processor : Intel(R) core (TM) - i3 -4150
CPU RAM : 4 GB
Hard Disk : 500 GB
Mouse : Optical Mouse
Network Interface card : Present
Software
1 All systems are configured in DUAL BOOT mode i.e, Students can boot from Windows 07.This
is very useful for students because they are familiar with different Operating Systems so that they can
execute their programs in different programming environments.
2 Each student has a separate login for database access
3 Software installed: Keil Micro vision, OFFICE-07, Systems are provided for students in the1:1
ratio.
4 Systems are assigned numbers and same system is allotted for students when they do the lab.
4
LAB CODE
1. Students should report to the concerned labs as per time table schedule.
2. Students who turn up late to the labs will in no case be permitted to do the program scheduled for the day.
3. After completion of the program, certification of the concerned staff in-charge in the observation book is
necessary.
4. Students should bring a notebook of about 100 pages and should enter the reading/observations into
5. the notebook while performing the experiment.
6. The record of observations along with the detailed experimental procedure of the experiment performed
in the immediate last session should be submitted and certified by the staff member in-charge.
7. Not more than three students in a group are permitted to perform the experiment on a setup.
8. The group-wise division made in the beginning should be adhered to and no mix up student among
different groups will be permitted later.
9. The components required pertaining to the experiment should be collected from stores in-charge after
duly filling in the requisition form.
10. When the experiment is completed, students should disconnect the setup made by them, and should
return all the components/instruments taken for the purpose.
11. Any damage of the equipment or burn-out of components will be viewed seriously either by putting
penalty or by dismissing the total group of students from the lab for the semester/year.
12. Students should be present in the labs for the total scheduled duration.
13. Students are required to prepare thoroughly to perform the experiment before coming to Laboratory.
14. Procedure sheets/data sheets provided to the student‘s groups should be maintained neatly and to be
returned after the experiment.
5
List of Lab Excercises
Submission – 1
Program to toggle all the bits of port P1 continuously with 250 ms delay.
Week – 1
Program to interface a switch and a buzzer to two different pins of a port such that the buzzer
Week – 2
should sound as long as the switch is pressed.
Week – 3 Program to interface LCD data pins to port P1 and display a message on it
Week – 5 Program to interface keypad. Whenever a key is pressed, it should be displayed on LCD
6
Description about ES Concepts:
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 reason such as
safety and usability; others may have low or no performance requirements, allowing the system hardware
to be simplified to reduce costs. Embedded systems are not always separate devices. Most often they are
physically built-in to the devices they control.
The software written for embedded systems is often called firmware, and is stored in read-only memory
or Flash memory chips rather than a disk drive. It often runs with limited computer hardware resources:
small or no keyboard, screen, and little memory. Embedded systems range from no user interface at all
— dedicated only to one task — to full user interfaces similar to desktop operating systems in devices
such as PDAs. Simple embedded devices use buttons, LEDs, and small character- or digit-only displays,
often with a simple menu system.
7
Introduction to 8051 Microcontroller:
By including the features that are specific to the task (Control), Cost is relatively low.
Microcontroller are a ―one chip solutions‖ which drastically reduces parts count and design costs.
Block Diagram:
8
8051 features:
4K bytes ROM
128 bytes RAM
Four 8-bit I/O ports
Two 16-bit timers
Serial interface
64K external code memory space
ALU
Working Registers
Clock Circuits
Timers and Counters
Serial Data Communication.
8051 CPU Registers:
A (8-bit Accumulator)
B (8-bit register for Mul &Div)
PSW (8-bit Program Status Word)
SP (8-bit Stack Pointer)
PC (16-bit Program Counter)
DPTR (16-bit Data Pointer)
The 8051 is a 40 pin device, but out of these 40 pins, 32 are used for I/O
24 of these are dual purpose, i.e. they can operate as I/O or a control line or as part of address or date
bus.
9
8051 Development Board
(P89V51RD2)
On board Peripherals:
Overview:
The UTS-MC-KIT-M7.3 has got P89V51RD2 microcontroller which has got 64KiloBytes of on
chip Flash memory and 1 KiloBytes of RAM. The kit is has got on board 11.0592MHz crystal for
generating the on chip clock of 11.0592MHz.
A Key feature of the board is it has got so many interfaces, with different on board peripherals
and has got expansion capability to add any further sensor and peripherals in future. This prototype board
is very easy to use for 8051 architecture. This board is interfaced with LED‘s, 7 SEG display, LCD
display, Pushbutton. This Board can also be interfaced with PC via serial communication and can be
viewed through hyper terminal. The LCD display can be connected easily through connectors. No
soldering work /No lose contact/ just plug in the berg connectors.
The board has got on chip peripherals like on board 32 KB bytes of RAM, Eight Light Emitting
Diodes, four Push Buttons, Four Seven Segment Displays, 16X2 Liquid Crystal Character Display(LCD),
Analog to Digital Converter, LM35 Temperature sensor, SPI based ADC, Hex Keypad, Buzzer relay,
steeper motor driver interface, Real time clock, RS-232 serial interface.
10
Component Description:
Microcontroller
The P89V51RD2 device contains a non-volatile 64KB Flash program memory.
In-System Programming (ISP) allows the user to download new code while the microcontroller sits in
the application. A default serial loader (boot loader) program in ROM allows serial In-System
programming of the Flash memory via the UART without
the need for a loader in the Flash code.
This device executes one machine cycle in 6 clock cycles, hence providing twice the speed of a
conventional 80C51. An OTP configuration bit lets the user select conventional 12 clock timing if desired.
This device is a Single-Chip 8-Bit Micro controller manufactured in advanced CMOS process and is a
derivative of the 80C51 micro controller family. The instruction set is 100% compatible with the 80C51
instruction set.
The device also has four 8-bit I/O ports, three 16-bit timer/event counters, a multisource, and four-
priority-level, nested interrupt structure, an enhanced UART and on-chip oscillator and timing circuits.
The added features of the P89V51RD2 makes it a powerful micro controller for applications that require
pulse width modulation, high-speed I/O and up/down counting capabilities such as motor control.
RVision is a Windows application that encapsulates the Keil microcontroller development tools
as well as several third-party utilities. RVision provides everything you need to start creating embedded
programs quickly. RVision includes an advanced editor, project manager, and make utility, which work
together to ease your development efforts, decreases the learning curve, and helps you to get started with
creating embedded applications quickly.
The below section provides a step-by-step tutorial that shows you how to create an embedded project
using the RVision IDE.
11
Downloading the hex file to the target using Flash magic Software:
Open the Flash Magic tool for downloading into the Microcontroller Board. Click on Device menu select
option you will be popped up with a window named choose device. Under choose device options select
8051 and click on Ok button to open flash magic tool to download the hex file in to the MC
Terminal Software for Check the Serial port Data receiving from Microcontroller to PC:
Terminal is a simple serial port (COM) terminal emulation program. It can be used for communication
with different devices such as modems, routers, embedded microcontroller systems, GSM phones, GPS
modules... It is very useful debugging tool for serial communication applications.
12
13
14
EXPERIMENT – 1
Aim:
Write a Embedded C Program to toggle all the bits of Port P1 continuously with 250 mS
delay led blink with 89V51RD2 microcontroller board
Equipment Requirements:
a) Hardware Requirements :
- 22 -
Source code:
/* Program to toggle all the bits of Port P1 continuously with 250 mS delay. */
#include<REG51.H>
#define LEDPORT P1
Flow Chart:
- 23 -
Hardware configuration:
Connect an 8 pin bus from Port 1 (P1) to the LED pins (No 3 pin strip) or place an 8 pin
Jumper connecting No2 and No3 pin strips.
Turn Off and On the Board or just reset it to view the output.
Results/Output verification:
Now the led program is running on Microcontroller. And the output can be seen in the
board. You can see led toggling
- 24 -
- 25 -
EXPERIMENT – 2
Aim:
Write a Embedded C Program to interface a switch and a buzzer to two different pins of a port such
that the buzzer should sound as long as the switch is pressed.
Equipment Requirements:
Hardware Requirements:
- 26 -
Source code:
/*Program to interface a switch and a buzzer to two different pins of a Port such that the
buzzer
should sound as long as the switch is pressed.*/
#include <REG51.H> // special function register declarations for the intended 8051
derivative
Flow Chart:
- 27 -
Hardware configuration:
1. Connect a single pin wire from PORT 1.4 to any switch available on board.
2. Place the jumper at jp6 jumper position to connect the buzzer onboard to the controller.
3. Turn ON and OFF or reset the board, to view the output.
Results/Output verification:
After programming the code into the microcontroller just reset the microcontroller. You can
listen to the buzzer buzzing.
- 28 -
EXPERIMENT – 3
Aim:
Write a Embedded C Program to interface LCD data pins to port P1 and display a message
on it using 89V51RD2
Equipment Requirements:
Hardware Requirements :
- 29 -
Source code:
/*Program to interface LCD data pins to port P1 and display a message on it.*/
#include <reg51.h>
#include "lcd.h" // refer LCD.H code for more to about LCD
main( )
{
LCD_init();
while(1)
{
LCD_clear();
Delay_sec(1);
LCD_row1();
LCD_puts(" welcome come to embedded lab ");
LCD_row2();
LCD_puts(" iare ");
Delay_sec(5);
LCD_clear();
Delay_sec(1);
LCD_clear();
LCD_row1();
LCD_puts("EMEBEDDED SYSTEMS ");
LCD_row2();
LCD_puts("AERONAUTICAL ENGG.");
Delay_sec(5);
}
}
- 30 -
Hardware configuration and Realization:
1. Connect a 6 pin jumper or 6 pin bus from PORT 2 to LCD module available on board.
2. Turn ON and OFF or reset the board, to view the output.
Results/Output verification:
After programming the code into the microcontroller just reset the microcontroller. You can see the
text on the LCD.
- 31 -
EXPERIMENT – 4
Aim:
Equipment Requirements:
Hardware Requirements:
- 32 -
Source code:
#define LEDPORT P0
void Delay(void);
while(1)
{
LEDPORT = ZERO;
Delay();
LEDPORT = ONE;
Delay();
LEDPORT = TWO;
Delay();
- 33 -
LEDPORT = THREE;
Delay();
LEDPORT = FOUR;
Delay();
LEDPORT = FIVE;
Delay();
LEDPORT = SIX;
Delay();
LEDPORT = SEVEN;
Delay();
LEDPORT = EIGHT;
Delay();
LEDPORT = NINE;
Delay();
LEDPORT = TEN;
Delay();
LEDPORT = ELEVEN;
Delay();
LEDPORT = TWELVE;
Delay();
LEDPORT = THIRTEEN;
Delay();
LEDPORT = FOURTEEN;
Delay();
LEDPORT = FIFTEEN;
Delay();
}
}
void Delay(void)
{
int j;
int i;
for(i=0;i<30;i++)
{
for(j=0;j<10000;j++)
{
}
}
}
- 34 -
HARWARE CONFIGURATION:
To check the output connects the wires as shown and press any key from the keypad that value should
be displayed on seven segments.
Result:
- 35 -
EXPERIMENT – 5
Aim:
Write a Embedded C Program to 4*4 interface keyboard. Whenever a key is pressed, it should be
displayed on LCD using 89V51RD2
Equipment Requirements:
Hardware Requirements:
- 36 -
Source code:
#include <reg51.h>
#include"lcd.h"
sbit C1 = P1^0;
sbit C2 = P1^1;
sbit C3 = P1^2;
sbit C4 = P1^3;
sbit R1 = P1^4;
sbit R2 = P1^5;
sbit R3 = P1^6;
sbit R4 = P1^7;
void delay()
{
unsigned int i;
for (i=0; i<10; i++); /* For 1 ms */
}
//test row 1
if (C1 == 0)
{ // key 1 is presed
delay(); //debounce
while (C1==0); //wait until release the key
return 1;
}
if (C2 == 0)
{ //key 2 is pressed
delay(); //debounce
while (C2==0); //wait until release the key
- 37 -
return 2;
}
if (C3 == 0)
{ //key 3 is pressed
delay(); //debounce
while (C3==0); //wait until release the key
return 3;
}
if (C4 == 0)
{ //key 4 is pressed
delay(); //debounce
while (C4==0); //wait until release the key
return 4;
}
//test row 2
R4=1;
R3=1;
R2=0;
R1=1;
if (C1 == 0)
{ //key 5 is pressed
delay(); //debounce
while (C1==0); //wait until release the key
return 5;
}
if (C2 == 0)
{ //key 6 is pressed
delay(); //debounce
while (C2==0); //wait until release the key
return 6;
}
if (C3 == 0)
{ //key 6 is pressed
delay(); //debounce
while (C3==0); //wait until release the key
return 7;
}
if (C4 == 0)
{ //key 7 is pressed
delay(); //debounce
while (C4==0); //wait until release the key
return 8;
}
//test row 3
- 38 -
R4=1;
R3=0;
R2=1;
R1=1;
if (C1 == 0)
{ //key 8 is pressed
delay(); //debounce
while (C1==0); //wait until release the key
return 9;
}
if (C2 == 0)
{ //key 9 is pressed
delay(); //debounce
while (C2==0); //wait until release the key
return 10;
}
if (C3 == 0)
{ //key A is pressed
delay(); //depounce
while (C3==0); //wait until release the key
return 11;
}
if (C4 == 0)
{ //key B is pressed
delay(); //depounce
while (C4==0); //wait until release the key
return 12;
}
//test row 4
R1=1;
R2=1;
R3=1;
R4=0;
if (C1 == 0)
{ //key C is pressed
delay(); //depounce
while (C1==0); //wait until release the key
return 13;
}
if (C2 == 0)
{ //key D is pressed
delay(); //depounce
while (C2==0); //wait until release the key
return 14;
- 39 -
}
if (C3 == 0)
{ //key E is pressed
delay(); //depounce
while (C3==0); //wait until release the key
return 15;
}
if (C4 == 0)
{ //key C is pressed
delay(); //depounce
while (C4==0); //wait until release the key
return 16;
}
return 0; // Means no key has been pressed
}
while(1)
{
key=READ_SWITCHES();
if(key)
{
P3 = key-1;
LCD_clear();
LCD_row1();
LCD_puts("< SERIAL KEYPAD >");
LCD_row2();
LCD_puts("KEY : ");
switch(key)
{
case 1:
{
LCD_putc('0');
break;
- 38 -
}
case 2:
{
LCD_putc('1');
break;
}
case 3:
{
LCD_putc('2');
break;
}
case 4:
{
LCD_putc('3');
break;
}
case 5:
{
LCD_putc('4');
break;
}
case 6:
{
LCD_putc('5');
break;
}
case 7:
{
LCD_putc('6');
break;
}
case 8:
{
LCD_putc('7');
break;
}
case 9:
{
LCD_putc('8');
break;
- 39 -
}
case 10:
{
LCD_putc('9');
break;
}
case 11:
{
LCD_putc('A');
break;
}
case 12:
{
LCD_putc('B');
break;
}
case 13:
{
LCD_putc('C');
break;
}
case 14:
{
LCD_putc('D');
break;
}
case 15:
{
LCD_putc('E');
break;
}
case 16: }
{
- 40 -
LCD_putc('F');
break;
}// switch
}//if
}//while
}//main
1. Connect a 6 pin jumper or 6 pin bus from PORT 2 to LCD module available on board.
2. Connect 8 pin jumper to the hex keypad module on the board.
3. Turn ON and OFF or reset the board, to view the output.
Results/Output verification:
After programming the code into the microcontroller just reset the microcontroller. You can
listen to the buzzer buzzing.
- 41 -
- 42 -
EXPERIMENT – 6(a)
Aim:
Equipment Requirements:
Hardware Requirements:
- 43 -
Basic Theory of 8051 Serial commutations:
Serial port must be configured prior to being used. In other words, it is necessary to
determine how many bits is contained in one serial ―word‖, baud rate and synchronization clock source.
The whole process is in control of the bits of the SCON register (Serial Control).
SM0 - Serial port mode bit 0 is used for serial port mode selection.
SM1 - Serial port mode bit 1.
SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit.
TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byte is sent. It's a signal
to the processor that the line is available for a new byte transmit. It must be cleared from within the
software.
RI - Receive Interrupt flag is automatically set upon one byte receive. It signals that byte is received and
should be read quickly prior to being replaced by a new data. This bit is also cleared from within the
software.
- 44 -
SM0 SM1 Mode Description Baud Rate
0 0 0 8-bit Shift Register 1/12 the quartz frequency
0 1 1 8-bit UART Determined by the timer 1
1 0 2 9-bit UART 1/32 the quartz frequency (1/64
the quartz frequency)
1 1 3 9-bit UART Determined by the timer 1
Source code:
/*Program to transmit a message from Microcontroller to PC serially using RS232.*/
- 45 -
DisplayMesPC(mes);
while(1);
}
void serial_init()
{
TMOD = 0x20; /* GATE OFF,C/#T = 0, M1 M0 = 10(8 BIT AUTO
RELOAD) TIMER 0 ,TIMER 1 IN MODE 2(AUTO RELOAD MODE)*/
SCON = 0x50; /* SERIAL PORT IN MODE2 8-BIT UART VARIABLE
BAUDRATE */
TH1 = 0xfd; /* TIMER 1 FOR BAUD RATE GEN(9.6K)*/
TR1 = 1; /* baud rate timer start*/
}
- 46 -
Flow chart:
Results/Output verification:
Now the program is running on Microcontroller. And the output can be seen in the board. You
can see terminal device .
- 47 -
EXPERIMENT – 6(b)
Aim:
Equipment Requirements:
Hardware Requirements:
- 48 -
Basic Theory of 8051 Serial commutations:
Serial port must be configured prior to being used. In other words, it is necessary to
determine how many bits is contained in one serial ―word‖, baud rate and synchronization clock source.
The whole process is in control of the bits of the SCON register (Serial Control).
SM0 - Serial port mode bit 0 is used for serial port mode selection.
SM1 - Serial port mode bit 1.
SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit.
TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byte is sent. It's a
signal
to the processor that the line is available for a new byte transmit. It must be cleared from within the
software.
RI - Receive Interrupt flag is automatically set upon one byte receive. It signals that byte is received
and
should be read quickly prior to being replaced by a new data. This bit is also cleared from within the
software.
SM0 SM1 Mode Description Baud Rate
0 0 0 8-bit Shift Register 1/12 the quartz frequency
- 49 -
0 1 1 8-bit UART Determined by the timer 1
0 1 2 9-bit UART 1/32 the quartz frequency
1 1 3 9-bit UART Determined by the timer 1
Source code:
/*Program to receive a message from PC to microcontroller serially using RS232.*/
#include <reg51.h>
unsigned char c;
TMOD = 0x20; /* configure timer for the correct baud rate*/ TH1 = 0xe6; /*
1200 bps for 12 MHz clock */
TCON = 0x00; /* Set timer to not running */
void main(void) {
unsigned char c;
while( 1 )
{
char ReceivSerial()
}
}
- 50 -
Flow chart:
Results/Output verification:
Now the program is running on Microcontroller. And the output can be seen in the board.
- 51 -
EXPERIMENT – 7
Program to interface Stepper Motor to rotate the motor in clockwise and anticlockwise directions
Aim:
Write a Embedded C Program to interface Stepper Motor to rotate the motor in clockwise and
anticlockwise directions
Equipment Requirements:
Hardware Requirements:
- 52 -
Switching sequence : One Phase excitation (Wave drive)
Source code:
/*Program to interface Stepper Motor to rotate the motor in clockwise and anticlockwise
directions*/
#include <reg51.h>
void main(void)
{
P3=0x00;
SW1 = 0;
SW2 = 0;
while(1)
{
- 53 -
if(SW1 == 0)
{
P3 = 0x50;
motor_delay(2);
P3 = 0x90;
motor_delay(2);
P3 = 0xA0;
motor_delay(2);
P3 = 0x60;
motor_delay(2);
}
else if(SW2 == 0)
{
P3 = 0x60;
motor_delay(2);
P3 = 0xA0;
motor_delay(2);
P3 = 0x90;
motor_delay(2);
P3 = 0x50;
motor_delay(2);
}
}
}
for (secd=0;secd<=sec;secd++)
for(i=0;i<=4;i++)
for (j= 0;j<=800;j++)
- 54 -
{
}
}
Result:
1. Connector the jumpers at the stepper motor driver IC.
2. Connect the switch pins to the port pins selected.
3. Connect the Stepper motor to the available pins beside the serial port.
- 55 -
EXPERIMENT – 8
Develop necessary interfacing circuit to read data from i) temperature sensor and process using 89c51
sdk, the data has to display terminal window
Aim:
Write a program to read data from temperature sensor and display the temperature value.
Equipment Requirements:
Hardware Requirements:
- 56 -
Source code:
/*Program to get analog input from Temperature sensor and display the temperature value on PC
Monitor.*/
void Delay(int a)
- 57 -
{
char i;
for(i=0;i<a;i++)
{
LCD_delay(250);
LCD_delay(250);
}
}
void serial_init()
{
= 0x20; /* GATE OFF,C/#T = 0, M1 M0 = 10(8 BIT AUTO RELOAD)
TIMER 0 ,TIMER 1 IN 2(AUTO RELOAD MODE)*/
void PowerOn( )
{
unsigned char inner, outer;
LCD_init();
void main()
{
P0=0xFF;
P1=0x04;
PowerOn();
while(1)
{
- 58 -
LCD_clear();
LCD_row1();
LCD_puts("Temperature sensor ");
DisplayMesPC("\r\nTemparature Value : ");
conv(); //Start conversion
read(); //Read ADC
display(); //Send the read value PC and LCD
Delay(4);
}
}
void conv()
{
wr = 0; //Make WR low
wr = 1; //Make WR high
while(intr); //Wait for INTR to go low
}
void read()
{
rd = 0; //Make RD low
adc_val = P0; //Read ADC port
rd = 1; //Make RD high
}
void display()
{ // display the adc vvalue in the form of milli volts
LCD_row2();
LCD_puts(" Temp :");
value=adc_val;
value=value*196; //since resolution is 5V/255=19.6mv
value=value/100; // 10 division by 196 instead 19.6 another 10 is 1*
corresponds 10mv
if(value>=1000)
{
temp=value/1000;
adc_val=temp+48;
LCD_putc(adc_val);
SendChar(adc_val);
}
temp1=value%1000;
if(temp1>=100&&temp1<=999){
temp=temp1;
- 59 -
temp=temp/100;
adc_val=temp+48;
LCD_putc(adc_val);
SendChar(adc_val);
}
Else
{
LCD_putc('0');
SendChar('0');
}
temp2=temp1%100;
if(temp2>=10&&temp2<=99)
{
temp=temp2;
temp=temp/10;
adc_val=temp+48;
LCD_putc(adc_val);
SendChar(adc_val);
}
else
{
LCD_putc('0');
SendChar('0');
}
temp3=temp2%10;
if(temp3>0&&temp3<10){
temp=temp3;
adc_val=temp+48;
LCD_putc(adc_val);
SendChar(adc_val);
}
else {
LCD_putc('0');
SendChar('0');
}
LCD_putc(0XDF);
SendChar('*');
SendChar(' ');
SendChar('C');
LCD_putc('*');
LCD_putc('C');
}
- 60 -
{
SBUF =x; // wrting the character into the serial buffer
TI = 0; // Clearing the Transmit empty flag
while(!TI); // wating for end of trasmission. after transmission the TI flag will set.
}
Hardware configuration:
To test the board Power supply cable should be connected to the Board and serial cable must be
connected to
the computer. The Data line of the ADC is connected to the P0 of microcontroller. The RD, WR, INTR
(J32)
signals are connected to the P1.0, P1.1, P1.2 respectively. The Jumper should be connected at J22. To
Connect
Temperature sensor to ADC input Connect J22 1&2 (Temp sensor) with jumper
The temperature is displayed in LCD and same thing displayed on the PC.
RESULTS:
To check the output connect the hardware as shown above diagram, increase the temperature on
the sensor side then we will see the variation on sensor data on both HyperTerminal and lcd.
- 61 -
EXPERIMENT –9
Write a Program to
Port RTOS on to 89V51 Microcontroller and verify. Run 2 to 3 tasks simultaneously on 89V51
SDK. Use LCD interface, LED interface, Serial communication.
Aim:
Write an Embedded C program to sort RTOS on to 89V51 Microcontroller and verify. Run 2
to 3 tasks simultaneously on P89V51RD2.Use LCD interface, LED interface, Serial communication.
Equipment Requirements:
Hardware Requirements:
Hard: A late response is incorrect and implies a system failure. An example of such a system is of
medical equipment monitoring vital functions of a human body, where a late response would be
considered as a failure.
Soft: Timeliness requirements are defined by using an average response e time. If a single
computation is late, it is not usually significant, although repeated late computation can result in
system failures. An example of such a system includes airlines reservation systems.
- 62 -
Firm: This is a combination of both hard and soft timeliness requirements. The computation has a
shorter soft requirement and a longer hard requirement. For example, a patient ventilator must
mechanically ventilate the patient a certain amount in a given time period. A few seconds' delay in the
initiation of breath is allowed, but not more than that.
Experimental procedure:
Open the keil IDE and do the same procedure like create new project and build the application.
Then open Flash magic and download the hex file. Please refer the above experimental procedure for
keil4 IDE. In this RTOS experiment we have to do few more settings for creating new project (if you
want to create new project then only do these settings),just follow the settings as below mentioned.
After creating new project file go to target and do these settings: SELECT TARGET and right
click on target settings and select RAM size is 0X0000 to 0X1000.Again go to settings and select C51
and select LEVEL 9. And do the below
Source code:
#include "rtos.h"
#include"uart.h"
#include"lcd.h"
void PowerOn()
{
unsigned char inner, outer;
LCD_init();
for (inner = 0; inner < 10; inner++)
LCD_delay(2);
serial_init();
}
- 63 -
void LED_TASK()
{
while(1) {
k_acquire(&mut);
k_yield();
if(task_time_counter1==20){
task_time_counter1=0;
LED1=LED1 ^ 1;
DisplayMesPC("\r\nLED Task Running");
}
task_time_counter1++;
k_release(&mut);
k_yield();
}
}
void LCD_TASK() {
unsigned char counter=0;
LCD_clear();
LCD_row1(); LCD_puts("LCD Task Running");
LCD_row2();
while(1) {
k_acquire(&mut);
k_yield();
if(task_time_counter2==5){
LCD_putc(counter+48);
counter++;
LED3=LED3 ^ 1;
task_time_counter2=0;
DisplayMesPC("\r\nLCD Task Running");
if(counter>15){
counter=0;
LCD_row2();
LCD_puts(" ");
LCD_row2();
}
}
task_time_counter2++;
k_release(&mut);
k_yield();
}
- 64 -
}
void UART_TASK() {
while(1) {
k_acquire(&mut);
k_yield();
if(task_time_counter3==10){
task_time_counter3=0;
LED2=LED2 ^ 1;
DisplayMesPC("\r\nUART Task Running");
}
task_time_counter3++;
k_release(&mut);
k_yield();
}
}
void main()
{
P0=0x00;
PowerOn();
DisplayMesPC("\r\nRTOS For 8051 Microcontroller");
k_create_mutex(&mut);
k_task_create(LED_TASK, "a", 1);
k_task_create(LCD_TASK, "b", 1);
k_task_create(UART_TASK, "c", 1);
k_start();
Hardware configuration:
- 65 -
To test the board
Power supply cable should be connected to the M7 Board and serial cable must be
connected to the computer.
Jumpers should be connected to J39[LED‘s],JP3 and J6[LCD]. To check the output just reset the board
and give proper connections and check the output on LCD , LED and on hyperterminal. H ere we are
assigned three leds for 3 tasks one led for led,second one for lcd and third one for UART. There you can
observe the the task time on each and every led.
- 66 -
Result
You can find on LCD display data and led blinks and UART data displayed this
terminal like this.
- 67 -
EXPERIMENT-10
Analog to Digital Converter unit (ADC 0809)
AIM: Write a program to develop analog to digital converter using 89C51 board.
{
- 71 -
SDA = dat & 0x80;
dat=dat<<1;
SCLK = HIGH;
Delay_Time();
SCLK = LOW;
}
SDA=HIGH;
Delay_Time();
SCLK = HIGH;
Delay_Time();
ACK = SDA;
Delay_Time();
SCLK = LOW;
}
unsigned char I2C_Read(void) //reading from i2c device bit by bit
{
unsigned char i,j;
j = 0;
i = SDA;
for(i=0;i<8;i++)
{
j<<=1;
SCLK = HIGH;
j |= SDA;
Delay_Time();
SCLK = LOW;
}
Delay_Time();
SDA = LOW;
Delay_Time();
SCLK = HIGH;
Delay_Time();
SCLK = LOW;
Delay_Time();
SDA = HIGH;
return j;
}
void main()
{
unsigned int i=0x00;
I2C_Start();
I2C_Write(0x9E); //send device address
I2C_Write(0x40); //send device's control register address
I2C_Start();
I2C_Write(0x9E); // send command for read
while(1)
{
- 72 -
if((swt & 0x1f)== 0x1E)
{
i=i+0x0a;
if(i>0xff)
i=0x00;
I2C_Write(i);
Delay_Time();
}
}
}
void Delay_Time()
{
unsigned int i;
for(i=0;i<=5000;i++);
}
- 73 -
EXPERIMENT-11
Aim:
Program to interface DAC device with P89V51RD2 and observer the analog output in CRO.
- 74 -
Hardware Connection
- 75 -
Actual Connection
Code
#include<reg51.h> //Header file for 8051 void main() // Start of main() function
{
P1 = 0x00; // Initialize Port 1 as Output
while(1) // Infinite Loop
{
do // 1st do-while for upward portion of //triangular wave
{
P1 += 0x05; // Increment P1 to get upward portion
}
while(P1<0xFF); // stop loop after reaching max value do // 2nd do-while for
downward portion of //triangular wave
{
P1 -= 0x05; // Decrement P1to get downward portion
}
while(P1>0x00); // stop loop after reaching lowest value
}
}
Expected Output
- 76 -
EXPERIMENT- 12
Program :
#include<reg51.h>
void main(void)
P0=0x09;
cur=P0;
while(1)
{ P1=0x02;
req=P1;
if(cur==req)
P0=F[req];
else if(req>cur)
for(i=cur;i<=req;i++)
{ P0=F[i];
for(j=0;j<250;j++);
- 76 -
}
else
for(i=cur;i>=req;i--)
{ P0=F[i];
for(j=0;j<250;j++);
} cur=req; P0=F[cur];
Interfacing Model:
- 78 -
Result: Elevator is interfaced with 8051 microcontroller.
- 79 -
TEXT BOOKS:
REFERENCES:
Web References:
1. https://www.cadsoftusa.com/download-eagle/freeware/
2. http://www.dauniv.ac.in/downloads/EmbsysRevEd_PPTs/Chap01Lesson_1Emsys.pdf
3. http://en.wikipedia.org/wiki/Embedded_system
4. http://www.atmel.in/Images/MCU_vs_MPU_Article.pdf
5. http://maxembedded.com/2011/06/05/mcu-vs-mpu/
6. http://www.cadsoft.de/wp-content/uploads/2011/05/V6_tutorial_en.pdf 6.
7. http://www.mikrocontroller.net/attachment/17909/Protel_99_SE_Traning_Manual_P
CB_ Desi gn.pdf
- 80 -