/* * Toggle PTC6-3 in C programming language for FRDM-KL25Z * with Wytec EduBase. On Wytec EduBase board, PTC6-3 are connected * to the four LEDs. * Default clock 41.94MHz is used. */ #include "MKL25Z4.h" void delayMs(int n); int main(void) { /* enable PTC 6-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 |= 0x78; /* make PTC6-3 as output pin */ for (;;) { PTC->PCOR = 0x50; /* turn off PTC6, 4 */ PTC->PSOR = 0x28; /* turn on PTC5, 3 */ delayMs(500); PTC->PCOR = 0x28; /* turn off PTC5, 3 */ PTC->PSOR = 0x50; /* turn on PTC6, 4 */ delayMs(500); } } // delay n milliseconds (41.94MHz CPU clock) void delayMs(int n) { int i, j; for(i = 0 ; i < n; i++) for(j = 0; j < 7000; j++) {} /* do nothing */ }