Question

In: Electrical Engineering

Using the parity bit, port b is to flash in a pattern of Odd Numbered LEDs...

Using the parity bit, port b is to flash in a pattern of Odd Numbered LEDs On and Even Numbered LEDS Off for 1 second, and then Odd Numbered LEDs Off and Even Numbered LEDS On for 1 second. This pattern will repeat indefinitely. Please provide the both the assembly code for MPLAB and a flow chart. Note - consider delay calculations and port B initialization have already been completed.

Solutions

Expert Solution

code for pattern:

//LED Pin Variables
int ledPins[] = {2,3,4,5,6,7,8,9}; //An array to hold the pin each LED is connected to
//i.e. LED #0 is connected to pin 2, LED #1, 3 and so on
//to address an array use ledPins[0] this would equal 2
//and ledPins[7] would equal 9

int lightModulo = 0; // for which modulo to light

/*
* setup() - this function runs once when you turn your Arduino on
* We the three control pins to outputs
*/
void setup()
{
  
//Set each pin connected to an LED to output mode (pulling high (on) or low (off)
for(int i = 0; i < 8; i++){ //this is a loop and will repeat eight times
pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
} //the code this replaces is below
  
Serial.begin(9600);
}


/*
* loop() - this function will start after setup finishes and then repeat
* we call a function called oneAfterAnother(). if you would like a different behaviour
* uncomment (delete the two slashes) one of the other lines
*/
void loop() // run over and over again
{
turnOnEvenOdd();
}

// turn on even LEDs, then odd LEDs.
// nice to have them set up as yellow/red
void turnOnEvenOdd() {
int delayTime = 250;
  
// print desired modulo.
Serial.println(lightModulo);
  
for (int i = 0; i < 8; i++) {
if ((i % 2) == lightModulo) {
// on
// when desired modulo is 1 (odd), odds will light
// when desired modulo is 0 (even), evens will light
digitalWrite(ledPins[i], HIGH);
} else {
// off
// ...and the others will be turned off
digitalWrite(ledPins[i], LOW);
}
}
  
// switch lightModulo to the other light
lightModulo--; // decrease. 1 turns to 0, 0 turns to -1
lightModulo = abs(lightModulo); // when it's -1 (from 0), abs to 1
  
delay(delayTime);
}


Related Solutions

Using the three-bit exponent field and four-bit significand, what is the bit pattern for the -2.5?...
Using the three-bit exponent field and four-bit significand, what is the bit pattern for the -2.5? (show work)
1. Assume that a bit sequence "10000000" has been transmitted through a transmission media using parity...
1. Assume that a bit sequence "10000000" has been transmitted through a transmission media using parity bits. Two bits have been altered in the path and the receiver has received it as "10000011". will the receiver be able to detect the error. Justify your answer. 2.Which of the following is NOT a consequence of poor project management? a. Time slippage. b. Loss of intellectual property. c. Failure to obtain anticipated benefits. d. Costs that exceed budgets. 3. Simon's software company...
Develop an I/O port decoder, using a PLD, that generates 16-bit I/O strobes for the following...
Develop an I/O port decoder, using a PLD, that generates 16-bit I/O strobes for the following 16-bit I/O port addresses: 1000H-1001H, 1002H-103H, 1004H-1005H, 1006H-1007H, 1008H-1009H, 100AH-100BH, 100CH-100DH, and 100EH-100FH.
5. Implement 2-D error detection mechanism using even parity check. Given a data bit to be...
5. Implement 2-D error detection mechanism using even parity check. Given a data bit to be send, perform the even parity check for the data to be send. Append the parity bit at the end of that data. At the receiver end, the receiver has to check for errors in transmission Please code in C language.
Input pin(s): inputw [1], sysclock [1] Output pin(s): outputq [1] Design a 3-bit parity generator using...
Input pin(s): inputw [1], sysclock [1] Output pin(s): outputq [1] Design a 3-bit parity generator using a minimal state table for a Moore model FSM. For every three bits that are observed on inputw during three consecutive clock cycles, the FSM generates the parity bit outputq = 1 if the number of 1s received in the sequence so far is odd. Must use a maximum of 3 flip flops.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT