Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Assignment Previous Year Question Papers (B. Tech.

2018-19)

Lab File: Embedded System & Design Lab (6CS10A)


Experiment #0
Get familiar with the microcontroller kit and the development software. Try the
sample programs that are supplied to get familiar with the Microcontroller.

Experiment #1
Blink an LED which is connected to your microcontroller using the built-in
timer in the microcontroller.

Program:

#include<reg51.h>
sbit led=P1^0;
unsigned int i=0;
void delay(){
TMOD = 0x01; // Timer0 mode1
TH0 = 0xFC; //initial value for 1ms
TL0 = 0x66;
TR0 = 1; // timer start
while(TF0==0); // check overflow condition
TR0 = 0; // Stop Timer
TF0 = 0; // Clear flag
}
void main()
{
while(1)
{
led = 1;
for(i=0;i<1000;i++)
{ delay();
}
led = 0;
for(i=0;i<1000;i++)
{
delay();
}}}

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

Experiment #2
Consider an alternate way to program this application. Here, the microcontroller turns the LED on and
waits in a busy loop to implement a delay of x milliseconds.
Program:
#include <REGX51.H>
void delay(unsigned int d)//define delay
{
unsigned int i;
for (i=0;1<d;i++)
{ }
}
void main()// main program starting
{
P1 = 0x00;//initilise P1 as all zeros
while(1)// while loop to run program all time
{
P1_0 = 0;//set pin P1.0 as zero
delay(1000);//calling delay function
P1_0 = 1;//set pin P1.0 as one
delay(1000);//calling delay function
}}

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

Experiment #3
If your microcontroller kit has an LCD interface, write a program to display a character string on the
LCD. Assume that the string is stored at a location STRING and consists of alphanumeric characters.
The string is nullterminated. Modify your program to scroll the displayed string from left to right.

Program:
#include<regx51.h>
#include<lcd.h>
unsigned int i;
void delay(unsigned int d)
{
for(i=0;i<d;i++);
}
void main()
{
InitLCD();
while(1)
{
ClearLCDScreen();
WriteStringToLCD("Aravali Institute Of technical Studies");
delay(10000);
}
}

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

Experiment #4
use microcontrollers to generate voltage waveforms such as (a) pulse train (b) triangular waveform.
Observe these waveforms on an oscilloscope.
a) Program:
#include<regx51.h>
void delay()
{
unsigned char i;
TMOD= 0x10;
for (i=0;i<14;i++)
{
TH1 = 0x00;
TL1 = 0x00;
TR1 = 1;
while(TF1 ==0);
TF1 = 0;
}
}

void main()
{
while(1){
P1_0 = 1;
delay();
P1_0 = 0;
delay();
}
}

b) Program:

#include<regx51.h>
void main()
{
unsigned char i = 0;
while(1){
for (i = 0;i<0xff;i++)

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

{
P1 = i;
}
for (i = 0;i<0x00;i++)
{
P1 = i;
}
}
}

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

Experiment #5
When the LED blinking program runs, pressing a key should generate an interrupt to the
microcontroller. If the key that has been pressed then the LED must be turned off for 2 seconds before

#include<regx51.h>
sbit sw = P3^2;
unsigned int i;
void delay(unsigned int d)
{for(i=0;i<d;i++);
}
void main()
{
P1 = 0xFF;
EA=1;
EX0=1;
IT0=1;
while(1)
{
P1 = 0xFF;
}
}

void isssr(void) interrupt 0


{
P1_0 = 0;
P1_1 = 1;
delay(20000);
P1_0 = 1;
P1_1 = 0;
delay(60000);

}
ARAVALI INSTITUTE OF TECHNICAL STUDIES
Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

Experiment #6
Your microcontroller may have a built-in temperature sensor. If not, interface an external temperature
sensor to the microcontroller. Write a program to take several measurements of temperature at regular
intervals and display the average temperature on the LCD display. Test if the readings change when the
ambient temperature changes.

