Example #1
1
int main(void)
{
	volatile uint32_t ui32Load;
	volatile uint32_t ui32PWMClock;
	volatile uint8_t ui8Adjust;
	ui8Adjust = 254;

	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
	GPIOPinConfigure(GPIO_PF1_M1PWM5);

	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
	GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN);
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_2);

	while(1)
	{

		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00)
		{
			ui8Adjust--;
			if (ui8Adjust < 10)
			{
				ui8Adjust = 10;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
		}

		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00)
		{
			ui8Adjust++;
			if (ui8Adjust > 254)
			{
				ui8Adjust = 254;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
		}

		SysCtlDelay(100000);
	}

}
//*****************************************************************************
//
//! Sets the value of the RTC match 0 register.
//!
//! \param ulMatch is the value for the match register.
//!
//! Sets the match 0 register for the RTC.  The Hibernation module can be
//! configured to wake from hibernation, and/or generate an interrupt when the
//! value of the RTC counter is the same as the match register.
//!
//! \return None.
//
//*****************************************************************************
void
HibernateRTCMatch0Set(unsigned long ulMatch)
{
    //
    // Write the new match value to the match register.
    //
    HWREG(HIB_RTCM0) = ulMatch;

    //
    // Add a delay here to enforce the required delay between write accesses to
    // certain Hibernation module registers.
    //
    if(CLASS_IS_FURY)
    {
        //
        // Delay a fixed time on Fury-class devices
        //
        SysCtlDelay(g_ulWriteDelay);
    }
    else
    {
        //
        // Wait for write complete to be signaled on later devices.
        //
        HibernateWriteComplete();
    }
}
void
UTUtilsDelayCycles(unsigned long ulTimeoutCycles)
{
    //
    // Call the assembler delay function to spin uselessly for the desired
    // period of time.
    //
#ifdef ENABLE_PREFETCH
    SysCtlDelay((ulTimeoutCycles * PREFETCH_FUDGE_NUM)/
                (DELAY_LOOP_INSTRUCTIONS * PREFETCH_FUDGE_DEN));
#else
    SysCtlDelay(ulTimeoutCycles / DELAY_LOOP_INSTRUCTIONS);
#endif

    return;
}
Example #4
0
/**
 * Configures the temperature sensor for continuous read mode and reads the
 *  status register
 *  Utilizes SSI0
 *
 *  \param statusreg - A pointer to store the status information that is read
 **/
