A. Consider Example This example asked you to run C code on MPLAB to send values
ID: 1846042 • Letter: A
Question
A. Consider Example
This example asked you to run C code on MPLAB to send values 00-FF to PORT B.
1. #include <P18F458.h>
2. void main(void)
3. {
4. unsigned char z;
5. TRISB = 0;
6. for(z=0;z<=255;z++)
7. PORTB = z;
8. while(1);
9. }
(d) 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.
While(z<255)
PORTB=z
z++
while(1)
(e) 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. #include <P18F458.h>
2. void main(void)
3. {
4. unsigned char z;
5. TRISB = 0;
6. TRISC =0;
6. for(z=0;z<=255;z++)
7. {
8. if(z%2==0)
9. PORTB = z;
10. else
11. PORTC=z;
12. }
13. while(1);
14. }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.