You are on page 1of 8

MBSD LAB REPORTS

Spring 2022
MBSD LAB

M.Subhan Ghani
19PWCSE1826
Lab 1
Lab Task:
Implement the assembly code for toggling in C and test it on Keil IDE.

Code:
#include<reg51.h>
#include<stdio.h>

void main() {
while(1) {
P1 = 0xff;
P1 = 0x00;
}
}
Lab 2
Task:
Interface Pull-up resistors with Port0 on starter circuit and write a program in assembly language and C
language to display the following patterns on Port.

Code:
#include<reg51.h>
#inlcude<stdio.h>

void delayfunc() {
int i = 0, j;
for(;i < 3000; i++)
for(j = 0; j < 30; j++);
}

void main() {
int a = 1;
P0 = 0x01;
while(1) {
P0 = 0x02;
delayfunc();
P0 = 0x04;
delayfunc();

P0 = 0x08;
delayfunc();

P0 = 0x0A;
delayfunc();

P0 = 0x0C;
delayfunc();

P0 = 0x0E;
delayfunc();
P0 = 0x0E;
delayfunc();

P0 = 0x10;
delayfunc();

P0 = 0x12;
delayfunc();
}
}

Lab No.3

Task:
Write a C language program which will continuously read values from Port 1 of 8051 and display them
on LEDs interfaced to Port 0 of 8051.
Code:
#include<reg51.h>
#inlcude<stdio.h>
void main() {
P1 = 0;
while(1) {
P0 = P1;
}
}

OUTPUT:

Task 2 of Lab 3:
Write a program to input two numbers, find their sum and display the result
NOTE: In this task I have taken least significant 4 bits of P1 as 1 number and most significant 4 bits of P1
as second number.
Code:
#include<reg51.h>
#inlcude<stdio.h>
void main() {
while(1) {
P0 = P1 + P2;
}
}

Task 3 of Lab3:
Write a program to find whether the input number is a prime number or not?
Code:
#include<reg51.h>
#inlcude<stdio.h>
sbit node = P2^0;
void main() {
P1 = 0;
while(1) {
if(P1 %2 == 0) node= 0;
else
node = 1;
}
}
Lab No. 4
Task:
Write a C code for Interfacing DIP Switches to 8051 using Interrupts.
Code:
#include<reg51.h>
#inlcude<stdio.h>
sbit pin = P3^2;
void ISR() interrupt 0 {
P0 = P0 * 2;
}

void main() {
pin = 1;
IE = 0x81;
}
OUTPUT:
Lab No.5
Task:
Display different numbers on Seven Segment Display.
Code:
#include <reg51.h>
#include <stdio.h>

void main(void)
{
Int e = 0;
P1 = 0;
for(e = 0;e < 10000;e++);
P1 = 15;
for(e = 0;e < 10000;e++);
P1 = 20;
for(e = 0;e < 10000;e++);
P1 = 200;
for(e = 0;e < 10000;e++);
P1 = 255;
for(e = 0;e < 10000;e++);

OUTPUT:
Lab No.6 Implementation of Timer using 8051
Task:
Lab No.6 Implementation of Timer using 8051
I implemented a hex second counter.
CODE:
#include <reg51.h>
#include <stdio.h>
void t0() interrupt 1 {
P1++;
TH0 = 0xa0;
TL0 = 0x28;
}
void main(void)
{
IE = 0x82; //timer 1
TMOD = 0x01;
TH0 = 0xa0;
TL0 = 0x28;
TH0 =
P1 = 0;
TR0 = 1;
while(1);
}

You might also like