please explain what the code means: initButtons Explain the following routine vo
ID: 3541768 • Letter: P
Question
please explain what the code means:
initButtons Explain the following routine void initButtons(unsigned int mask) { if(mask&0x0008) TRISDbits.TRISD6=1; if(mask&0x0004) TRISDbits.TRISD7=l; if(mask&0x0002) TRISAbits.TRISA7=l; if(mask&OxOOOl;) TRISDbits.TRISD13=l; get Button Explain the following code: unsigned int getButton(unsigned int mask) { unsigned int button; switch(mask) { case 0x0008: button=!PORTDbits.RD6; break; case 0x0004: button=!PORTDbits.RD7; break; case 0x0002: TRJSAbits.TRISA7=1; button=!PORTAbits.RA7; break; case 0x0001: button=!PORTDbits.RDl3; break; default: button=0; } return (button); }Explanation / Answer
initButton:
anding mask with 0x0008 is nothing but checkling 4th bit in mask.
if 4th bit in mask is enabled ,set TRISDbits.TRISD6 to 1
anding mask with 0x0004 is nothing but checkling 3rd bit in mask.
if 3rd bit in mask is enabled ,set TRISDbits.TRISD7 to 1
anding mask with 0x0002 is nothing but checkling 2nd bit in mask.
if 2rn bit in mask is enabled ,set TRISDbits.TRISA7 to 1
anding mask with 0x0001 is nothing but checkling 1st bit in mask.
if 1st bit in mask is enabled ,set TRISDbits.TRISD13 to 1
getButton:
if mask is 0x0008 return negation of PORTDbits.RD6
else if mask is 0x0004 return negation of PORTDbits.RD7
else if mask is 0x0002 return negation of PORTDbits.RA7
else if mask is 0x0001 return negation of PORTDbits.RD13
else return 0;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.