Sometimes we want to monitor only a few bits of an input por

Sometimes, we want to monitor only a few bits of an input port. Also, sometimes we want to send an output to only one bit of a port. Discuss some of the ways that we can achieve these objectives.for this purpose. Mention some of them and illustrate how they are used.

Solution

Well there are too many families of MCU so i will answer for the Microchip of 8-bit MCU becuase is the most popular, your question doesnt tell me nothing about what MCU you are working it could be AVR, Arduino, ect there have different languages

Well for Microchip

There a registre call it TRISx

If we fill it with 1 is an input, if we fill it we 0 is an output

For the PORTA

TRISBbits.TRISB0 = 1; //RB0 is input pin
TRISBbits.TRISB1 = 1; //RB1 is input pin
TRISBbits.TRISB2 = 1; //RB2 is input pin
TRISEbits.TRISE1 = 1; //RE3 is input pin
TRISDbits.TRISD4 = 1; //RD4 is input pin
TRISDbits.TRISD5 = 1; //RD5 is input pin
TRISDbits.TRISD6 = 1; //RD6 is input pin
TRISAbits.TRISA4 = 0; //RA4 is output pin
TRISAbits.TRISA5 = 0; //RA5 is output pin

If we want to write in a bit port, we need to decalre this pin as an output before

To reada pin in a port we need to use the PORTx register

X=PORTA

That intrusccion read the values of the pins in of PORTA and save it to x

To write we use the LATX register

LATCbits.LATA5=1; //write one in that port
LATCbits.LATC4=0;//write zero in that port
LATCbits.LATC3=1; //write one in that port

Sometimes, we want to monitor only a few bits of an input port. Also, sometimes we want to send an output to only one bit of a port. Discuss some of the ways th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site