In: Electrical Engineering
Write instruction(s) in C to get bits 4 and 7 of Port-C, then compute the “XOR (exclusive OR)” of these two bits and write the result of the “XOR operation” to bit 4 of Port-D.
As you haven't notified the Microcontroller's name and mentioned about PortC and PortD, I assume that you are talking about the PIC controller. The code for which is explained below.
#include<> //Add the appropriate PIC header file, corresponding to the one you are using.
void main()
{
ANSEL=0; // For configuring the pins as digital pins
ANSELH=0;
PORTC =0; //Clearing the C pins
TRISC=0xFF; //Configuring PORTC as input port
PORTD=0; //Clearing D pins
TRIS D=0b1110111; //Configuring PORTD's pin 4 as output
sbit A at RC4_bit; // Getting 4th pin of PortC
sbit B at RC7_bit; // Getting 7th pin of PortC
sbit C at RD4_bit; // Accessing 4th pin of Port D
C= A^B; //Bitwise XOR operator is used
}
Keep in mind that TRIS pin has to be set to 0 or 1 to set the port as output or input respectively.
After which you have to access the individual bits and perform required actions on them.
Even if it is a different microcontroller, Follow similar steps to arrive at your answer. The syntax may change but the concept is the same.
Hope you understood the solution :)