The program is suppose to detect what switch is turned on and from there change the traffic light to either red, yellow, or green. I'm stuck and I don't know if my initialization are right for Port A and Port E. we are only suppose to change the DEN and DIR. When I run it on debug, nothing happens. It's supposed to start with the red light.
// Input/Output:
// PE2 - Red
// PE1 - Yellow
// PE0 - Green
// PA3 - South
// PA2 - West
// Preprocessor Directives
#include <stdint.h>
#include "tm4c123gh6pm.h"
// Global Variables
uint8_t In0, In1;
uint8_t Out;
// Function Prototypes - Each subroutine defined
void Delay(void);
int main(void) {
// Initialize GPIO on Ports A, E
unsigned long int delay;
SYSCTL_RCGC2_R |= 0x11; // enables clock for e and a
delay = SYSCTL_RCGC2_R;
GPIO_PORTE_AMSEL_R = 0x00; //diables analog
GPIO_PORTE_AFSEL_R = 0x00; //disable alternate function
GPIO_PORTE_PCTL_R = 0x00000000; //enable GPIO
GPIO_PORTE_DEN_R = 0x07; // Ports E0-2
GPIO_PORTE_DIR_R = 0x07; //inputs PE0-2
GPIO_PORTA_AMSEL_R = 0x00; //disables analog
GPIO_PORTA_AFSEL_R = 0x00; //disable alternate function
GPIO_PORTA_PCTL_R = 0x00000000; //enable GPIO
GPIO_PORTA_DEN_R = 0x0C; // Ports A2 and A3
GPIO_PORTA_DIR_R = ~0x0C; //outputs PA2 and PA3
// Initial state: Red LED lit
Out = (GPIO_PORTE_DATA_R & 0x04); //red starting
while(1) {
In0 = GPIO_PORTA_DATA_R&0x08 ; // Read value of south
In1 = GPIO_PORTA_DATA_R&0x04 ; // read west
// Check the following conditions and set Out appropriately:
// If south is enabled and red LED is on, then red LED turns off and green LED turns on.
// If west is enabled and green LED is on, then green LED turns off and yellow LED turns on.
// If yellow LED is on, then yellow LED turns off and red LED turns on.
if ((In0 == 0x08) & ((Out&0x04) == 0x04)){ // south and red
GPIO_PORTE_DATA_R = 0x01; //green light turns on
Delay();
Out = GPIO_PORTE_DATA_R;
}
if ((In1== 0x04) & ((Out&0x01) == 0x01)){ //west and green
GPIO_PORTE_DATA_R = 0x02; //yellow light turns on
Delay();
Out = GPIO_PORTE_DATA_R;
}
if ((Out&0x02) == 0x02){ //if yellow
GPIO_PORTE_DATA_R = 0x04; //red light turns on
Delay();
Out = GPIO_PORTE_DATA_R;
}
Out = GPIO_PORTE_DATA_R;
// ??? = Out; // Update LEDs based on new value of Out
}
}
// Subroutine to wait about 0.1 sec
// Inputs: None
// Outputs: None
// Notes: the Keil simulation runs slower than the real board
void Delay(void) {
volatile uint32_t time;
time = 727240*200/91; // 0.1sec
while(time) {
time--;
}
}
are you sure about the direct register modifications?, try to double check if you are flipping the correct bits in registers. Also check what these hex values you writing are correct. Take a multi-meter and measure the voltage on the mentioned GPIO, does it change as supposed?, if not then either your electric circuitry has bug, or the inits().
User contributions licensed under CC BY-SA 3.0