SlideShare a Scribd company logo
1 of 67
8051 ASSIGNMENTS
1. WAP to Add, Sub, Mul, Div Two 8-bit Numbers?
2. WAP to Add, Sub, Mul, Div Two 8-bit Numbers Using Switch Case and place the
result on P2?
3. WAP to multiply two 8-bit Numbers using functions?
4. WAP to Add, Sub, Mul, Div Two 8-bit Numbers Using Switch Case and using
functions, call the Arithmetic Operations place the result on P2?
5. WAP to Get the ‘X’ value from P1 and send ‘X^2’ to P2, continuously?
6. WAP to add numbers from 1 to 10 and place the result on P1?
7. WAP to find a factorial of a number (input from P1 and continuously read input from
P1) and place the result on P2?
8. WAP to blink Port pins of P1 (infinite times) using time delay?
9. WAP to blink alternate Port pins of P1 (infinite times) using time delay?
10. WAP to find a factorial of a number (input from P1 and continuously read input from
P1) and place the result on P2 Using Functions?
(1)
ADD SUB
unsigned char a,b,c; unsigned char a,b,c;
a=10,b=5; a=10,b=5;
c=a + b; c=a-b;
P1=c; P1=c;
MUL DIV
unsigned char a,b,c; unsigned char a,b,c;
a=10,b=5; a=10,b=5;
c=a*b; c=a/b;
P1=c; P1=c;
(2)
while(1)
{
x=P1;
switch(x)
{
case 0x01 : P2=a + b; break;
case 0x02 : P2=a-b; break;
case 0x03 : P2=a*b; break;
case 0x04 : P2=a/b; break;
default : break;
}
}
(3)
void mul (unsigned char, unsigned char);
main()
{
mul(a , b);
}
void mul (unsigned char a, unsigned char b)
{
P2=a*b;
}
(4)
void add(unsigned char , unsigned char);
void sub(unsigned char , unsigned char);
void mul(unsigned char , unsigned char);
void div(unsigned char , unsigned char);
while(1)
{
x=P1;
switch(x)
{
case 0x01 : add(a, b); break;
case 0x02 : sub(a, b); break;
case 0x03 : mul(a, b); break;
case 0x04 : div(a, b); break;
default : break;
}
}
void add(unsigned char a , unsigned char b)
{
P2=a + b;
}
void sub(unsigned char a , unsigned char b)
{
P2=a-b;
}
void mul(unsigned char a , unsigned char b)
{
P2=a*b;
}
void div(unsigned char a , unsigned char b)
{
P2=a/b;
}
(5)
while(1)
{
x=P1;
P2=x*x;
}
(6)
unsigned char i,n=0;
for(i=1;i<=10;i++)
{
n=n+i;
}
P1=n;
(7)
while(1)
{
n=P1;
x=1;
for( i=1;i<=n;i++)
{
x=x*i;
}
P2=x;
}
8051 ASSIGNMENTS
1. WAP to send values 00-FF to port P1?
2. WAP to send Hex values for ASCII characters of 0,1,2,3,4,5,A,B,C, and D
to port P1?
3. WAP to toggle all the bits of P0,P1, and P2 continuously with some time
delay. Use the sfr keyword to declare the port addresses?
4. WAP to perform logical operations and send result to ports P0,P1, and P2?
5. WAP to convert packed BCD 0x29 to ASCII and display the bytes on P1 and
P2?
6. WAP to convert ASCII digits of ‘4’ and ‘7’ to packed BCD and display
them on P1?
7. WAP to convert FD (hex value) to Decimal and display the digits on P0,P1,
and P2?
8. WAP to Add Two 16 bit numbers in Assembly?
9. WAP to find number of 1s and 0s in given byte in Assembly?
10. WAP to generate a Fibonacci series up to 10 numbers and store the series
from 40H Location in Assembly?
(1)
void Delay(unsigned int);
unsigned char i;
for(i=0;i<=255;i++)
{
P1 = i;
Delay(1000);
}
void Delay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i < itime; i++)
for(j=0;j<2000;j++);
}
(2)
void Delay(unsigned int);
unsigned char num[]="012345ABCD";
unsigned char i;
for(i=0;i<=10;i++)
{
P1 = num[i];
Delay(2000);
}
void Delay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i < itime; i++)
for(j=0;j<4000;j++);
}
(3)
sfr P0 = 0x80;
sfr P1 = 0x90;
sfr P2 = 0xA0;
void Delay(unsigned int);
while(1)
{
P0=0x55;
P1=0x55;
P2=0x55;
Delay(250);
P0=0xAA;
P1=0xAA;
P2=0xAA;
Delay(250);
}
(4)
void Delay(unsigned int);
------------
P0 = 0x35 & 0x0F;
P1 = 0x04 | 0x68;
P2 = 0x54 ^ 0x78;
Delay(9000);
P0 = ~0x55;
P1 = 0x9A >> 3;
P2 = 0x77 >> 4;
Delay(9000);
P0 = 0x6 << 4;
----------
void Delay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i< itime; i++)
for(j=0;j<5000;j++);
}
(5)
unsigned char x , y;
unsigned char mybyte = 0x29;
x = mybyte & 0x0F;
P1 = x | 0x30;
y = mybyte & 0xF0;
y = y >> 4;
P2 = y | 0x30;
(6)
unsigned char bcdbyte;
unsigned char x='4',y='7';
x = x & 0x0F;
x = x << 4;
y = y & 0x0F;
bcdbyte = x | y;
P1 = bcdbyte;
(7)
unsigned char hex=0xFD,temp,d1,d2,d3;
temp = hex / 10;
d1 = hex % 10;
d2 = temp % 10;
d3 = temp / 10;
P0 = d1;
P1 = d2;
P2 = d3;
(9)
ORG 0000H
CLR C
MOV R1,#0
MOV R2,#0
MOV R3,#8
MOV A,#97H
L1: RLC A
JNC L2
INC R1
L2: JC L3
INC R2
L3: DJNZ R3,L1
END
(10)
ORG 0000H
MOV R0,#10
MOV R1,#40H
MOV A,#1
MOV R3,#0
BACK: ADD A,R3
XCH A,R3
MOV @R1,A
INC R1
DJNZ R0,BACK
END
8051 ASSIGNMENTS
1. WAP to toggle alternate bits of port P1 continuously with some
delay in between. Use Timer 0, 16-bit mode to generate the delay?
2. WAP to toggle only one bit P1.5 continuously for every 50ms. Use
Timer 0, mode 1 (16-bit) to create the delay?
3. WAP to toggle alternate bits of port P2 continuously for every
500ms. Use Timer 1, mode 1 to create the delay?
4. WAP to create frequency of 2500Hz on pin P2.5. Use Timer 1,
mode 2 to create the delay?
5. WAP to generate a square wave of 2KHz frequency on pin P1.5?
6. WAP to generate a square wave of 50Hz frequency on pin P2.5?
7. WAP to find a largest number in an array (in Assembly)?
8. WAP to find a smallest number in an array (in Assembly)?
9. WAP for Ascending Order (in Assembly)?
10. WAP for Descending Order (in Assembly)?
(1)
void T0Delay();
while(1)
{
P1 = 0x55;
T0Delay();
P1 = 0xAA;
T0Delay();
}
void T0Delay()
{
TMOD = 0x01;
TL0 = 0x00;
TH0 = 0x35;
TR0 = 1;
while(TF0==0);
TR0 = 0;
TF0 = 0;
}
(2)
void T0M1Delay();
while(1)
{
P1_5 = ~P1_5;
T0M1Delay();
}
void T0M1Delay()
{
TMOD = 0x01;
TL0 = 0xFD;
TH0 = 0x4B;
TR0 = 1;
while(TF0==0);
TR0 = 0;
TF0 = 0;
}
(3)
void T1M1Delay();
unsigned char i;
P2 = 0x55;
while(1)
{
P2 = ~P2;
for(i=0;i<20;i++)
T1M1Delay();
}
void T1M1Delay()
{
TMOD = 0x10;
TL1 = 0xFE;
TH1 = 0xA5;
TR1 = 1;
while(TF1==0);
TR1 = 0;
TF1 = 0;
}
(4)
void T1M2Delay();
while(1)
{
P2_5 = ~P2_5;
T1M2Delay();
}
void T1M2Delay()
{
TMOD = 0x20;
TH1 = -184;
TR1 = 1;
while(TF1==0);
TR1 = 0;
TF1 = 0;
}
(5)
void T1M1Delay();
while(1)
{
P1_5 = ~P1_5;
T1M1Delay();
}
void T1M1Delay()
{
TMOD = 0x10;
TL1 = 0x1A;
TH1 = 0xFF;
TR1 = 1;
while(TF1==0);
TR1 = 0;
TF1 = 0;
}
(6)
void T1M1Delay();
while(1)
{
P2_5 = ~P2_5;
T1M1Delay();
}
void T1M1Delay()
{
TMOD = 0x10;
TL1 = 0x00;
TH1 = 0xDC;
TR1 = 1;
while(TF1==0);
TR1 = 0;
TF1 = 0;
}
(7)
ORG 0000H
MOV R1,#50H
MOV R2,#05H
MOV 40H,#00H
L2: MOV A,@R1
CJNE A,40H,L1
L3: INC R1
DJNZ R2,L2
MOV A,40H
MOV R3,A
SJMP $
L1: JC L3
MOV 40H,A
SJMP L3
END
(8)
ORG 0000H
MOV R1,#50H
MOV R2,#05H
MOV A,@R1
MOV 40H,A
L2: CJNE A,40H,L1
L3: INC R1
MOV A,@R1
DJNZ R2,L2
MOV A,40H
MOV R3,A
SJMP $
L1: JNC L3
MOV 40H,A
SJMP L3
END
(9)
ORG 0000H
MOV R1,#50H
MOV R2,#05H
MOV 30H,#04H
MOV B,#50H
L3: MOV A,@R1
MOV 40H,A
L2: MOV A,@R1
CJNE A,40H,L1
L4: INC R1
DJNZ R2,L2
INC B
MOV R1,B
MOV R2,30H
DJNZ 30H,L3
SJMP $
L1: JNC L4
XCH A,40H
MOV @R1,A
MOV A,40H
PUSH 01H
MOV R1,B
MOV @R1,A
POP 01H
SJMP L4
END
(10)
ORG 0000H
MOV R1,#50H
MOV R2,#05H
MOV 30H,#04H
MOV B,#50H
L3: MOV A,@R1
MOV 40H,A
L2: MOV A,@R1
CJNE A,40H,L1
L4: INC R1
DJNZ R2,L2
INC B
MOV R1,B
MOV R2,30H
DJNZ 30H,L3
SJMP $
L1: JC L4
XCH A,40H
MOV @R1,A
MOV A,40H
PUSH 01H
MOV R1,B
MOV @R1,A
POP 01H
SJMP L4
END
8051 ASSIGNMENTS
1. WAP to transfer the letter “A” serially at 4800 Baud Rate
continuously. Use serial communication mode 1?
2. WAP to transfer the word “CBIT” at 9600 Baud Rate
continuously. Use serial communication mode 1?
3. WAP to receive bytes of data serially and put them in P1. Set
the Baud Rate at 4800. Use serial communication mode 1?
4. WAP to send two different strings to the serial port .Assuming
that SW is connected to pin P2.0, monitor its status and make
decision as follows:-
(i) SW = 0: send your first name,
(ii) SW= 1: send your last name. Use serial communication
mode 1?
5. WAP to send the two messages “Normal Speed” and “High
Speed” to the serial port. Assuming that SW is connected to
pin P2.0, monitor its status and set the baud rate as follows:-
(i) SW = 0: 28,800 baud rate,
(ii) SW= 1: 56K baud rate. Use serial
communication mode 1?
8051 ASSIGNMENTS
1. WAP to read the KeyBoard and send it to the serial port. Use
baud rate 9600?
2. Write the above program in Assembly
3. WAP to get data from P2 and send it to P1, while simultaneously
creating a square wave of 200us period on pin P0.5. Use timer 0
mode 2 to create the square wave?
4. WAP to get data from P2 and send it to P1, while simultaneously
creating,
(i) Square wave of 200us period on pin P0.5,
(ii) Sending a letter ‘A’ to the serial port. Use timer 0 mode 2 to
create the square wave and use 9600 baud rate?
5. WAP using interrupts to do the following :-
(a) Receive data serially and send it to P0,
(b) Read port P1,transmit data serially, and give a copy to P2.
(c) Make timer 0 mode 2 generate a square wave of 5KHz
frequency on pin P0.5. Set baud rate at 4800.
(1)
TMOD = 0x20;
TH1 = 0xFA;
SCON = 0x50;
TR1 = 1;
while(1)
{
SBUF = 'A';
while(TI == 0);
TI = 0;
}
(2)
void SerTx (unsigned char);
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while(1)
{
SerTx('C');
SerTx('B');
SerTx('I');
SerTx('T');
}
void SerTx (unsigned char ch)
{
SBUF = ch;
while(TI == 0);
TI = 0;
}
(3)
unsigned char ch;
TMOD = 0x20;
TH1 = 0xFA;
SCON = 0x50;
TR1 = 1;
while(1)
{
while(RI == 0);
ch = SBUF;
P1 = ch;
RI = 0;
}
(4)
#define SW P2_0
unsigned char i;
unsigned char fname[] = "CBIT";
unsigned char lname[] = "College";
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
(4)
if(SW == 0)
{
for(i=0;i<4;i++)
{
SBUF = fname[i];
while(TI == 0);
TI = 0;
}
}
else
{
for(i=0;i<7;i++)
{
SBUF = lname[i];
while(TI == 0);
TI = 0;
}
}
while(1);
(5)
#define SW P2_0
unsigned char i;
unsigned char Mesg1[] = "Normal Speed";
unsigned char Mesg2[] = "High Speed";
TMOD = 0x20;
TH1 = 0xFF;
SCON = 0x50;
TR1 = 1;
(5)
if(SW == 0)
{
for(i=0;i<12;i++)
{
SBUF = Mesg1[i];
while(TI == 0);
TI = 0;
}
}
else
{
PCON = PCON | 0x80;
for(i=0;i<10;i++)
{
SBUF = Mesg2[i];
while(TI == 0);
TI = 0;
}
}
while(1);
#include <REG51.H>
main()
{
unsigned char byte;
TMOD=0x20;
TH1=0xFA;
SCON=0X50;
TR1=1;
while(1)
{
while(RI==0);
byte=SBUF;
RI=0;
SBUF=byte;
while(TI==0);
SBUF=byte;
TI=0;
}
}
6
(8)
void timer0() interrupt 1
{
P0_5 = ~P0_5;
}
main()
{
TMOD = 0x02;
TH1 = 0xA4;
IE = 0x82;
TR1 = 1;
while(1)
{
P1 = P2;
}
}
(9)
void timer0() interrupt 1
{
P0_5 = ~P0_5;
}
void serial() interrupt 4
{
IE = 0x82;
SBUF = 'A';
while(TI==0);
TI = 0;
RI = 0;
}
(9)
TMOD = 0x22;
TH1 = -3;
TH0 = 0xA4;
SCON = 0x50;
IE = 0x92;
TR = 1;
TR0 = 1;
while(1)
{
IE = 0x92;
P1 = P2;
}
(10)
void timer0() interrupt 1
{
P0_5 = ~P0_5;
}
void serial() interrupt 4
{
if(TI == 1)
{
TI = 0;
}
else
{
P0 = SBUF;
RI = 0;
}
}
(10)
unsigned char ch;
TMOD = 0x22;
TH1 = 0xF6;
TH0 = 0xA4;
SCON = 0x50;
IE = 0x92;
TR1 = 1;
TR0 = 1;
while(1)
{
ch = P1;
SBUF = ch;
P2 = ch;
}
8051 ASSIGNMENTS
1. WAP to enter user name and password it is correct print Access
granted otherwise print Access Denied, use serial communication.
Use 9600 baud rate?
2. WAP to blink Port pins of P2 (infinite times) using time delay and
execute on Proteus?
3. WAP to blink alternate Port pins of P2(infinite times) using time
delay and execute on Proteus?
4. WAP to display the single character on LCD and execute in Proteus?
5. WAP to display the single character on LCD and Scroll it
continuously and execute in proteus?
6. WAP to display the string on LCD and execute in Proteus?
7. WAP to display the string on LCD and Scroll it continuously and
execute in proteus?
8. WAP to read the Keyboard and display on serial port and LCD?
9. WAP to read the Keypad Key and display on LCD?
10. WAP to read the Keypad Key and display on LCD and also on serial
port?
(2)
#include <AT89X51.H>
void Delay(unsigned int);
main()
{
while(1)
{
P2=0x00;
Delay(250);
P2=0xFF;
Delay(250);
}
}
void Delay(unsigned int itime)
{
unsigned int i, j;
for(i=0; i< itime; i++)
for(j=0; j<1275; j++);
}
(4)
#include <AT89X51.H>
Delay(unsigned char itime)
{
unsigned char i, j;
for(i=0; i<itime ; i++)
for(j=0;j<255;j++);
}
lcd_cmd (unsigned char value)
{
P2=value;
P3_6=0;
P3_5=1;
Delay(50);
P3_5=0;
}
(4)
lcd_data (unsigned char ch)
{
P2=ch;
P3_6=1;
P3_5=1;
Delay(50);
P3_5=0;
}
main()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x0E);
lcd_cmd(0x06);
lcd_cmd(0x80);
lcd_data('A');
while(1);
}
(6)
#include <AT89X51.H>
Delay(unsigned char itime)
{
unsigned char i, j;
for(i=0; i<itime ; i++)
for(j=0;j<255;j++);
}
lcd_cmd(unsigned char value)
{
P2=value;
P3_6=0;
P3_5=1;
Delay(50);
P3_5=0;
}
(6)
lcd_data(unsigned char *str3)
{
while(*str3)
{
P2=*str3;
P3_6=1;
P3_5=1;
Delay(50);
P3_5=0;
str3++;
}
}
main()
{
unsigned char *str1="CBIT";
unsigned char *str2="COLLEGE";
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x0E);
lcd_cmd(0x06);
lcd_cmd(0x86);
lcd_data(str1);
lcd_cmd(0xc2);
lcd_data(str2);
while(1);
}
(9)
#include <AT89X51.H>
#define COLROW P1
unsigned char keypadMatrix [4][4]={"0123",
"4567",
"89AB",
“CDEF"};
//-----------------------LCD DELAY-----------------------//
Delay1(unsigned char itime)
{
unsigned char i, j;
for(i=0; i<itime; i++)
for(j=0;j<255;j++);
}
//-----------------------KEYPAD DELAY--------------------//
void Delay2(unsigned char itime)
{
unsigned int i, j;
for(i=0; i<itime; i++)
for(j=0;j<1257;j++);
}
(9)
//-------------------LCD COMMAND FUNCTION----------------//
lcd_cmd(unsigned char value)
{
P2=value; //LCD CONNECTED TO P2
P3_6=0; //REGISTER SELECT
P3_5=1; //ENABLE HIGH
Delay1(50);
P3_5=0; //ENABLE LOW
}
//-----------------------LCD DATA FUNCTION---------------//
lcd_data(unsigned char ch)
{
P2=ch; //LCD CONNECTED TO P2
P3_6=1; //REGISTER SELECT
P3_5=1; //ENABLE HIGH
Delay1(50);
P3_5=0; //ENABLE LOW
}
(9)
//----------------LCD INITIALISATION FUNCTION------------//
lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x0E);
lcd_cmd(0x06);
lcd_cmd(0x80);
}
(9)
//--------------------KEYPAD FUNCTION--------------------//
unsigned char keypad()
{
unsigned char key, ROW,COL;
do
{
COLROW = 0xF0;
COL = COLROW;
COL &= 0xF0;
}while(COL != 0xF0);
do
{
Delay2(20);
COL = COLROW;
COL &= 0xF0;
}while(COL == 0xF0);
(9)
COLROW = 0xFE;
COL = COLROW;
COL &= 0xF0;
if(COL != 0xF0)
{
ROW = 0;
goto FINDC;
}
COLROW = 0xFD;
COL = COLROW;
COL &= 0xF0;
if(COL != 0xF0)
{
ROW = 1;
goto FINDC;
}
COLROW = 0xFB;
COL = COLROW;
COL &= 0xF0;
if(COL != 0xF0)
{
ROW = 2;
goto FINDC;
}
COLROW = 0xF7;
COL = COLROW;
COL &= 0xF0;
ROW = 3;
(9)
FINDC:
if(COL == 0xE0)
key = keypadMatrix[ROW][0];
else if(COL == 0xD0)
key = keypadMatrix[ROW][1];
else if(COL == 0xB0)
key = keypadMatrix[ROW][2];
else
key = keypadMatrix[ROW][3];
return key;
}
//-----------------------MAIN PROGRAM-----------------------//
main()
{
unsigned char key;
lcd_init();
while(1)
{
key = keypad();
lcd_data(key);
}
}
//----------------------------------------------------------------------//
8051 ASSIGNMENTS
1. WAP to rotate stepper motor in clockwise and
execute in proteus?
2. WAP to rotate stepper motor in anticlockwise and
execute in proteus?
3. WAP to monitor the status of SW and perform the
following :-
(a) If SW = 0, the stepper motor rotates
clockwise.
(b) If SW = 1, the stepper motor rotates
anticlockwise, and execute in proteus?
4. WAP to rotate stepper motor in clockwise in
Assembly and execute in proteus?
5. WAP to ADC and Display on LCD and execute in
proteus?
(1)
#include <AT89X51.H>
void Delay(unsigned int itime)
{
unsigned int i, j;
for(i=0; i<itime; i++)
for(j=0;j<500;j++);
}
main()
{
while(1)
{
P2 = 0x09;
Delay(100);
P2 = 0x0C;
Delay(100);
P2 = 0x06;
Delay(100);
P2 = 0x03;
Delay(100);
}
}
(2)
#include <AT89X51.H>
void Delay(unsigned int itime)
{
unsigned int i, j;
for(i=0; i<itime; i++)
for(j=0;j<500;j++);
}
main()
{
while(1)
{
P2 = 0x03;
Delay(100);
P2 = 0x06;
Delay(100);
P2 = 0x0C;
Delay(100);
P2 = 0x09;
Delay(100);
}
}
(3)
#include <AT89X51.H>
#define SW P1_0
void Delay(unsigned int itime)
{
unsigned int i, j;
for(i=0; i<itime; i++)
for(j=0;j<1275;j++);
}
main()
{
while(1)
{
if(SW==0)
{
P2 = 0x09;
Delay(100);
P2 = 0x0C;
Delay(100);
P2 = 0x06;
Delay(100);
P2 = 0x03;
Delay(100);
}
(3)
else
{
P2 = 0x03;
Delay(100);
P2 = 0x06;
Delay(100);
P2 = 0x0C;
Delay(100);
P2 = 0x09;
Delay(100);
}
}
}
(4)
ORG 00H
MOV A,#99H
BACK: MOV P2,A
RR A
ACALL DELAY
SJMP BACK
DELAY:MOV R1,#100
H1:MOV R2,#255
H2:DJNZ R2,H2
DJNZ R1,H1
RET
END
(5)
#include <AT89X51.H>
//===============================================
#define ADC_0804_Data P1 //Pins 11(DB7)-18(DB0)
sbit Read = P3^2; //Pin 2
sbit Write = P3^3; //Pin 3
sbit Interrupt = P3^5; //Pin 5
unsigned char ADC_Value =0;
//===============================================
Delay(unsigned char itime)
{
unsigned char i, j;
for(i=0; i<itime; i++)
for(j=0;j<255;j++);
}
//===============================================
(5)
lcd_cmd(unsigned char cmd)
{
P2=cmd;
P3_6=0;
P3_7=1;
Delay(50);
P3_7=0;
}
//===============================================
lcd_print (unsigned char *str)
{
while(*str)
{
P2=*str;
P3_6=1;
P3_7=1;
Delay(50);
P3_7=0;
str++;
}
}
(5)
//===============================================
lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x0E);
lcd_cmd(0x06);
lcd_cmd(0x80);
}
//===============================================
unsigned char ADC_0804()
{
unsigned char i;
Read=1;
Write=0;
for(i=0;i<50;i++);
Write=1;
while(Interrupt==1);
Read=0;
ADC_Value=ADC_0804_Data;
return ADC_Value;
}
(5)
unsigned char * Hex2ASCII(unsigned char Hex)
{
unsigned char D[3],Temp;
Temp = Hex/10;
D[2] = Hex%10;
D[1] = Temp%10;
D[0] = Temp/10;
D[2] |= 0x30;
D[1] |= 0x30;
D[0] |= 0x30;
D[3] = '0';
return D;
}
main()
{
unsigned char *D;
lcd_init();
lcd_print("Temperature=");
while(1)
{
ADC_Value=ADC_0804();
D=Hex2ASCII(ADC_Value);
lcd_cmd(0x8C);
lcd_print(D);
}
}

