Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C that reads a 3-bit desired light pattern from the 3 input s

ID: 3854761 • Letter: W

Question

Write a program in C that reads a 3-bit desired light pattern from the 3 input switches connected to pins P2.3-P2.5 and displays the patter on the 8 LEDs with some rotation options based on the other 3 switches.


[4] 3.a) Switch on Port2.0 (Read/Rotate mode)


On (logic 0) – Read mode: Your program continuously reads the switches and takes only the 3-bits (Port 2.3-2.5) as a desired display pattern and displays them on the LEDs (Port 1.3-1.5). All other LEDs on Port 1 are masked to zero (turned off).


Off (logic 1) – Rotate mode: Once this switch is turned off, your program will rotate the pattern on the 8 LEDs connected to Port1 pins 0-7. The pattern is the 3-bit value you constantly updated and saved during the Read mode.


[4] 3.b) Switch on Port2.1 (Left/Right direction mode)


On (logic 0) – The LED pattern rotates to the Left.


Off (logic 1) – The LED pattern rotates to the Right.


[4] 3.c) Switch on Port2.2 (Fast/Slow speed

mode) **Hint: Software Delay**


On (logic 0) – The patter rotation is Fast.


Off (logic 1) – The patter rotation is Slow


Explanation / Answer

#include<stdio.h>

main()

{ int k=1,p,l,i;

int p2[8],p1[8];

for(i=0;i<8;i++){

p1[i]=0;

p2[i]=0;

}

while(k==1)

{

printf("enter the pin inputs from p2.3-p2.5:");

scanf("%d%d%d",&p2[3],&p2[4],&p2[5]);

  

printf("Press Logic 0 for on and 1 for off on switch port p2.0 ");

scanf("%d",&l);

p1[3]=p2[3];

p1[4]=p2[4];

p1[5]=p2[5];

if(l==0)

{p=1;

for(i=0;i<8;i++)

printf("p1.%d : %d ",i,p2[i]);

printf(" press either 1 to continue or 0 to stop :");

scanf("%d",&p);

printf(" ");

while(p==1)

{ printf("enter the pin inputs from p2.3-p2.5:");

scanf("%d%d%d",&p2[3],&p2[4],&p2[5]);

p1[3]=p2[3];

p1[4]=p2[4];

p1[5]=p2[5];

for(i=0;i<8;i++)

printf("p1.%d : %d ",i,p2[i]);

printf(" press either 1 to continue or 0 to stop :");

scanf("%d",&p);

printf(" ");

}

}

else

{

printf("After Rotation of pattern : ");

for(i=0;i<8;i++)

{ if(p2[i]==0)

printf("p1.%d : 1 ",i);

else

printf("p1.%d : 0 ",i);

  

}

}

  

  

printf("press 0 for on and 1 for off on switch port p2.1 : ");

scanf("%d",&l);

if(l==0)

{ printf(" Left Rotation of pattern from read mode : ");

  

printf("p1.0 : %d ",p1[0]);

printf("p1.1 : %d ",p1[5]);

printf("p1.2 : %d ",p1[6]);

printf("p1.3 : %d ",p1[3]);

printf("p1.4 : %d ",p1[2]);

printf("p1.5 : %d ",p1[1]);

printf("p1.7 : %d ",p1[6]);

printf("p1.7 : %d ",p1[7]);

  

}

else

{printf(" Right rotation of pattern from read mode: ");

printf("p1.0 : %d ",p1[0]);

printf("p1.1 : %d ",p1[1]);

printf("p1.2 : %d ",p1[2]);

printf("p1.3 : %d ",p1[7]);

printf("p1.4 : %d ",p1[6]);

printf("p1.5 : %d ",p1[5]);

printf("p1.7 : %d ",p1[4]);

printf("p1.7 : %d ",p1[3]);

}

  

  

printf("press 0 for on and 1 for off on switch port p2.2 : ");

scanf("%d",&l);

if(l==0)

printf("Make Rotation fast ");

else

printf("Make Rotation slow ");

  

printf("Enter 1 to continue or 0 to exit:");

scanf("%d",&k);

printf(" ");

  

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote