#include <P18F458.h> void main(void) { unsigned char mynum[]= \"012345ABCD\"; un
ID: 1846089 • Letter: #
Question
#include <P18F458.h>
void main(void)
{
unsigned char mynum[]= "012345ABCD";
unsigned char z;
TRISB = 0;
for(z=0;z<10;z++)
PORTB = mynum[z];
while(1);
}
(5%) In the original code, what is sent to PORTB when z = 9?
(8%) If line 4 is changed to unsigned char mynum[]= "012345AB"; what is sent to PORTB when z = 9?
(8%) If line 4 is changed to unsigned char mynum[]= "012345ABCDEFGH"; what is sent to PORTB when z = 9?
(12%) How can you change line 7 the for loop so that it can read the whole mynum[] array whether it is "012345ABCD", "012345AB", "012345ABCDEFGH", or "012345ABCDEFGHIJKLMNOPQRSTUVWXYZ"?
Explanation / Answer
(1) the ascii value of D i.e. 68 is sent to PORTB
2) some garbage value is sent to PORTB
3) the ascii value of D i.e. 68 is sent to PORTB
4) for(z=0;mynum[z]!='';z++)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.