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

Using assembly language: Task 1: Write a complete program to turn on all 8 LEDs

ID: 3586119 • Letter: U

Question

Using assembly language:

Task 1: Write a complete program to turn on all 8 LEDs by pressing the push button (P0.14) eight times. By each press on the push button one of the eight LEDs should get on. Start from PO.8 to P0.15. (first press, turn on P0.8, second press turn on P0.9 and so on). Task 2: Write a complete program to turn off all 8 LEDs( on Task1), based on the result of comparison between number A, and B A is a constant value 10, and B is the number of press on push button. If B is equal A, turn off all 8 LEDs. (Now after you are done with Task1, keep on pressing push button till B is equal to A, then turn off all 8 LEDs.)

Explanation / Answer

Task 2 is dependent on Task 1, so single program is made for both.

Please modify the input/output register variables for your need.

Save the below content in a *.c file and compile to get executable and run.

/******************************************/

/*
* Led.c
*
* Created on: 04-Oct-2017
*      Author:
*/
#include<stdio.h>

// function prototypes
void TurnOnLED();
void TurnOffLED();
#define A 10
int pushbutton; // input register variable for push button
               //                   1       when pressed once
               //                   0       when not pressed
int B=0; //counter variable
//Following are output register variables for LED
// LED will turn on when value is 1
// LED will turn off when value is 0
int P0_8;
int P0_9;
int P0_10;
int P0_11;
int P0_12;
int P0_13;
int P0_14;
int P0_15;
int main()
{

   while(1)
   {
       if(pushbutton==1 && B<A)
       {
           TurnOnLED();
           B++;
       }
       else if(pushbutton==1 && B==A)
       {
           TurnOffLED();
           B=0;
       }
   }
}

void TurnOnLED()
{
   switch(B)
   {
   case 0:
       P0_8=1;
       break;
   case 1:
       P0_9=1;
       break;
   case 2:
       P0_10=1;
       break;
   case 3:
       P0_11=1;
       break;
   case 4:
       P0_12=1;
       break;
   case 5:
       P0_13=1;
       break;
   case 6:
       P0_14=1;
       break;
   case 7:
       P0_15=1;
       break;
   default:
       break;
   }

}

void TurnOffLED()
{
   P0_8=0;
   P0_9=0;
   P0_10=0;
   P0_11=0;
   P0_12=0;
   P0_13=0;
   P0_14=0;
   P0_15=0;
}

/********************************************/

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