void temp_configSensorContinuousRead(uint32_t *statusreg) {
	uint32_t commandWriteConfigReg  = 0x00000C01;
	uint32_t commandReadStatusReg   = 0x00000040; // 0b01000000
	uint32_t commandReadStatusEmpty = 0x00000000;
	uint32_t trashBin[2];

	// Setup Configuration Register (register address: 0x01
	SSIDataPut(SSI0_BASE, commandWriteConfigReg);
	SSIDataPut(SSI0_BASE, commandReadStatusEmpty);
	// SysCtlDelay(4170000); // (3 cycles/loop) * (1/50MHz) * (4170000 loop cycles) = 250.2ms

	// Read any residual data from the SSI port.  This makes sure the receive
	// FIFOs are empty, so we don't read any unwanted junk.  This is done here
	// because the SPI SSI mode is full-duplex, which allows you to send and
	// receive at the same time.  The SSIDataGetNonBlocking function returns
	// "true" when data was returned, and "false" when no data was returned.
	// The "non-blocking" function checks if there is any data in the receive
	// FIFO and does not "hang" if there isn't.
	while(SSIDataGetNonBlocking(SSI0_BASE, &trashBin[0]))
	{
	}

	// Read status register (Address: 0x0)
	SSIDataPut(SSI0_BASE, commandReadStatusReg);
	SSIDataGet(SSI0_BASE, &trashBin[1]);
	SSIDataPut(SSI0_BASE, commandReadStatusEmpty);
	SSIDataGet(SSI0_BASE, statusreg);

	//Need to adjust for different processor frequencies
	SysCtlDelay(4170000); // (3 cycles/loop) * (1/50MHz) * (4170000 loop cycles) = 250.2ms
}
Example #5
0
void SampleLightCO(void){
	
	unsigned long ulADC0_Value[1];
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
	ADC_CTL_END);
	ADCSequenceEnable(ADC0_BASE, 3);
	ADCIntClear(ADC0_BASE, 3);

	while(1){
		ADCProcessorTrigger(ADC0_BASE, 3);
		while(!ADCIntStatus(ADC0_BASE, 3, false)){
		}
		ADCIntClear(ADC0_BASE, 3);
		ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value);
		
		Log("Breath Level = ");
		LogD(ulADC0_Value[0]);
		Log("\r");

		SysCtlDelay(SysCtlClockGet() / 12);
	}
}
Example #6
0
void uartprinntf()
{
    //
    // Initionalize system clock.
    //
    xSysCtlPeripheralClockSourceSet( 10000000,  xSYSCTL_XTAL_6MHZ );
 
    SysCtlDelay(10000);

    xSPinTypeUART(UART0RX,PB0);
    xSPinTypeUART(UART0TX,PB1);

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART_S_EXT12M);

    //
    // Config 8 bit word length, 1 stop bit, 
    // and none parity bit, receive FIFO 1 byte.
    //
    UARTConfigSetExpClk(UART0_BASE, 115200, (UART_CONFIG_WLEN_8 | 
                                             UART_CONFIG_STOP_ONE | 
                                               UART_CONFIG_PAR_NONE));

    UARTEnable(UART0_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));

    UARTBufferWrite(UART0_BASE, "NUC1xx.UART.BAUDRATE EXAMPLE \r\n", sizeof("NUC1xx.UART.BAUDRATE EXAMPLE \r\n")); 
}
Example #7
0
//*****************************************************************************
//
//! \internal
//!
//! Write a sequence of bytes to the SSD0303 or SD1300 controller.
//!
//! This function continues a transfer to the display controller by writing a
//! sequence of bytes over the I2C bus.  This must only be called after calling
//! Display96x16x1WriteFirst(), but before calling Display96x16x1WriteFinal().
//!
//! The data is written in a polled fashion; this function will not return
//! until the entire byte sequence has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
Display96x16x1WriteArray(uint8_t const *pucBuffer, uint32_t ulCount)
{
    //
    // Loop while there are more bytes left to be transferred.
    //
    while(ulCount != 0)
    {
        //
        // Wait until the current byte has been transferred.
        //
        while(I2C0_MASTER->MRIS == 0)
        {
        }

        //
        // Provide the required inter-byte delay.
        //
        SysCtlDelay(g_ulDelay);

        //
        // Write the next byte to the controller.
        //
        I2C0_MASTER->MDR = *pucBuffer++;
        ulCount--;

        //
        // Continue the transfer.
        //
        I2C0_MASTER->MCS = I2C_MASTER_CMD_BURST_SEND_CONT;
    }
}
Example #8
0
//*****************************************************************************
//
//! \internal
//!
//! Write a byte to the SSD0303 or SSD1300 controller.
//!
//! \param ucChar is the byte to be transmitted to the controller.
//!
//! This function continues a transfer to the display controller by writing
//! another byte over the I2C bus.  This must only be called after calling
//! Display96x16x1WriteFirst(), but before calling Display96x16x1WriteFinal().
//!
//! The data is written in a polled faashion; this function will not return
//! until the byte has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
Display96x16x1WriteByte(uint8_t ucChar)
{
    //
    // Wait until the current byte has been transferred.
    //
    while(I2C0_MASTER->MRIS == 0)
    {
    }

    //
    // Provide the required inter-byte delay.
    //
    SysCtlDelay(g_ulDelay);

    //
    // Write the next byte to the controller.
    //
    I2C0_MASTER->MDR = ucChar;

    //
    // Continue the transfer.
    //
    I2C0_MASTER->MCS = I2C_MASTER_CMD_BURST_SEND_CONT;
}
Example #9
0
void BPMTimerSetUp()
{
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // timer 0
	SysCtlDelay(3);
	 //
	// Enable processor interrupts.
	//

	//IntPrioritySet(INT_TIMER0A_TM4C123, 2);
	//
	// Configure the two 32-bit periodic timers.
	//
	ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
	ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/500);
	//ROM_SysCtlClockGet()/100000
	//ROM_SysCtlClockGet()/500

	// Setup the interrupts for the timer timeouts.
    ROM_IntEnable(INT_TIMER0A);
    ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    //
	// Enable the timers.
	//
	ROM_TimerEnable(TIMER0_BASE, TIMER_A);
	
}
Example #10
0
int main(void) {
    SysCtlClockSet(
    SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000);

    ADCSequenceDisable(ADC0_BASE, 1);
    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 3,
    ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 1);

    UARTprintf("This is ADC examlpe");

    while (1) {
        UARTprintf("Temperature is: %d \210 C\n", ADC_getVal());
        SysCtlDelay(40000000 / 3);
    }
}
Example #11
0
int main(void) {
	SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_SYSDIV_5| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
	ADCSequenceEnable(ADC0_BASE, 1);
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

	ledPinConfig();
	while (1)
	{
		Test2();
		//print_temc();
		SysCtlDelay(SysCtlClockGet()/3);

	}
}
Example #12
0
File: main.c Project: AlexGora/cox
int main(void)
{
	unsigned char i;
	xSysCtlClockSet(16000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
//	xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);


	SensorShieldInit();
	SensorShieldIOInit();

    xGPIOSPinDirModeSet(SENSOR_SHIELD_I0, xGPIO_DIR_MODE_IN);
    xGPIOSPinDirModeSet(SENSOR_SHIELD_I1, xGPIO_DIR_MODE_IN);
    xGPIOSPinDirModeSet(SENSOR_SHIELD_I2, xGPIO_DIR_MODE_IN);
    xGPIOSPinIntEnable(SENSOR_SHIELD_I0, xGPIO_RISING_EDGE);
    xGPIOSPinIntEnable(SENSOR_SHIELD_I1, xGPIO_RISING_EDGE);
    xGPIOSPinIntEnable(SENSOR_SHIELD_I2, xGPIO_RISING_EDGE);
    xGPIOSPinIntCallbackInit(SENSOR_SHIELD_I0, Key1Callback);
    xGPIOSPinIntCallbackInit(SENSOR_SHIELD_I1, Key2Callback);
    xGPIOSPinIntCallbackInit(SENSOR_SHIELD_I2, Key3Callback);
    xIntEnable(xINT_GPIOB);
    xIntEnable(xINT_GPIOB);

	SensorShieldOutWrite(SENSOR_SHIELD_O0, 1);
	SensorShieldOutWrite(SENSOR_SHIELD_O1, 1);
	SensorShieldOutWrite(SENSOR_SHIELD_O2, 1);
	SensorShieldOutWrite(SENSOR_SHIELD_O3, 1);
	SensorShieldOutWrite(SENSOR_SHIELD_O4, 1);
	SensorShieldOutWrite(SENSOR_SHIELD_O5, 1);

    while(1)
    {
    	if(key2)
    	{
    		key2 = 0;
    		for(i=0;i<10;i++){
    		SensorShieldOutWrite(SENSOR_SHIELD_O0, 1);
    		SensorShieldOutWrite(SENSOR_SHIELD_O1, 1);
    		SensorShieldOutWrite(SENSOR_SHIELD_O2, 1);
    		SysCtlDelay(1000000);
    		SensorShieldOutWrite(SENSOR_SHIELD_O0, 0);
    		SensorShieldOutWrite(SENSOR_SHIELD_O1, 0);
    		SensorShieldOutWrite(SENSOR_SHIELD_O2, 0);
    		SysCtlDelay(1000000);
    		}
    	}
    }
}
void _EncoderInit(){
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
	SysCtlDelay(1);

	HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= 0x80;

	//Set Pins to be PHA0 and PHB0
	GPIOPinConfigure(GPIO_PD6_PHA0);
	GPIOPinConfigure(GPIO_PD7_PHB0);

	GPIOPinTypeQEI(GPIO_PORTD_BASE, GPIO_PIN_6 |  GPIO_PIN_7);


	QEIDisable(QEI0_BASE);
	QEIIntDisable(QEI0_BASE,QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX);

	QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B  | QEI_CONFIG_NO_RESET 	| QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 1000);
	QEIVelocityConfigure(QEI0_BASE,	QEI_VELDIV_1,80000000/12);
	QEIEnable(QEI0_BASE);
	QEIVelocityEnable(QEI0_BASE);
	//Set position to a middle value so we can see if things are working
	QEIPositionSet(QEI0_BASE, 500);


	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
	SysCtlDelay(1);

	//Set Pins to be PHA0 and PHB0
	GPIOPinConfigure(GPIO_PC5_PHA1);
	GPIOPinConfigure(GPIO_PC6_PHB1);

	GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 |  GPIO_PIN_6);


	QEIDisable(QEI1_BASE);
	QEIIntDisable(QEI1_BASE,QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX);

	QEIConfigure(QEI1_BASE, (QEI_CONFIG_CAPTURE_A_B  | QEI_CONFIG_NO_RESET 	| QEI_CONFIG_QUADRATURE | QEI_CONFIG_SWAP), 1000);
	QEIVelocityConfigure(QEI1_BASE,	QEI_VELDIV_1,80000000/12);
	QEIEnable(QEI1_BASE);
	QEIVelocityEnable(QEI1_BASE);
	//Set position to a middle value so we can see if things are working
	QEIPositionSet(QEI1_BASE, 500);
}
Example #14
0
//*****************************************************************************
//
// Configure the USB controller and power the bus.
//
// This function configures the USB controller for host operation.
// It is assumed that the main system clock has been configured at this point.
//
// \return None.
//
//*****************************************************************************
void
ConfigureUSBInterface(void)
{
    //
    // Enable the uDMA controller and set up the control table base.
    // This is required by usblib.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    uDMAEnable();
    uDMAControlBaseSet(g_sDMAControlTable);

    //
    // Enable the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Set the USB pins to be controlled by the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN);
    ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Register the host class driver
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, NUM_CLASS_DRIVERS);

    //
    // Open an instance of the mass storage class driver.
    //
    g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Force the USB mode to host with no callback on mode changes since
    // there should not be any.
    //
    USBStackModeSet(0, eUSBModeForceHost, 0);

    //
    // Wait 10ms for the pin to go low.
    //
    SysCtlDelay(SysCtlClockGet()/100);

    //
    // Initialize the host controller.
    //
    USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);
}
Example #15
0
int getDistance()
{
	int i,j;
	float lat_proper; //These store the properly formatted lat/longs in decimal.
	float long_proper;
	LCDWriteText("Locating...     ", 0, 0);
	LCDWriteText("                ", 1, 0);

#ifdef EASYOPEN //Untested, should work.
	int open=true;
	for(int i=0;i<3000;i++)
	{
		if (GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)!=0) {open = false;}
	}
	if (open == true) {return 0;}
#endif

	for (i = 0;i<TIMEOUT;i++) //for TIMEOUT seconds of trying
	{
		if (haveFix == 1)
		{
			//This should all work - the values given are reasonable, but needs to be tested outside.
			lat_proper = 10*(latitude[0]-ATD)+latitude[1]-ATD;
			lat_proper += ((float)(10*(latitude[2]-ATD) + latitude[3]-ATD))/60.0;

			long_proper = 10*(longitude[1]-ATD)+longitude[2]-ATD;
			long_proper += ((float)(10*(longitude[3]-ATD)+longitude[4]-ATD))/60.0;

			for (j=0;j<5;j++)
			{
				lat_proper += ((float)(latitude[5+j]-ATD) /(600.0 * (float)(10^j)));
				long_proper += ((float)(longitude[6+j]-ATD) /(600.0 * (float)(10^j)));
			}
			if (neglat){lat_proper = -lat_proper;}
			if (neglong){long_proper = -long_proper;}

			double dlat1=lat_proper*(M_PI/180);

			double dlong1=long_proper*(M_PI/180);
			double dlat2 = FINALLAT * (M_PI/180);
			double dlong2= FINALLONG * (M_PI/180);

			double dLong=dlong1-dlong2;
			double dLat=dlat1-dlat2;

			double aHarv= pow(sin(dLat/2.0),2.0) + cos(dlat1)*cos(dlat2)*pow(sin(dLong/2),2);
			double cHarv=2*atan2(sqrt(aHarv),sqrt(1.0-aHarv));
			//double distance=EARTHRADIUS*cHarv;
			haveFix = 0;
			return (int)(EARTHRADIUS*cHarv*1000); //whatever, need to get correct distance here.
		}
		SysCtlDelay(SysCtlClockGet()/3);
	}

	//if got fix, return distance.
	//else, return 99999 to signal couldn't fix so no penalty

	return 99999;
}
Example #16
0
File: morse.c Project: black13/io
void pause (unsigned int amount)
{
	/*
      static unsigned int fudge_factor = 0 ;
      unsigned long ul ;
	*/
    SysCtlDelay(SysCtlClockGet() / (1000 * 3));
}
//*****************************************************************************
//
// This function provides a 1 second delay using a simple polling method.
//
//*****************************************************************************
void
SimpleDelay(void)
{
    //
    // Delay cycles for 1 second
    //
    SysCtlDelay(16000000 / 3);
}
Example #18
0
void glcd_setpage (unsigned char page)
{
	/*set CS1(CS1=1 ans CS2=0)right side is selected for column>64 */
	GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_3, 0x00);

	/*Select the page*/
	glcd_cmd(0xB8 | page);
	SysCtlDelay(100);

	/*set CS2(CS1=0 ans CS2=1)left side is selected for column<64 */
	GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_3, 0x08);

	/*select the page*/
	glcd_cmd(0xB8 | page);
	SysCtlDelay(100);

}
int main(void)
{

	SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable the GPIO A ports


	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_7); // Set pin 7 as the output port

	while(1)
	{
		GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7,0);
		SysCtlDelay(4000000);
		GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7,128); // Give '1' to pin 7
		SysCtlDelay(4000000);
	}
}
Example #20
0
uint8_t cc112x_write_regs(const int xcvr, const uint16_t const regSettings[][2], const int arrLen)
{
    while(SSIBusy(SSI0_BASE));
	SysCtlDelay(SysCtlClockGet() / (3*1000));

	int i;
	for(i = 0; i < arrLen; i++)
	{
		//cc112x_print_status_byte(cc112x_sgl_reg_access(xcvr, REG_WRITE, regSettings[i][0], regSettings[i][1]));
		cc112x_sgl_reg_access(xcvr, REG_WRITE, regSettings[i][0], regSettings[i][1]);
		//UART_TX_string("\n\r");

	}

	SysCtlDelay(SysCtlClockGet() / (3*100));
	return 0;
}
Example #21
0
void loop(){

	char le = (char) UARTCharGet(b5);
	putChar(le);
	UARTCharPut(b5, (char)((int) le - 32));
	SysCtlDelay(3000);

}
void main(void)
{ 
    //unsigned long ulTmp = 0;

    /********************** Configure System clock *************************/
    SysCtlClockSet(100000000, SYSCTL_OSC_INT | SYSCTL_XTAL_12_MHZ);
    SysCtlDelay(TICK_SLOW);

    // Configure LED(PC3) pin
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    xGPIOSPinTypeGPIOOutput(PC3);

    // Turn off LED
    GPIOPinClr(GPIOC_BASE, GPIO_PIN_3);

    // Disable NVIC RTC interrupt
    xIntDisable(xINT_RTC);
    RTCDisable();
    RTCIntCallbackInit(RTCHandler);

    // Enable RTC second increment interrupt.
    // Enable RTC minute interrupt.
    RTCIntCfg( INT_SEC_EN          |   INT_MIN_DIS         |
               INT_HOUR_DIS        |   INT_DOM_DIS         |
               INT_DOW_DIS         |   INT_DOY_DIS         |
               INT_MON_DIS         |   INT_YEAR_DIS        |
               INT_ALARM_SEC_DIS   |   INT_ALARM_MIN_EN    |
               INT_ALARM_HOUR_DIS  |   INT_ALARM_DOM_DIS   |
               INT_ALARM_DOW_DIS   |   INT_ALARM_DOY_DIS   |
               INT_ALARM_MON_DIS   |   INT_ALARM_YEAR_DIS  );

    RTCTimeSet(RTC_TIMETYPE_SECOND,      0);
    RTCTimeSet(RTC_TIMETYPE_MINUTE,      0);
    RTCTimeSet(RTC_TIMETYPE_HOUR,        0);
    RTCTimeSet(RTC_TIMETYPE_DAYOFWEEK,   0);
    RTCTimeSet(RTC_TIMETYPE_DAYOFMONTH,  0);
    RTCTimeSet(RTC_TIMETYPE_DAYOFYEAR,   0);
    RTCTimeSet(RTC_TIMETYPE_MONTH,       0);
    RTCTimeSet(RTC_TIMETYPE_YEAR,        0);

    RTCAlarmSet(RTC_TIMETYPE_SECOND,     0);
    RTCAlarmSet(RTC_TIMETYPE_MINUTE,     1);
    RTCAlarmSet(RTC_TIMETYPE_HOUR,       0);
    RTCAlarmSet(RTC_TIMETYPE_DAYOFWEEK,  0);
    RTCAlarmSet(RTC_TIMETYPE_DAYOFMONTH, 0);
    RTCAlarmSet(RTC_TIMETYPE_DAYOFYEAR,  0);
    RTCAlarmSet(RTC_TIMETYPE_MONTH,      0);
    RTCAlarmSet(RTC_TIMETYPE_YEAR,       0);

    RTCEnable();
    RTCCounterReset();
    xIntEnable(xINT_RTC);

    while (1)
    {
        ; // DoNothing
    }
}
Example #23
0
void initLCD() {

	// -- paramra LED test
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, 0x0F);
	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3,  0x0F );

	SysCtlPeripheralEnable(LCDPORTENABLE);

	// -- paramra port A as control
	SysCtlPeripheralEnable(LCDCTRLENABLE);

	GPIOPinTypeGPIOOutput(LCDPORT,
				0xff);

	// -- paramra port A as control
	GPIOPinTypeGPIOOutput(LCDCTRL,
					0xff);

	// Please refer to the HD44780 datasheet for how these initializations work!
	SysCtlDelay((500e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDCTRL, RS,  0x00 );

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDCTRL, E, 0x10);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDCTRL, E, 0x00);

	SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDCTRL, E, 0x10);SysCtlDelay((20e-6)*CLKSPEED/3);GPIOPinWrite(LCDCTRL, E, 0x00);

	SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDCTRL, E, 0x10);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDCTRL, E, 0x00);

	SysCtlDelay((10e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x20 );
	GPIOPinWrite(LCDCTRL, E, 0x10);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDCTRL, E, 0x00);

	SysCtlDelay((10e-3)*CLKSPEED/3);

	LCDCommand(0x01);	// Clear the screen.
	LCDCommand(0x06);	// Cursor moves right.
	LCDCommand(0x0f);	// Cursor blinking, turn on LCD.


}
Example #24
0
void delaymycode(uint16_t delaytime) {
	uint16_t i = 0;
	
	while(i < delaytime){
		SysCtlDelay(200000);  //100ms. argument of 100 is 2uS
		i++;
	}
	return;
}
Example #25
0
void CHRONO_Delay_1ms(uint32_t delay)
{
	uint32_t i = 0;
	while(i<delay)
	{
		SysCtlDelay((SysCtlClockGet() / FREQ_1KHz / NUM_LOOP_CYCLES ));
		i++;
	}
}
static void SysInit(void)
{
    // Close watchdog
    (*((volatile unsigned long *)(0x40048100))) = 0x00;
    
    // Configure System clock    
    xSysCtlClockSet(F_CLK, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    SysCtlDelay(100*TICK_1MS);
}
Example #27
0
void delayMicroseconds(unsigned long nTime) {
    if (!nTime) return;
    else if (nTime < 3) SysCtlDelay(12 * nTime);	// empirical
    else {
        // Compensates for latency
        unsigned long endtime = micros() + nTime - 1;
        while(micros() < endtime);
    }
}
Example #28
0
void delay_ms(unsigned long ms)
{
  unsigned long t;

  t =  ms * (SysCtlClockGet() / 3000);
  SysCtlDelay(t); //3 cycles

  return;
}
//*****************************************************************************
//
// Configure the USB controller and power the bus.
//
// This function configures the USB controller for host operation.
// It is assumed that the main system clock has been configured at this point.
//
// \return None.
//
//*****************************************************************************
void
ConfigureUSBInterface(void)
{
    //
    // Enable the uDMA controller and set up the control table base.
    // This is required by usblib.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    uDMAEnable();
    uDMAControlBaseSet(g_sDMAControlTable);

    //
    // Enable the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Set the USB pins to be controlled by the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
    GPIOPinConfigure(GPIO_PH3_USB0EPEN);
    GPIOPinConfigure(GPIO_PH4_USB0PFLT);
    ROM_GPIOPinTypeUSBDigital(GPIO_PORTH_BASE, GPIO_PIN_3 | GPIO_PIN_4);

    //
    // Register the host class driver
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, NUM_CLASS_DRIVERS);

    //
    // Open an instance of the mass storage class driver.
    //
    g_ulMSCInstance = USBHMSCDriveOpen(0, MSCCallback);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Set the ID pin to be driven low so that OTG calls are not necessary.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0);

    //
    // Wait 10ms for the pin to go low.
    //
    SysCtlDelay(SysCtlClockGet()/100);

    //
    // Initialize the host controller.
    //
    USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);
}
void initMPU6500(mpu6500_t *mpu6500) {
    uint8_t i2cBuffer[5]; // Buffer for I2C data

    i2cBuffer[0] = i2cRead(MPU6500_ADDRESS, MPU6500_WHO_AM_I);
    if (i2cBuffer[0] == MPU6500_WHO_AM_I_ID) { // Read "WHO_AM_I" register
#if UART_DEBUG
        UARTprintf("MPU-6500 found\n");
#endif
    } else if (i2cBuffer[0] == MPU9250_WHO_AM_I_ID) {
#if UART_DEBUG
        UARTprintf("MPU-9250 found\n");
#endif
    } else {
#if UART_DEBUG
        UARTprintf("Could not find MPU-6500 or MPU-9250: %2X\n", i2cBuffer[0]);
#endif
        while (1);
    }

    i2cWrite(MPU6500_ADDRESS, MPU6500_PWR_MGMT_1, (1 << 7)); // Reset device, this resets all internal registers to their default values
    delay(100);
    while (i2cRead(MPU6500_ADDRESS, MPU6500_PWR_MGMT_1) & (1 << 7)) {
        // Wait for the bit to clear
    };
    delay(100);
    i2cWrite(MPU6500_ADDRESS, MPU6500_PWR_MGMT_1, (1 << 3) | (1 << 0)); // Disable sleep mode, disable temperature sensor and use PLL as clock reference

    i2cBuffer[0] = 0; // Set the sample rate to 1kHz - 1kHz/(1+0) = 1kHz
    i2cBuffer[1] = 0x03; // Disable FSYNC and set 41 Hz Gyro filtering, 1 KHz sampling
    i2cBuffer[2] = 3 << 3; // Set Gyro Full Scale Range to +-2000deg/s
    i2cBuffer[3] = 2 << 3; // Set Accelerometer Full Scale Range to +-8g
    i2cBuffer[4] = 0x03; // 41 Hz Acc filtering
    i2cWriteData(MPU6500_ADDRESS, MPU6500_SMPLRT_DIV, i2cBuffer, 5); // Write to all five registers at once

    // Set accelerometer and gyroscope scale factor from datasheet
    mpu6500->gyroScaleFactor = MPU6500_GYRO_SCALE_FACTOR_2000;
    mpu6500->accScaleFactor = MPU6500_ACC_SCALE_FACTOR_8;

    /* Enable Raw Data Ready Interrupt on INT pin and enable bypass/passthrough mode */
    i2cBuffer[0] = (1 << 5) | (1 << 4) | (1 << 1); // Enable LATCH_INT_EN, INT_ANYRD_2CLEAR and BYPASS_EN
                                                   // When this bit is equal to 1, the INT pin is held high until the interrupt is cleared
                                                   // When this bit is equal to 1, interrupt status is cleared if any read operation is performed
                                                   // When asserted, the I2C_MASTER interface pins (ES_CL and ES_DA) will go into 'bypass mode' when the I2C master interface is disabled
    i2cBuffer[1] = (1 << 0);                       // Enable RAW_RDY_EN - When set to 1, Enable Raw Sensor Data Ready interrupt to propagate to interrupt pin
    i2cWriteData(MPU6500_ADDRESS, MPU6500_INT_PIN_CFG, i2cBuffer, 2); // Write to both registers at once

    // Set INT input pin
    SysCtlPeripheralEnable(GPIO_MPU_INT_PERIPH); // Enable GPIO peripheral
    SysCtlDelay(2); // Insert a few cycles after enabling the peripheral to allow the clock to be fully activated
    GPIOPinTypeGPIOInput(GPIO_MPU_INT_BASE, GPIO_MPU_INT_PIN); // Set as input

    delay(100); // Wait for sensor to stabilize

    while (calibrateMPU6500Gyro()) { // Get gyro zero values
        // Loop until calibration is successful
    }
}