question about a program code

i have this code need to get to work what i should do


#include <stdint.h>
#include <stdbool.h>

#include "C:/ti/TivaWare_C_Series-1.1/inc/hw_types.h"
#include "C:/ti/TivaWare_C_Series-1.1/inc/hw_memmap.h"
#include "C:/ti/TivaWare_C_Series-1.1/driverlib/sysctl.h"
#include "C:/ti/TivaWare_C_Series-1.1/driverlib/gpio.h"
#include "C:/ti/TivaWare_C_Series-1.1/inc/hw_gpio.h"
#include "C:/ti/TivaWare_C_Series-1.1/inc/tm4c123gh6pge.h"

// Define pin to LED color mapping.

#define RED_LED GPIO_PIN_1
#define BLUE_LED GPIO_PIN_2
#define GREEN_LED GPIO_PIN_3
#define B2 GPIO_PIN_0
#define B1 GPIO_PIN_4

//Define counts for time periods clock tick is 20ns
#define T50ms 50000000/20
#define MAXcount 0x00ffffff
#define T750ms 750000000/20
#define T300ms 300000000/20
#define T500ms 500000000/20
#define T200ms 200000000/20




void SysTickDelay (int32_t );
void LEDon (int32_t );

void Initialize (void);


unsigned char UARTInputCharacter(void);
void UARTOutputCharacter(unsigned char OutputCharacter);
void UART_Init(void);
void TimerISR(void);

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
}



/**********************************************************************************************/


void SysTickDelay (int32_t Scount)
{


// 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);

GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED);

//to unlock the GPIO at portF
HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_BASE+GPIO_O_CR) = 0x11;


GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, B1|B2);

GPIOPadConfigSet(GPIO_PORTF_BASE, B1|B2 , GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

}



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.
*/

while(TimeOut == 1)
{
Count++;

}
TimeOut = 0;
SysTickDelay((T200ms) *Count );
LEDon(RED_LED);
LEDon( GREEN_LED);
LEDon( BLUE_LED);
UARTOutputCharacter(Count);
UARTOutputCharacter('\n');
}

}

void TimerISR(void)
{
if (TimeOut)
TimeOut=0;
else
TimeOut=1;
}




Topic archived. No new replies allowed.