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

1. (10 pts) GPIO A design requires Ports A, B and F .outputs: PAO (Port A\'s Pin

ID: 2293006 • Letter: 1

Question

1. (10 pts) GPIO A design requires Ports A, B and F .outputs: PAO (Port A's Pin 0), PA6, PF1 and PF2 inputs: PBI and PB3. Two switches swl and sw2 are wired in positive-logic to PBl and PB3, respectively (a) (5pts) Write C code that initialize all pins. No analog feature, no alternative functions, but only digital feature for all pins. (b) (Spts) Write code for main function including while loop that checks if both swl and sw2 are pressed and hold at the same time. If they are, system turns on PA6 and PF1 and turns off PAO and PF2. Otherwise, system turns off PAO and toggle PA6, PF1 and PF2

Explanation / Answer

a) To declare a pin as input it is made 0 and to declare as output it is made 1

C code for initialising the pins -

sbit PA0=1; sbit PA6=1; sbit PF1=1; sbit PF2=1; //declaring as output

sbit PB1=0; sbit PB3=0; //declaring as input

b) Code for main function-

void main(){

while (1){

if(PB1==1&&PB3==1){

msdelay(100); //calling a delay function to create 100ms delay

if(PB1==1&&PB3==1){

PA6=1;PF1=1;PA0=0;PF2=0;

}

else {

PA0=0;

PA6=!PA6; //Toggling pins

PF1=!PF1;

PF2=!PF2;

}

}

}

}