int32_t TimeOut;
// The error routine that is called if the driver library encounters an error.
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
/************************************************** Serial Functions ***************************/
// Check for a serial character
int32_t CheckForInputCharacter(void)
{
return (UART0_FR_R&0x0010);
}
// Wait for a serial character
unsigned char UARTInputCharacter(void)
{
int32_t InputCharacter;
// Wait until a character is received
while ((UART0_FR_R&0x0010) != 0);
// Read the input buffer
InputCharacter=UART0_DR_R&0xff;
return InputCharacter;
}
// Send a serial character
void UARTOutputCharacter(unsigned char OutputCharacter)
{
// wait until transmitter is ready
while ((UART0_FR_R&0x0020) != 0);
// Write data to the transmitter buffer
UART0_DR_R = OutputCharacter;
}
// Assumes a 50 MHz bus clock, creates 115200 baud rate
void UART_Init(void){
SYSCTL_RCGC1_R |= 0x0001; // activate UART0
// Run Mode Clock Gating Control Register 1
SYSCTL_RCGC2_R |= 0x0021; // activate port A and port F
UART0_CTL_R &= ~0x0001; // disable UART
UART0_IBRD_R = 27; // UART Integer Baud-Rate Divisor
// IBRD=int(50000000/(16*115,200)) = int(27.1267)
UART0_FBRD_R = 8; // UART Fractional Baud-Rate Divisor
// FBRD = int(0.1267 * 64 + 0.5) = 8
UART0_LCRH_R = 0x0070; // UART Line Control,8-bit length, enable FIFO
UART0_CTL_R = 0x0301; // enable RXE, TXE and UART
GPIO_PORTA_AFSEL_R |= 0x03; // alt funct on PA1-0
GPIO_PORTA_DEN_R |= 0x03; // digital I/O on PA1-0
}
// Setup the system clock to run at 50 Mhz from PLL with crystal reference
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
//to enable timer features
NVIC_ST_CTRL_R = 0;
//to specifies the start value to load into the timer
NVIC_ST_RELOAD_R = Scount;
//containds the current value of the timer
NVIC_ST_CURRENT_R = 0;
//enable /disable time
NVIC_ST_CTRL_R = 0x00000005;
while ((NVIC_ST_CTRL_R&0x10000)==0){}
}
void LEDon (int32_t LED)
{
GPIOPinWrite(GPIO_PORTF_BASE, 0x0e, LED);
}
void Initialize (void)
{
// Enable and configure the GPIO port for the LED and switches operation.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
int main()
{
//a. Declare a counter variable and initialize it to zero.
int32_t Count = 0;
Initialize();
UART_Init();
//c. Initialize the timer to delay 200 ms.
SysTickDelay(T200ms);
// b.Write a loop to increment the counter and reset it to 0 on the next increment after
//255
while(1)
{
if(Count > 255)
Count = 0;
if(TimeOut == 1)
/*d. In a loop:
i. Wait for the TimeOut flag to be set to be set
ii. Clear the TimeOut flag
iii. Iincrement the counter
iv. Call SysTickInit to set the next count to 200 ms times the lower three bits
of the current count. For example, if the count is seven, the time period
will be 1400 ms.
v. Turn on the LEDs.
vi. Output the current count value to the serial port, then output a carriage
return.
*/