Program:
#include <reg51.h>
#define input P1;
double newtemp,pass1,pass2,T; //variables used
//LCD
sbit rs = P3^0; //register select pin
sbit rw = P3^1; //read write pin
sbit e = P3^2; //enable pin
//ADC
sbit rd=P3^7; //defines rd pin of ADC use for reading purposes
sbit wr=P3^6; // define wr pin of ADC use for writing purposes
sbit intr=P3^4; //defines intr pin use for sending interrupts from microcontroller
void delay(unsigned int time) //Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
double adc() // Function to read the values from ADC and send to controller.
{
double temp;
rd=1;
wr=0;
delay(1);
wr=1;
while(intr==1);
{rd=0;
temp=input;
delay(3);}
return temp;
}

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

void lcdcmd(unsigned char item) //Function to send commands to LCD see command tables in LCD
Link
{
P2 = item;
rs= 0;
rw=0;
e=1; //send to high to low pulse while writing
delay(1);
e=0;
}
void lcddata(double item) //Function to send data to LCD
{
P2 = item;
rs= 1;
rw=0;
e=1; //send high to low pulse while writing
delay(1);
e=0;
}
void disp_temp(double num) //displays number on LCD
{
unsigned char UnitDigit = 0; //It will contain unit digit of number
unsigned char TenthDigit = 0; //It will contain 10th position digit of number
unsigned char HundDigit = 0; //It will contain 100th position digit of number
unsigned char decimal=0; //It will contain the decimal position of number
int point;
point=num*10;
HundDigit=(num/100);
if( HundDigit != 0) // If it is zero, then don't display
lcddata(HundDigit+0x30); // Make Character of HundDigit and then display it on LCD
TenthDigit = num - HundDigit*100; // Findout Tenth Digit
TenthDigit = TenthDigit/10;
if (HundDigit==0 && TenthDigit==0){} // If it is zero, then don't display
else
lcddata(TenthDigit+0x30); // Make Char of TenthDigit and then display it on LCD
UnitDigit = num - HundDigit*100;
UnitDigit = UnitDigit - TenthDigit*10;

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

lcddata(UnitDigit+0x30); // Make Char of UnitDigit and then display it on LCD


lcddata('.');
decimal=(point%10);
lcddata (decimal+0x30); // Make Char of Decimal Digit and then display it on LCD
lcddata(' '); lcddata('C');
}
void read(){ // Displays "READING" while controller reads from ADC
lcdcmd(0x0E); //turn display ON for cursor blinking
lcdcmd(0x01); //clear screen
lcdcmd(0x06); //increment cursor
lcddata('R');lcddata('E');lcddata('A');lcddata('D');lcddata('I');lcddata('N');lcddata('G');lcddata(' ');
}
void main()
{
P0=0x00; //intialize port 0 to low use while controller reads the temperature
from
//ADC
read(); // show reading on LCD while controller reads from ADC
while(1){ // use for checking errors while reading the value from ADC
newtemp=adc(); //reads first value from ADC
delay(60); //waits 60 msec
pass1=adc(); // reads the Second value from ADC
delay(60); // waits 60 msec
if (newtemp==pass1){ //compare first and second value
break; // if first and second value is same breaks the loop
}
}
while(1){ //enters in the permanent loop
T=160; //set reference voltage acting multiplier factor for temperature accuration
newtemp=(((newtemp*T)/255)); //converts the temperature value according to reference adjusted in
decimal
lcdcmd(0x0E); //turn display ON for cursor blinking
lcdcmd(0x01); //clear screen
lcdcmd(0x06); //increment
disp_temp(newtemp); //show temperature
delay(300); //waits 3sec before re-measure the value of temperature

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

while(1){ // re-measure the value from ADC but this time double check
newtemp=adc();
delay(60);
pass1=adc();
delay(60);
pass2=adc();
if (newtemp==pass1){
if(pass1==pass2){
break; }
}
}
// end ADC while loo[
} // end while permanent loop
} // end main loop

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

