PORT_Init(); // Initialize Port I/O
OSCILLATOR_Init (); // Initialize Oscillator
while (1)
{
if (S1 == 0) // If switch depressed
{
D1 = 1; // Turn on LED
}
else
{
D1 = 0; // Else, turn it off
}
if (S2 == 0) // If switch depressed
{
D2 = 1; // Turn on LED
}
else
{
D2 = 0; // Else, turn it off
}
if (S3 == 0) // If switch depressed
{
D3 = 1; // Turn on LED
}
else
{
D3 = 0; // Else, turn it off
}
if (S4 == 0) // If switch depressed
{
D4 = 1; // Turn on LED
}
else
{
D4 = 0; // Else, turn it off
}
} // end of while(1)
} // end of main()
void OSCILLATOR_Init (void)
{
OSCICN |= 0x03; // Configure internal oscillator for
// its maximum frequency (24.5 Mhz)
}
void PORT_Init (void)
{
P2MDIN |= 0xF0; // Lower four pins on P2 are digital
P2MDOUT = 0x0F; // enable LEDs as push-pull outputs
// enable Switches as open-drain
P2 |= 0xF0; // Set port latches for P2.0
// and P2.1 to '1'