0
1.2kviews
Write a language program to read P2 and P3. Shift the bits of P2 to right by two bits and P3 to left by four bits. Store the content of P2 to P0 and P3 to P1.
1 Answer
written 5.6 years ago by | • modified 5.6 years ago |
The program
#include< regx51.h>
void main(void)
{
unsigned char a,b;
P2=0xFFH; $ \ \ \ \ \ \ \ $ //set port 2 as an input
P3=0xFFH; $ \ \ \ \ \ \ \ $//set port 1 as an input
a=P2; $ \ \ \ \ \ \ \ $ //read status of bits from P2
b=P3; $ \ \ \ \ \ \ \ $//read status of bits from P3
a=a>>3; $ \ \ \ \ \ \ \ $ //shift P2 bits to right by 3 bits
P0=a; $ \ \ \ \ \ \ \ $ //send to port 0
b=b>>4; $ \ \ \ \ \ \ \ $ //shift P3 bits to left by 4 bits
P1=b; $ \ \ \ \ \ \ \ $ //send to port 1
}