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

This example asked you to run C code on MPLAB to send values 00-FF to PORT B. #i

ID: 1846088 • Letter: T

Question

This example asked you to run C code on MPLAB to send values 00-FF to PORT B.

#include <P18F458.h>   

void main(void)

  {

    unsigned char z;

    TRISB = 0;

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

      PORTB = z;

    while(1);

  }


(7%) What happens to the code if you want to run that in PIC18F4321? Do you possibly need any change?

(8%) If you change the inside of for loop from z<=255 to z <= 100, will this code still work (with possibly less iterations?)?

(10%) What happens if you replace the line 7 PORTB = z; by z = PORTB;? Mention if you need also some code change.

(10%) Show how you do this if you want to replace the original for loop (of lines 6 and 7) by a while loop (you still have while(1) in line 8). Yes, this is an ECE 114 question.

(10%) Show how you can do this if you want PORTB = z; for even z and PORTC = z; for odd z. The range of z is from 0 till 255 as original code.


Explanation / Answer

1) change1st line to #include <PI18F4321.h>


2) yes, with lesser iterations


3) the value of PORTB is assigned to z;


4)

the for loop of lines 6 and 7 can be replaced by :


z=0;

while(z<=255)

{

PORTB = z;

z++;

}




z=0;

while(z<=254)

{

PORTB = z;

z = z+2;

}


z = 1;

while(z<=255)

{

PORTC = z;

z = z+2;

}

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