More Related Content

Similar to 8051 C Assignments with all examples covered

8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED CAman Sharma
 
โครงงาน เครื่องคิดเลข
โครงงาน เครื่องคิดเลขโครงงาน เครื่องคิดเลข
โครงงาน เครื่องคิดเลขBung Lfkglialbmk
 
Chapter 7 8051 programming in c
Chapter 7  8051 programming in cChapter 7  8051 programming in c
Chapter 7 8051 programming in cAbdelrahman Elewah
 
Maicrocontroller lab basic experiments
Maicrocontroller lab basic experimentsMaicrocontroller lab basic experiments
Maicrocontroller lab basic experimentsnoorahamed tahasildar
 
Maicrocontroller lab basic experiments
Maicrocontroller lab basic experimentsMaicrocontroller lab basic experiments
Maicrocontroller lab basic experimentsNoor Tahasildar
 
Buy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineBuy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineTechnogroovy
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051logesh waran
 
Instruction 8.pptx
Instruction 8.pptxInstruction 8.pptx
Instruction 8.pptxHebaEng
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IOT Academy
 
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9Irfan Qadoos
 
PWM wave generator using microcontroller
 PWM wave generator using microcontroller  PWM wave generator using microcontroller
PWM wave generator using microcontroller Swapnil2515
 
8051 basic programming
8051 basic programming8051 basic programming
8051 basic programmingANJUSHA R
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent vijaydeepakg
 
Chp5 pic microcontroller instruction set copy
Chp5 pic microcontroller instruction set   copyChp5 pic microcontroller instruction set   copy
Chp5 pic microcontroller instruction set copymkazree
 
8085 paper-presentation
8085 paper-presentation8085 paper-presentation
8085 paper-presentationJiMs ChAcko
 
Temperature sensor with a led matrix display (arduino controlled)
Temperature sensor with a led matrix display (arduino controlled)Temperature sensor with a led matrix display (arduino controlled)
Temperature sensor with a led matrix display (arduino controlled)TechLeap
 
Microcontroller (8051) general and simple alp n cprograms
Microcontroller (8051) general and simple alp n cprogramsMicrocontroller (8051) general and simple alp n cprograms
Microcontroller (8051) general and simple alp n cprogramsVedavyas PBurli
 

Similar to 8051 C Assignments with all examples covered (20)

8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
 
โครงงาน เครื่องคิดเลข
โครงงาน เครื่องคิดเลขโครงงาน เครื่องคิดเลข
โครงงาน เครื่องคิดเลข
 
Chapter 7 8051 programming in c
Chapter 7  8051 programming in cChapter 7  8051 programming in c
Chapter 7 8051 programming in c
 
