I am trying to write two programs 1) is going to write 4 bits of a number to 4 pins in one port and the second 4 bits in the second port 2) read these bits. Where I am stuck is how to write and read individual pins, maybe I am missing some documentation but I can't seem to figure this out.
I have port D and E initialized as follows below:
If someone could point me in the right direction on where to read up on this or correct my intializations I would appreciate it. Thanks.
void PortDInit(void) {
volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // 1) D clock
delay = SYSCTL_RCGC2_R; // delay
GPIO_PORTD_LOCK_R = 0x4C4F434B; // 2) unlock PortD
GPIO_PORTD_CR_R |= 0x14; // allow changes to PF4 (SW1) and PF2 (Blue LED)
GPIO_PORTD_AMSEL_R = 0x00; // 3) disable analog function
GPIO_PORTD_PCTL_R = 0x00; // 4) GPIO clear bit PCTL
GPIO_PORTD_DIR_R &=~ 0x07; // 5) PD2, PD1, PD0 for output
// PF2 (Blue LED) is output
GPIO_PORTD_AFSEL_R = 0x00; // 6) no alternate function
GPIO_PORTD_PUR_R |= 0x10; // enable pullup resistor on PF4
GPIO_PORTD_DEN_R |= 0x14; // 7) enable digital pins PF4, PF2
}
//initalizes portE
void PortE_Init(void){
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000010; // 1) E clock
delay = SYSCTL_RCGC2_R; // delay
GPIO_PORTE_CR_R = 0x2F; // allow changes to PE5,3-0
GPIO_PORTE_AMSEL_R = 0x00; // 3) disable analog function
GPIO_PORTE_PCTL_R = 0x00000000; // 4) GPIO clear bit PCTL
GPIO_PORTE_DIR_R |= 0x08; // 5) PE3 input
GPIO_PORTE_DIR_R &=~ 0x07; // 5) PE2,PE1,PE0 output
GPIO_PORTE_AFSEL_R = 0x00; // 6) no alternate function
GPIO_PORTE_PUR_R = 0x08; // enable pullup resistors on PE3
GPIO_PORTE_DEN_R = 0x0F; // 7) enable digital pins PE3-PE0