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

please answer the questions correctly with all parts it\'s very important, thank

ID: 2083335 • Letter: P

Question

please answer the questions correctly with all parts it's very important, thanks in advance :)

An embedded system is designed to communicate with an external device using an 8-bit port declared as variable portA. Write 'C' code to interact with the pins of portA as follows: wait until pin 0 and 7 go high toggle pin 6 set pins 1 and 2 What do the following C lines do? portA &= 0xFE; while (! (PortA & 0200)); while ((PortA & 0x04) = 0); if (PortA & 0x01) printf ("device is enabled");

Explanation / Answer

(A)

#include <reg51.h>

sbit mybit1 = portA^0 ; #notice the way to single bit is declared  

sbit mybit1 = portA^7 ;

sbit toggle = portA^6 ;

sbit pin1 = portA^1 ;

sbit pin2 = portA^2 ;

void main(void)

{

while(1)

{

if(mybit1 ==1 && mybit2 == 1) #waiting for bist 0 and 7 ate high

{

# Code for toggle 6 bit

if ( toggle == 1)   

toggle = 0 ;

else

toggle = 1;

#code for set 1 and 2 pins

pin1 =1 ;

   pin2 = 1 ;

}

}

}

(b)   

(i) portA &= 0XFE ;

   it means portA = portA & 0XFE 0xFE = 1111 1110 in binary

the portA is AND operation with 1111 1110 and the result is stored into the portA

(ii) while(!(portA & 0200) ) ;

The while loop exute until the the result of AND operation between portA and 0200 is TRUE

if the Result is TRUE, the while condition will be FALSE

(iii) while( (portA & 0X04) == 0) ;

first portA AND operation with 0000 0100(i.e 0X04)

and the result is FALSE(0000 0000) the while condition is TRUE

the while loop excute until the While condition will be FALSE

(iv) if (portA & 0X01) printf("device is enabled") ;

if the the result of AND operation portA and 0000 0001 (i.e 0X01 ) is TRUE(other than the 0) it will print "device is enabled" text

Thanku