Professional Documents
Culture Documents
Module
LEDs.c
Revision
1.0.1
Description
This is a template file for implementing a simple service under the
Gen2 Events and Services Framework.
Notes
History
When Who
--------------------
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include <stdio.h>
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_Port.h"
#include "ES_DeferRecall.h"
#include "ES_Timers.h"
#include "termio.h"
#include "BITDEFS.h" // standard bit definitions to make things more readable
//Time define
//#define TicksPerMS 40000 //use system clock
//#define OneShotTimeout 100 * TicksPerMS // 100 ms
//#define PeriodMinTicks 10000
//#define PeriodMaxTicks 45000
void InitLEDs(void)
{
//Init TEAM LEDs
//Initialize PB2 - PB3 to be digital outputs
HWREG(SYSCTL_RCGCGPIO)|= SYSCTL_RCGCGPIO_R1; // Port B
while ((HWREG(SYSCTL_RCGCGPIO) & SYSCTL_RCGCGPIO_R1) != SYSCTL_RCGCGPIO_R1);
HWREG(GPIO_PORTB_BASE+GPIO_O_DEN)|= ( BIT2HI | BIT3HI );
HWREG(GPIO_PORTB_BASE+GPIO_O_DIR)|= ( BIT2HI | BIT3HI );
//Turn off LEDs at initialization by writing LO to BIT2 and BIT3
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT2LO;
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT3LO;
void TurnOffLEDs(void){
//Turn off LEDs by writing LO to PB2, PB3 & PF4
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT2LO;
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT3LO;
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT4LO;
}
void TurnOnRLED(void){
//Turn on Red LED by writing HI to PB2
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT2HI;
}
void TurnOnBLED(void){
//Turn on Blue LED by writing HI to PB3
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT3HI;
}
void TurnOnYLED(void){
//Turn on game indicator LED by writing HI to PF4
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT4HI;
}
int GetTeamColor(void){
//read PF3
//if PF3 is HI, return RED (1), otherwise return BLUE (0)
if( (HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) & BIT3HI) == BIT3HI) return
RED;
return BLUE;
}
/*------------------------------- Footnotes -------------------------------*/
/*------------------------------ End of file ------------------------------*/