Experiment #7
Your microcontroller may have a built-in ADC. Build a voltmeter that can measure stable voltages in a
certain range. The measured value must be displayed on the LCD display. Measure the same voltage
using a multimeter and record the error in measurement. Tabulate the error for several values of the
voltage.
Program:
#include <REGX51.H>
#include "lcd.h"
#define adc_port P1 //ADC Port
#define rd P3_7 //Read signal P3.7
#define wr P3_6 //Write signal P3.6
#define cs P3_5 //Chip Select P3.5
#define intr P3_4 //INTR signal P3.4

void conv(); //Start of conversion function


void read(); //Read ADC function

unsigned int adc_avg,adc;

void main(){
char i;
LCD_INI();
while(1){ //Forever loop
adc_avg = 0;
for(i=0;i<10;i++){
conv(); //Start conversion
read(); //Read ADC
adc_avg += adc;
}
adc_avg = adc_avg/10;
wrt_cmd(0x80);
wrt_string("V(DC): ");
adc = adc_avg * 59;

hex2lcd((unsigned char)(adc/1000));
wrt_data('.');
adc = adc%1000;

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

hex2lcd((unsigned char)(adc/10));

wrt_data('V');
}
}

void conv(){
cs = 0; //Make CS low
wr = 0; //Make WR low
wr = 1; //Make WR high
cs = 1; //Make CS high
while(intr); //Wait for INTR to go low
}

void read(){
cs = 0; //Make CS low
rd = 0; //Make RD low
adc = adc_port; //Read ADC port
rd = 1; //Make RD high
cs = 1; //Make CS high
}

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

Experiment #8
Wite a program do display numbers from 0 to 9 using 7 segment display and 8051
microcontroller.
Program:

#include<regx51.h>

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

unsigned int i;
void delay(unsigned int d)
{
for(i=0;i<d;i++);
}
void main()
{
while(1)
{
P1=0x3F;
delay(500000);
P1=0x06;
delay(500000);
P1=0x5B;
delay(500000);
P1=0x4F;
delay(500000);
P1=0x66;
delay(500000);
P1=0x6D;
delay(500000);
P1=0x7D;
delay(500000);
P1=0x07;
delay(500000);
P1=0x7F;
delay(500000);
P1=0x67;
delay(500000);
}
}

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

Appendix lcd.h file for Exp =7(voltmeter)


#include "lcd.h"
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**** Cheacking the busy flag of LCD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void busy()
{
flag=1;

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

rs=0;
rw=1;
while(flag!=0)
{
en=0;
en=1;
}}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**** Writing command to LCD ****
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void wrt_cmd(unsigned char val_lcd)
{
busy();
lcd_port=val_lcd;
rs=0;
rw=0;
en=1;
en=0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~
**** Writing data on LCD ****
~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void wrt_data(unsigned char dat)
{
busy();
lcd_port=dat;
rs=1;
rw=0;
en=1;
en=0;
}

void wrt_string(unsigned char *string)


{
while(*string)
wrt_data(*string++);
}

void LCD_INI(void)
{
wrt_cmd(0X30);
wrt_cmd(0X0C);
wrt_cmd(0X01);
ARAVALI INSTITUTE OF TECHNICAL STUDIES
Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat
Assignment Previous Year Question Papers (B. Tech. 2018-19)

wrt_cmd(0X06);
}

void hex2lcd(unsigned char hex){


char temp1,temp2;
temp1 = hex;
temp2=0;
do{
temp1 = temp1-100;
if(temp1>=0)
temp2++;
} while(temp1>=0);
if(temp2>0)
wrt_data(temp2+0x30);
temp2=0;
temp1 = temp1+100;
do{
temp1 = temp1-10;
if(temp1>=0)
temp2++;
} while(temp1>=0);
wrt_data(temp2+0x30);
temp2 = temp1+10;
wrt_data(temp2+0x30);
}

ARAVALI INSTITUTE OF TECHNICAL STUDIES


Umarda - 313015, Udaipur (Raj.) India. Tel.: +91-294-2650131-35, 9414164115, 9001895904
Email: info@aravalieducation.org, Web: www.aravalieducation.org

Suraj Prajapat

You might also like