/* * Read switches and use the data to set LEDs for FRDM-KL25Z * with Wytec EduBase. On Wytec EduBase board, PTC6-3 are connected * to the four LEDs and PTC13-10 are connected to both the DIP switches (SW1) * and the pushbuton switches (SW2-SW5). * In order for the pushbutton switches to be effective, the DIP switches * must be at the off position. */ #include int main(void) { unsigned int data; /* enable PTC6-3 as output for LEDs */ SIM->SCGC5 |= 0x800; /* enable clock to Port C */ PORTC->PCR[3] = 0x100; /* make PTC3 pin as GPIO */ PORTC->PCR[4] = 0x100; /* make PTC4 pin as GPIO */ PORTC->PCR[5] = 0x100; /* make PTC5 pin as GPIO */ PORTC->PCR[6] = 0x100; /* make PTC6 pin as GPIO */ PTC->PDDR |= 0x0078; /* make PTC6-3 as output pin */ /* enable PTC13-10 as input for switches */ PORTC->PCR[10] = 0x100; /* make PTC10 pin as GPIO */ PORTC->PCR[11] = 0x100; /* make PTC11 pin as GPIO */ PORTC->PCR[12] = 0x100; /* make PTC12 pin as GPIO */ PORTC->PCR[13] = 0x100; /* make PTC13 pin as GPIO */ PTC->PDDR &= ~0x3C00; /* make PTC13-10 as input pin */ for (;;) { data = PTC->PDIR; /* read the switches */ PTC->PDOR = data >> 7; /* and write to LEDs */ } }