/* p2_1.c Toggling LED in C using registers by addresses * This program toggles green LED for 0.5 second ON and 0.5 second OFF. * The green LED is connected to PTB19. * The LEDs are low active (a '0' turns ON the LED). */ /* System Integration Module System Clock Gating Control Register 5*/ #define SIM_SCGC5 (*((volatile unsigned int*)0x40048038)) /* Port B Pin Control Register 19*/ #define PORTB_PCR19 (*((volatile unsigned int*)0x4004A04C)) /* Port B Data Direction Register */ #define GPIOB_PDDR (*((volatile unsigned int*)0x400FF054)) /* Port B Data Output Register */ #define GPIOB_PDOR (*((volatile unsigned int*)0x400FF040)) int main (void) { void delayMs(int n); SIM_SCGC5 |= 0x400; /* enable clock to Port B */ PORTB_PCR19 = 0x100; /* make PTB19 pin as GPIO (See Table 2-4) */ GPIOB_PDDR |= 0x80000; /* make PTB19 as output pin */ while (1) { GPIOB_PDOR &= ~0x80000; /* turn on green LED */ delayMs(500); GPIOB_PDOR |= 0x80000; /* turn off green LED */ delayMs(500); } } /* Delay n milliseconds * The CPU core clock is set to MCGFLLCLK at 41.94 MHz in SystemInit(). */ void delayMs(int n) { int i; int j; for(i = 0 ; i < n; i++) for (j = 0; j < 7000; j++) {}