Maicrocontroller lab basic experiments
Maicrocontroller lab basic experimentsMaicrocontroller lab basic experiments
Maicrocontroller lab basic experiments
 
Maicrocontroller lab basic experiments
Maicrocontroller lab basic experimentsMaicrocontroller lab basic experiments
Maicrocontroller lab basic experiments
 
Buy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineBuy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects Online
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 
Instruction 8.pptx
Instruction 8.pptxInstruction 8.pptx
Instruction 8.pptx
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
 
PWM wave generator using microcontroller
 PWM wave generator using microcontroller  PWM wave generator using microcontroller
PWM wave generator using microcontroller
 
Pwm wave
Pwm wave Pwm wave
Pwm wave
 
8051 basic programming
8051 basic programming8051 basic programming
8051 basic programming
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent
 
Chp5 pic microcontroller instruction set copy
Chp5 pic microcontroller instruction set   copyChp5 pic microcontroller instruction set   copy
Chp5 pic microcontroller instruction set copy
 
4 io port-programming
4 io port-programming4 io port-programming
4 io port-programming
 
8085 paper-presentation
8085 paper-presentation8085 paper-presentation
8085 paper-presentation
 
Temperature sensor with a led matrix display (arduino controlled)
Temperature sensor with a led matrix display (arduino controlled)Temperature sensor with a led matrix display (arduino controlled)
Temperature sensor with a led matrix display (arduino controlled)
 
