0% found this document useful (0 votes)
7 views

Digital Assignment LAB 2

embedded c assignement

Uploaded by

Affan Ahmmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Digital Assignment LAB 2

embedded c assignement

Uploaded by

Affan Ahmmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Digital Assignment LAB 2

Embedded C Programming
Winter Semester 24
Submitted by,
Affan Ahmmed
21BEI0006
Exp: 2(a)

Date: 03/02/2024

Aim:

a) To print the values from 0 to 255 in port 1

b) To print the character array in port 1

c) To print the unsigned character in port 1

Algorithm:

a) The embedded C software initialises an 8-bit variable called "z," then iterates from 0 to 255 using a
for loop. An 8051 microcontroller's Port 1 (P1) is assigned the value "z" within the loop. P1's output
most likely increases continually because of this.

b) An 8-bit variable called "z" and a character array called "ch" are initialized with the values
"012345ABCD" by the embedded C programming. The 8051 microcontroller's Port 1 (P1) is assigned
to each character from 'ch' as iterates from 0 to 9 using a for loop. This causes P1 to display a string
of characters.

c) This embedded C programme declares a character array called "ch" that contains strings
representing a series of numerical numbers. Next, it assigns each character to Port 1 (P1) of an 8051
microcontroller, perhaps for output, by iterating through the array using a for loop.

Code:

a)

#include <reg51.h>

void main() {

unsigned char z;

for (z=O;z<=255;z++)

P1=z;

}
b)

#include <reg51.h>

void main() {

unsigned char ch[]="012345ABCD";

unsigned char z;

for(z=0;z<=9;z++)

P1=ch[z];

c)

#include <reg51.h>

void main() {

unsigned char ch[]="+1,-1,+2,-2,+3,-3";

unzigned char z;

for(z=0;z<=5;z++)

P1=ch[z];

}
Exp: 2(b)

Date: 06/02/2024

Logical Programming

Aim:

a) Take any packed BCD number, unpack them and display it in P1 and P2

b) Find sum of the given numbers and its check sum

c) Write the programme in a way when a switch is turned on and off, a buzzer gets activated.

Algorithm:

a) This embedded C programme changes the lower 4 bits of Port 1 (P1) to the lower nibble of 'i' and
initialises a variable called 'i' with 0x78. After extracting the higher nibble of "i" and shifting it four
bits to the right, it stores the outcome in the variable "x." Finally, Port 2 (P2) is given the higher
nibble of 'x'.

b) This embedded C programme calculates the two's complement sum of an array (i) using an 8-bit
microcontroller (8051) and displays the result on ports P1 and P2. Iterating over the array, it adds up
the total, takes its two-fold complement, and outputs it to the designated ports.

c) This embedded C programme toggles the status of a pin (P1^7) dependent on the input state of
another pin (P1^1) using an 8051 microcontroller. When P1^1 is low within an infinite loop, P1^7 is
set high for a delay and then lowered low once more for another delay. The delay function uses
stacked loops to produce a time delay.

You might also like