int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1SEL = 0; //
P1SEL2 = 0; // Input/Output function is selected
P2SEL = 0; //
P2SEL2 = 0; //
P1DIR = 0x00; // P1.3 & P1.4 are used for input, so lazy so I set 0 for entire Port 1
P2DIR = 0xFF; // Port 2 is used for LEDs
P1REN = 0x18; // Turn on pull up resistor P1.3 & P1.4
/******* LEDs show ******/
for (i=0;i<8;i++)
{
P2OUT = ~(0x01<<i);
__delay_cycles(50000);
}
for (i=0;i<8;i++)
{
P2OUT = ~(0x80>>i);
__delay_cycles(50000);
}
for (i=0;i<8;i++)
{
P2OUT = ~(0x01<<i);
__delay_cycles(50000);
}
for (i=0;i<8;i++)
{
P2OUT = ~(0x80>>i);
__delay_cycles(50000);
}
/**** End of LEDs Show *****/
P2OUT = ~(0x10); // Turn on center leds
i = 4; // and ready for button
while(1) // loop forever
{
if ((P1IN & 0x10) == 0) // Button P1.4 is being pressed
i++;
if ((P1IN & 0x08) == 0) // Button P1.3 is being pressed
i--;
if (i == -1) // Scroll
i = 7;
if (i == 8)
i = 0;
P2OUT = ~(0x01 << i);
__delay_cycles(100000); // Chong rung phim
}
}