Microcontroller (8051) general and simple alp n cprograms
Microcontroller (8051) general and simple alp n cprogramsMicrocontroller (8051) general and simple alp n cprograms
Microcontroller (8051) general and simple alp n cprograms
 
Intel 8051 Programming in C
Intel 8051 Programming in CIntel 8051 Programming in C
Intel 8051 Programming in C
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

8051 C Assignments with all examples covered

  • 1. 8051 ASSIGNMENTS 1. WAP to Add, Sub, Mul, Div Two 8-bit Numbers? 2. WAP to Add, Sub, Mul, Div Two 8-bit Numbers Using Switch Case and place the result on P2? 3. WAP to multiply two 8-bit Numbers using functions? 4. WAP to Add, Sub, Mul, Div Two 8-bit Numbers Using Switch Case and using functions, call the Arithmetic Operations place the result on P2? 5. WAP to Get the ‘X’ value from P1 and send ‘X^2’ to P2, continuously? 6. WAP to add numbers from 1 to 10 and place the result on P1? 7. WAP to find a factorial of a number (input from P1 and continuously read input from P1) and place the result on P2? 8. WAP to blink Port pins of P1 (infinite times) using time delay? 9. WAP to blink alternate Port pins of P1 (infinite times) using time delay? 10. WAP to find a factorial of a number (input from P1 and continuously read input from P1) and place the result on P2 Using Functions?
  • 2. (1) ADD SUB unsigned char a,b,c; unsigned char a,b,c; a=10,b=5; a=10,b=5; c=a + b; c=a-b; P1=c; P1=c; MUL DIV unsigned char a,b,c; unsigned char a,b,c; a=10,b=5; a=10,b=5; c=a*b; c=a/b; P1=c; P1=c;
  • 3. (2) while(1) { x=P1; switch(x) { case 0x01 : P2=a + b; break; case 0x02 : P2=a-b; break; case 0x03 : P2=a*b; break; case 0x04 : P2=a/b; break; default : break; } }
  • 4. (3) void mul (unsigned char, unsigned char); main() { mul(a , b); } void mul (unsigned char a, unsigned char b) { P2=a*b; }
  • 5. (4) void add(unsigned char , unsigned char); void sub(unsigned char , unsigned char); void mul(unsigned char , unsigned char); void div(unsigned char , unsigned char); while(1) { x=P1; switch(x) { case 0x01 : add(a, b); break; case 0x02 : sub(a, b); break; case 0x03 : mul(a, b); break; case 0x04 : div(a, b); break; default : break; } }
  • 6. void add(unsigned char a , unsigned char b) { P2=a + b; } void sub(unsigned char a , unsigned char b) { P2=a-b; } void mul(unsigned char a , unsigned char b) { P2=a*b; } void div(unsigned char a , unsigned char b) { P2=a/b; }
  • 10. 8051 ASSIGNMENTS 1. WAP to send values 00-FF to port P1? 2. WAP to send Hex values for ASCII characters of 0,1,2,3,4,5,A,B,C, and D to port P1? 3. WAP to toggle all the bits of P0,P1, and P2 continuously with some time delay. Use the sfr keyword to declare the port addresses? 4. WAP to perform logical operations and send result to ports P0,P1, and P2? 5. WAP to convert packed BCD 0x29 to ASCII and display the bytes on P1 and P2? 6. WAP to convert ASCII digits of ‘4’ and ‘7’ to packed BCD and display them on P1? 7. WAP to convert FD (hex value) to Decimal and display the digits on P0,P1, and P2? 8. WAP to Add Two 16 bit numbers in Assembly? 9. WAP to find number of 1s and 0s in given byte in Assembly? 10. WAP to generate a Fibonacci series up to 10 numbers and store the series from 40H Location in Assembly?
  • 11. (1) void Delay(unsigned int); unsigned char i; for(i=0;i<=255;i++) { P1 = i; Delay(1000); } void Delay(unsigned int itime) { unsigned int i, j; for(i=0;i < itime; i++) for(j=0;j<2000;j++); }
  • 12. (2) void Delay(unsigned int); unsigned char num[]="012345ABCD"; unsigned char i; for(i=0;i<=10;i++) { P1 = num[i]; Delay(2000); } void Delay(unsigned int itime) { unsigned int i, j; for(i=0;i < itime; i++) for(j=0;j<4000;j++); }
  • 13. (3) sfr P0 = 0x80; sfr P1 = 0x90; sfr P2 = 0xA0; void Delay(unsigned int); while(1) { P0=0x55; P1=0x55; P2=0x55; Delay(250); P0=0xAA; P1=0xAA; P2=0xAA; Delay(250); }
  • 14. (4) void Delay(unsigned int); ------------ P0 = 0x35 & 0x0F; P1 = 0x04 | 0x68; P2 = 0x54 ^ 0x78; Delay(9000); P0 = ~0x55; P1 = 0x9A >> 3; P2 = 0x77 >> 4; Delay(9000); P0 = 0x6 << 4; ---------- void Delay(unsigned int itime) { unsigned int i, j; for(i=0;i< itime; i++) for(j=0;j<5000;j++); }
  • 15. (5) unsigned char x , y; unsigned char mybyte = 0x29; x = mybyte & 0x0F; P1 = x | 0x30; y = mybyte & 0xF0; y = y >> 4; P2 = y | 0x30;
  • 16. (6) unsigned char bcdbyte; unsigned char x='4',y='7'; x = x & 0x0F; x = x << 4; y = y & 0x0F; bcdbyte = x | y; P1 = bcdbyte;
  • 17. (7) unsigned char hex=0xFD,temp,d1,d2,d3; temp = hex / 10; d1 = hex % 10; d2 = temp % 10; d3 = temp / 10; P0 = d1; P1 = d2; P2 = d3;
  • 18. (9) ORG 0000H CLR C MOV R1,#0 MOV R2,#0 MOV R3,#8 MOV A,#97H L1: RLC A JNC L2 INC R1 L2: JC L3 INC R2 L3: DJNZ R3,L1 END
  • 19. (10) ORG 0000H MOV R0,#10 MOV R1,#40H MOV A,#1 MOV R3,#0 BACK: ADD A,R3 XCH A,R3 MOV @R1,A INC R1 DJNZ R0,BACK END
  • 20. 8051 ASSIGNMENTS 1. WAP to toggle alternate bits of port P1 continuously with some delay in between. Use Timer 0, 16-bit mode to generate the delay? 2. WAP to toggle only one bit P1.5 continuously for every 50ms. Use Timer 0, mode 1 (16-bit) to create the delay? 3. WAP to toggle alternate bits of port P2 continuously for every 500ms. Use Timer 1, mode 1 to create the delay? 4. WAP to create frequency of 2500Hz on pin P2.5. Use Timer 1, mode 2 to create the delay? 5. WAP to generate a square wave of 2KHz frequency on pin P1.5? 6. WAP to generate a square wave of 50Hz frequency on pin P2.5? 7. WAP to find a largest number in an array (in Assembly)? 8. WAP to find a smallest number in an array (in Assembly)? 9. WAP for Ascending Order (in Assembly)? 10. WAP for Descending Order (in Assembly)?
  • 21. (1) void T0Delay(); while(1) { P1 = 0x55; T0Delay(); P1 = 0xAA; T0Delay(); } void T0Delay() { TMOD = 0x01; TL0 = 0x00; TH0 = 0x35; TR0 = 1; while(TF0==0); TR0 = 0; TF0 = 0; }
  • 22. (2) void T0M1Delay(); while(1) { P1_5 = ~P1_5; T0M1Delay(); } void T0M1Delay() { TMOD = 0x01; TL0 = 0xFD; TH0 = 0x4B; TR0 = 1; while(TF0==0); TR0 = 0; TF0 = 0; }
  • 23. (3) void T1M1Delay(); unsigned char i; P2 = 0x55; while(1) { P2 = ~P2; for(i=0;i<20;i++) T1M1Delay(); } void T1M1Delay() { TMOD = 0x10; TL1 = 0xFE; TH1 = 0xA5; TR1 = 1; while(TF1==0); TR1 = 0; TF1 = 0; }
  • 24. (4) void T1M2Delay(); while(1) { P2_5 = ~P2_5; T1M2Delay(); } void T1M2Delay() { TMOD = 0x20; TH1 = -184; TR1 = 1; while(TF1==0); TR1 = 0; TF1 = 0; }
  • 25. (5) void T1M1Delay(); while(1) { P1_5 = ~P1_5; T1M1Delay(); } void T1M1Delay() { TMOD = 0x10; TL1 = 0x1A; TH1 = 0xFF; TR1 = 1; while(TF1==0); TR1 = 0; TF1 = 0; }
  • 26. (6) void T1M1Delay(); while(1) { P2_5 = ~P2_5; T1M1Delay(); } void T1M1Delay() { TMOD = 0x10; TL1 = 0x00; TH1 = 0xDC; TR1 = 1; while(TF1==0); TR1 = 0; TF1 = 0; }
  • 27. (7) ORG 0000H MOV R1,#50H MOV R2,#05H MOV 40H,#00H L2: MOV A,@R1 CJNE A,40H,L1 L3: INC R1 DJNZ R2,L2 MOV A,40H MOV R3,A SJMP $ L1: JC L3 MOV 40H,A SJMP L3 END
  • 28. (8) ORG 0000H MOV R1,#50H MOV R2,#05H MOV A,@R1 MOV 40H,A L2: CJNE A,40H,L1 L3: INC R1 MOV A,@R1 DJNZ R2,L2 MOV A,40H MOV R3,A SJMP $ L1: JNC L3 MOV 40H,A SJMP L3 END
  • 29. (9) ORG 0000H MOV R1,#50H MOV R2,#05H MOV 30H,#04H MOV B,#50H L3: MOV A,@R1 MOV 40H,A L2: MOV A,@R1 CJNE A,40H,L1 L4: INC R1 DJNZ R2,L2 INC B MOV R1,B MOV R2,30H DJNZ 30H,L3 SJMP $ L1: JNC L4 XCH A,40H MOV @R1,A MOV A,40H PUSH 01H MOV R1,B MOV @R1,A POP 01H SJMP L4 END
  • 30. (10) ORG 0000H MOV R1,#50H MOV R2,#05H MOV 30H,#04H MOV B,#50H L3: MOV A,@R1 MOV 40H,A L2: MOV A,@R1 CJNE A,40H,L1 L4: INC R1 DJNZ R2,L2 INC B MOV R1,B MOV R2,30H DJNZ 30H,L3 SJMP $ L1: JC L4 XCH A,40H MOV @R1,A MOV A,40H PUSH 01H MOV R1,B MOV @R1,A POP 01H SJMP L4 END
  • 31. 8051 ASSIGNMENTS 1. WAP to transfer the letter “A” serially at 4800 Baud Rate continuously. Use serial communication mode 1? 2. WAP to transfer the word “CBIT” at 9600 Baud Rate continuously. Use serial communication mode 1? 3. WAP to receive bytes of data serially and put them in P1. Set the Baud Rate at 4800. Use serial communication mode 1? 4. WAP to send two different strings to the serial port .Assuming that SW is connected to pin P2.0, monitor its status and make decision as follows:- (i) SW = 0: send your first name, (ii) SW= 1: send your last name. Use serial communication mode 1? 5. WAP to send the two messages “Normal Speed” and “High Speed” to the serial port. Assuming that SW is connected to pin P2.0, monitor its status and set the baud rate as follows:- (i) SW = 0: 28,800 baud rate, (ii) SW= 1: 56K baud rate. Use serial communication mode 1?
  • 32. 8051 ASSIGNMENTS 1. WAP to read the KeyBoard and send it to the serial port. Use baud rate 9600? 2. Write the above program in Assembly 3. WAP to get data from P2 and send it to P1, while simultaneously creating a square wave of 200us period on pin P0.5. Use timer 0 mode 2 to create the square wave? 4. WAP to get data from P2 and send it to P1, while simultaneously creating, (i) Square wave of 200us period on pin P0.5, (ii) Sending a letter ‘A’ to the serial port. Use timer 0 mode 2 to create the square wave and use 9600 baud rate? 5. WAP using interrupts to do the following :- (a) Receive data serially and send it to P0, (b) Read port P1,transmit data serially, and give a copy to P2. (c) Make timer 0 mode 2 generate a square wave of 5KHz frequency on pin P0.5. Set baud rate at 4800.
  • 33. (1) TMOD = 0x20; TH1 = 0xFA; SCON = 0x50; TR1 = 1; while(1) { SBUF = 'A'; while(TI == 0); TI = 0; }
  • 34. (2) void SerTx (unsigned char); TMOD = 0x20; TH1 = 0xFD; SCON = 0x50; TR1 = 1; while(1) { SerTx('C'); SerTx('B'); SerTx('I'); SerTx('T'); } void SerTx (unsigned char ch) { SBUF = ch; while(TI == 0); TI = 0; }
  • 35. (3) unsigned char ch; TMOD = 0x20; TH1 = 0xFA; SCON = 0x50; TR1 = 1; while(1) { while(RI == 0); ch = SBUF; P1 = ch; RI = 0; }
  • 36. (4) #define SW P2_0 unsigned char i; unsigned char fname[] = "CBIT"; unsigned char lname[] = "College"; TMOD = 0x20; TH1 = 0xFD; SCON = 0x50; TR1 = 1;
  • 37. (4) if(SW == 0) { for(i=0;i<4;i++) { SBUF = fname[i]; while(TI == 0); TI = 0; } } else { for(i=0;i<7;i++) { SBUF = lname[i]; while(TI == 0); TI = 0; } } while(1);
  • 38. (5) #define SW P2_0 unsigned char i; unsigned char Mesg1[] = "Normal Speed"; unsigned char Mesg2[] = "High Speed"; TMOD = 0x20; TH1 = 0xFF; SCON = 0x50; TR1 = 1;
  • 39. (5) if(SW == 0) { for(i=0;i<12;i++) { SBUF = Mesg1[i]; while(TI == 0); TI = 0; } } else { PCON = PCON | 0x80; for(i=0;i<10;i++) { SBUF = Mesg2[i]; while(TI == 0); TI = 0; } } while(1);
  • 40. #include <REG51.H> main() { unsigned char byte; TMOD=0x20; TH1=0xFA; SCON=0X50; TR1=1; while(1) { while(RI==0); byte=SBUF; RI=0; SBUF=byte; while(TI==0); SBUF=byte; TI=0; } } 6
  • 41. (8) void timer0() interrupt 1 { P0_5 = ~P0_5; } main() { TMOD = 0x02; TH1 = 0xA4; IE = 0x82; TR1 = 1; while(1) { P1 = P2; } }
  • 42. (9) void timer0() interrupt 1 { P0_5 = ~P0_5; } void serial() interrupt 4 { IE = 0x82; SBUF = 'A'; while(TI==0); TI = 0; RI = 0; }
  • 43. (9) TMOD = 0x22; TH1 = -3; TH0 = 0xA4; SCON = 0x50; IE = 0x92; TR = 1; TR0 = 1; while(1) { IE = 0x92; P1 = P2; }
  • 44. (10) void timer0() interrupt 1 { P0_5 = ~P0_5; } void serial() interrupt 4 { if(TI == 1) { TI = 0; } else { P0 = SBUF; RI = 0; } }
  • 45. (10) unsigned char ch; TMOD = 0x22; TH1 = 0xF6; TH0 = 0xA4; SCON = 0x50; IE = 0x92; TR1 = 1; TR0 = 1; while(1) { ch = P1; SBUF = ch; P2 = ch; }
  • 46. 8051 ASSIGNMENTS 1. WAP to enter user name and password it is correct print Access granted otherwise print Access Denied, use serial communication. Use 9600 baud rate? 2. WAP to blink Port pins of P2 (infinite times) using time delay and execute on Proteus? 3. WAP to blink alternate Port pins of P2(infinite times) using time delay and execute on Proteus? 4. WAP to display the single character on LCD and execute in Proteus? 5. WAP to display the single character on LCD and Scroll it continuously and execute in proteus? 6. WAP to display the string on LCD and execute in Proteus? 7. WAP to display the string on LCD and Scroll it continuously and execute in proteus? 8. WAP to read the Keyboard and display on serial port and LCD? 9. WAP to read the Keypad Key and display on LCD? 10. WAP to read the Keypad Key and display on LCD and also on serial port?
  • 47. (2) #include <AT89X51.H> void Delay(unsigned int); main() { while(1) { P2=0x00; Delay(250); P2=0xFF; Delay(250); } } void Delay(unsigned int itime) { unsigned int i, j; for(i=0; i< itime; i++) for(j=0; j<1275; j++); }
  • 48. (4) #include <AT89X51.H> Delay(unsigned char itime) { unsigned char i, j; for(i=0; i<itime ; i++) for(j=0;j<255;j++); } lcd_cmd (unsigned char value) { P2=value; P3_6=0; P3_5=1; Delay(50); P3_5=0; }
  • 49. (4) lcd_data (unsigned char ch) { P2=ch; P3_6=1; P3_5=1; Delay(50); P3_5=0; } main() { lcd_cmd(0x38); lcd_cmd(0x01); lcd_cmd(0x0E); lcd_cmd(0x06); lcd_cmd(0x80); lcd_data('A'); while(1); }
  • 50. (6) #include <AT89X51.H> Delay(unsigned char itime) { unsigned char i, j; for(i=0; i<itime ; i++) for(j=0;j<255;j++); } lcd_cmd(unsigned char value) { P2=value; P3_6=0; P3_5=1; Delay(50); P3_5=0; }
  • 51. (6) lcd_data(unsigned char *str3) { while(*str3) { P2=*str3; P3_6=1; P3_5=1; Delay(50); P3_5=0; str3++; } } main() { unsigned char *str1="CBIT"; unsigned char *str2="COLLEGE"; lcd_cmd(0x38); lcd_cmd(0x01); lcd_cmd(0x0E); lcd_cmd(0x06); lcd_cmd(0x86); lcd_data(str1); lcd_cmd(0xc2); lcd_data(str2); while(1); }
  • 52. (9) #include <AT89X51.H> #define COLROW P1 unsigned char keypadMatrix [4][4]={"0123", "4567", "89AB", “CDEF"}; //-----------------------LCD DELAY-----------------------// Delay1(unsigned char itime) { unsigned char i, j; for(i=0; i<itime; i++) for(j=0;j<255;j++); } //-----------------------KEYPAD DELAY--------------------// void Delay2(unsigned char itime) { unsigned int i, j; for(i=0; i<itime; i++) for(j=0;j<1257;j++); }
  • 53. (9) //-------------------LCD COMMAND FUNCTION----------------// lcd_cmd(unsigned char value) { P2=value; //LCD CONNECTED TO P2 P3_6=0; //REGISTER SELECT P3_5=1; //ENABLE HIGH Delay1(50); P3_5=0; //ENABLE LOW } //-----------------------LCD DATA FUNCTION---------------// lcd_data(unsigned char ch) { P2=ch; //LCD CONNECTED TO P2 P3_6=1; //REGISTER SELECT P3_5=1; //ENABLE HIGH Delay1(50); P3_5=0; //ENABLE LOW }
  • 55. (9) //--------------------KEYPAD FUNCTION--------------------// unsigned char keypad() { unsigned char key, ROW,COL; do { COLROW = 0xF0; COL = COLROW; COL &= 0xF0; }while(COL != 0xF0); do { Delay2(20); COL = COLROW; COL &= 0xF0; }while(COL == 0xF0);
  • 56. (9) COLROW = 0xFE; COL = COLROW; COL &= 0xF0; if(COL != 0xF0) { ROW = 0; goto FINDC; } COLROW = 0xFD; COL = COLROW; COL &= 0xF0; if(COL != 0xF0) { ROW = 1; goto FINDC; } COLROW = 0xFB; COL = COLROW; COL &= 0xF0; if(COL != 0xF0) { ROW = 2; goto FINDC; } COLROW = 0xF7; COL = COLROW; COL &= 0xF0; ROW = 3;
  • 57. (9) FINDC: if(COL == 0xE0) key = keypadMatrix[ROW][0]; else if(COL == 0xD0) key = keypadMatrix[ROW][1]; else if(COL == 0xB0) key = keypadMatrix[ROW][2]; else key = keypadMatrix[ROW][3]; return key; } //-----------------------MAIN PROGRAM-----------------------// main() { unsigned char key; lcd_init(); while(1) { key = keypad(); lcd_data(key); } } //----------------------------------------------------------------------//
  • 58. 8051 ASSIGNMENTS 1. WAP to rotate stepper motor in clockwise and execute in proteus? 2. WAP to rotate stepper motor in anticlockwise and execute in proteus? 3. WAP to monitor the status of SW and perform the following :- (a) If SW = 0, the stepper motor rotates clockwise. (b) If SW = 1, the stepper motor rotates anticlockwise, and execute in proteus? 4. WAP to rotate stepper motor in clockwise in Assembly and execute in proteus? 5. WAP to ADC and Display on LCD and execute in proteus?
  • 59. (1) #include <AT89X51.H> void Delay(unsigned int itime) { unsigned int i, j; for(i=0; i<itime; i++) for(j=0;j<500;j++); } main() { while(1) { P2 = 0x09; Delay(100); P2 = 0x0C; Delay(100); P2 = 0x06; Delay(100); P2 = 0x03; Delay(100); } }
  • 60. (2) #include <AT89X51.H> void Delay(unsigned int itime) { unsigned int i, j; for(i=0; i<itime; i++) for(j=0;j<500;j++); } main() { while(1) { P2 = 0x03; Delay(100); P2 = 0x06; Delay(100); P2 = 0x0C; Delay(100); P2 = 0x09; Delay(100); } }
  • 61. (3) #include <AT89X51.H> #define SW P1_0 void Delay(unsigned int itime) { unsigned int i, j; for(i=0; i<itime; i++) for(j=0;j<1275;j++); } main() { while(1) { if(SW==0) { P2 = 0x09; Delay(100); P2 = 0x0C; Delay(100); P2 = 0x06; Delay(100); P2 = 0x03; Delay(100); }
  • 62. (3) else { P2 = 0x03; Delay(100); P2 = 0x06; Delay(100); P2 = 0x0C; Delay(100); P2 = 0x09; Delay(100); } } }
  • 63. (4) ORG 00H MOV A,#99H BACK: MOV P2,A RR A ACALL DELAY SJMP BACK DELAY:MOV R1,#100 H1:MOV R2,#255 H2:DJNZ R2,H2 DJNZ R1,H1 RET END
  • 64. (5) #include <AT89X51.H> //=============================================== #define ADC_0804_Data P1 //Pins 11(DB7)-18(DB0) sbit Read = P3^2; //Pin 2 sbit Write = P3^3; //Pin 3 sbit Interrupt = P3^5; //Pin 5 unsigned char ADC_Value =0; //=============================================== Delay(unsigned char itime) { unsigned char i, j; for(i=0; i<itime; i++) for(j=0;j<255;j++); } //===============================================
  • 65. (5) lcd_cmd(unsigned char cmd) { P2=cmd; P3_6=0; P3_7=1; Delay(50); P3_7=0; } //=============================================== lcd_print (unsigned char *str) { while(*str) { P2=*str; P3_6=1; P3_7=1; Delay(50); P3_7=0; str++; } }
  • 67. (5) unsigned char * Hex2ASCII(unsigned char Hex) { unsigned char D[3],Temp; Temp = Hex/10; D[2] = Hex%10; D[1] = Temp%10; D[0] = Temp/10; D[2] |= 0x30; D[1] |= 0x30; D[0] |= 0x30; D[3] = '0'; return D; } main() { unsigned char *D; lcd_init(); lcd_print("Temperature="); while(1) { ADC_Value=ADC_0804(); D=Hex2ASCII(ADC_Value); lcd_cmd(0x8C); lcd_print(D); } }