In: Computer Science
Q8. If the bits 0 and 2 of P1IN are set, then toggle all the bits of P1OUT simultaneously except the bit 4, else toggle only the bit 4 of P1OUT.
Hello,
#include <msp430g2553.h>
volatile unsigned int i = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= BIT0;
// P1.0 output, BIT0 is
define as (0x0001) in the header file
P1OUT &= ~BIT0;
// P1.0 output LOW, LED Off
P1DIR |= BIT6;
// P1.6 output
P1OUT &= ~BIT6;
// P1.6 output LOW, LED Off
for (;;)
{
P1OUT ^= BIT0 + BIT6; // Toggle LED
at P1.0 and P1.6
// Here BIT1 and BIT6 added
and relevant two bits will be toggled
for(i=0; i< 20000;
i++); // Delay between LED toggles.
}
}
If you find this answer useful, please upvote