Hello Jeremie:
When you create a new bareboard project, the included MCU header file (e.g. MK20D50.h) already contains helpful macros to manage your pins. Please check the video in the next link:
Video Link : 1460
So, the definitions you'd want to create would be something like:
#define PIN0 (1<<0)
#define PIN1 (1<<1)
//...
#define PIN7 (1<<7)
//...
// Then you can use those definitions as next examples (e.g. port C):
// Enable the clock for the desired port:
SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;
// Configure the pins as GPIO, using the mux macro:
PORTC_PCR2 = PORT_PCR_MUX(1); // Pin function alternative '1' is GPIO
PORTC_PCR7 = PORT_PCR_MUX(1);
// To configure pin 7 as output and pin 2 as input:
GPIOC_PDDR |= PIN7;
GPIOC_PDDR &= ~PIN2;
// To set pin 7:
GPIOC_PSOR |= PIN7;
//or
GPIOC_PDOR |= PIN7;
// To clear pin 7:
GPIOC_PCOR |= PIN7;
//or
GPIOC_PDOR &= ~PIN7;
// For reading pin 2:
temp_var = GPIOC_PDIR & PIN2;
You can also find non-processor expert based examples in the next links:
TWR-K20D50M (KINETIS_50MHZ_SC):
TWR-K20D50M Product Summary Page
TWR-K20D72M (TWR-K20D72M_LAB):
TWR-K20D72M Product Summary Page
Hope this is useful :smileyhappy:
/Jorge Gonzalez