Example #1
0
//*****************************************************************************
//
//! \brief print some data to terminal.
//!
//! \param None
//!
//! \return None.
//
//*****************************************************************************
void UartPrintf(void)
{
    unsigned long i;
    //
    //Set System Clock
    //
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    xSysCtlDelay(10000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOD);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

      xSPinTypeUART(UART1TX,PA9);
    

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1);

    xUARTConfigSet(USART1_BASE, 115200, (UART_CONFIG_WLEN_8 |
                                         UART_CONFIG_STOP_ONE | 
                                         UART_CONFIG_PAR_NONE));

    xUARTEnable(USART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));

    for(i = 0; i < sizeof("STM32F1xx.UART Example of CoX \r\n"); i++)
    {
        xUARTCharPut(USART1_BASE, ucData[i]);
    }
}
Example #2
0
//*****************************************************************************
//
//! \brief The example of the function of read and write.
//!
//! \param None
//!
//! \details The example of the function of read and write.
//! \return None.
//
//*****************************************************************************
void M24CxxReadWrite(void)
{

    unsigned long i;

    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    UartInit();
    HT24CxxInit();

    UartPrintfChar('\r');
    UartPrintfChar('\n');
    //
    // write data to M24Cxx
    //
    HT24CxxBufferWrite(ucWriteData, WriteAddress, Length);
    //
    // Read data from M24Cxx
    //
    HT24CxxBufferRead(ucReadData, WriteAddress, Length);

    for(i = 0; i < Length; i++)
    {
        UartPrintfChar(ucReadData[i]);
    }
}
Example #3
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xtimer001 test.
//!
//! \return None.
//
//*****************************************************************************
static void xTimer001Setup(void)
{
    int i;
    //
    //Set the external 12MHZ clock as system clock 
    //
    SysCtlKeyAddrUnlock();
    xSysCtlClockSet(12000000, xSYSCTL_XTAL_6MHZ | xSYSCTL_OSC_MAIN);
    
    //
    // Set the timer clock
    //
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR0_S_EXT12M);
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR1_S_EXT12M);
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR2_S_EXT12M);
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR3_S_EXT12M);
    
    //
    // Enable the tiemr0-3 peripheral
    //
    for(i = 0; i < 4; i++)
    {   
        
        xSysCtlPeripheralEnable(ulTimerID[i]);  
       
    }
    
}
Example #4
0
void LCDShield(void)
{
    int key;
	
    xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);
    xSysCtlDelay(1000);
	
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);	
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(sD13));   
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1);
	
    LCDShieldInit();
	
    //
    // Enable Peripheral SPI0
    //
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
	  
    xSPinTypeADC(ADC0, sA0);
	  
    //
    // ADC Channel0 convert once, Software tirgger.
    //
    xADCConfigure(xADC0_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR);  
	  
    //
    // Enable the channel0
    //
    xADCStepConfigure(xADC0_BASE, 0, xADC_CTL_CH0); 
    
    //
    // Enable the adc
    //
    xADCEnable(xADC0_BASE);
		
    //
    // start ADC convert
    //
    xADCProcessorTrigger( xADC0_BASE );
		
    LCDShieldLocationSet(0, 0);
    LCDShieldDisplayString("Hello Nuvoton!");
    LCDShieldLocationSet(0, 1);
    LCDShieldDisplayString("Hello CooCox! ");
		
    xSysCtlDelay(1000000);

    while(1)
    {
        key = LCDShieldButtonGet();
        if(key != -1)
        {
            LCDShieldDisplayClear();
            LCDShieldLocationSet(0, 0);
            LCDShieldDisplayString("The key is: ");
            LCDShieldLocationSet(0, 1);
            LCDShieldDisplayString(&cKey[key][0]);
        }
    }
}
Example #5
0
void UART_example(void)
{
    unsigned int i = 0;

    //
    // Configure System clock
    //
    xSysCtlClockSet(84000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);
    SysCtlDelay(10000);

    //
    // Enable GPIO/UART Clock
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOG);

    //
    // Remap UART pin to GPIO Port UART0_RX --> PG1 UART0_TX --> PG2
    xSPinTypeUART(UART0RX, PG1);
    xSPinTypeUART(UART0TX, PG2);

    //
    // Configure UART Baud 115200 8-N-1
    //
    xUARTConfigSet(xUART0_BASE, 115200, xUART_CONFIG_WLEN_8 | xUART_CONFIG_PAR_NONE | xUART_CONFIG_STOP_1);

    //
    // Enable UART Receive/Transmit
    //
    xUARTEnable(xUART0_BASE, xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX);

    //
    // print out welcome information
    //

    i = 0;
    while(Buf[i] != '\0')
    {
        xUARTCharPut(xUART0_BASE, Buf[i++]);
    }

    //
    // Echo user's input information
    //
    while((Rec = UxARTCharGet(xUART0_BASE)) != '\n')
    {
        xUARTCharPut(xUART0_BASE, Rec);
    }

    //
    // print out run over information
    //
    i = 0;
    while(Buf[i] != '\0')
    {
        xUARTCharPut(xUART0_BASE, End[i++]);
    }

    while(1);                  
}
Example #6
0
//*****************************************************************************
//
//! \brief Init Spi communction port and wifi handshake pin.
//
//! WiFi shield IO refence volatge == 3.3V
//! Pin map is below:
//! HAND_PIN  --> PA3
//! SPI1_NSS  --> PA4
//! SPI1_SCK  --> PA5
//! SPI1_MISO --> PA6
//! SPI1_MOSI --> PA7
//!
//! \param none.
//!
//! \return None
//
//*****************************************************************************
void SpiDrv_Init(void)
{
    
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SPI1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    xGPIOSPinTypeGPIOInput(PA3);
    xGPIOSPinTypeGPIOOutput(PA4);

    xSPinTypeSPI(SPI1CLK(3),  PA5);
    xSPinTypeSPI(SPI1MOSI(3), PA7);
    xSPinTypeSPI(SPI1MISO(1), PA6);

    //
    // Configure MCU as a master device , 8 bits data width ,MSB first,Mode_0
    //
    xSPIConfigSet(xSPI1_BASE, 4000000, xSPI_MOTO_FORMAT_MODE_0 |
                                                xSPI_MODE_MASTER |
                                                xSPI_MSB_FIRST |
                                                xSPI_DATA_WIDTH8);
    xSPISSSet(xSPI1_BASE, xSPI_SS_SOFTWARE, xSPI_SS0);

    xSPIEnable(xSPI1_BASE);
}
Example #7
0
void SensorExample(void)
{
	int ADValue;
	char buf[4];
	//
    // Initionalize system clock.
    //
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    xSysCtlDelay(100000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    xSysCtlPeripheralEnable2(sUART_BASE);
    xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 |
									     xUART_CONFIG_STOP_1 |
									     xUART_CONFIG_PAR_NONE));
    xUARTEnable(sUART_BASE, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    sPinTypeUART(sUART_BASE);

	SensorShieldInit();

    while(1){
        ADValue = ADCValueGet(SENSOR_SHIELD_AI2);
        buf[0] = ADValue/1000 + 0x30;
        buf[1] = ADValue/100%10 + 0x30;
        buf[2] = ADValue/10%10 + 0x30;
        buf[3] = ADValue%10 + 0x30;
	    SensorShieldUARTBufferPut(sUART_BASE, buf, 4);
    }
}
Example #8
0
void main(void)
{
    //Set System clock to 72MHz
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    SysCtlDelay(10000);
    xSysCtlPeripheralEnable2(I2C1_BASE);

    xSysCtlPeripheralEnable2(xGPIO_PORTB_BASE);    

    //Map I2C1 Pin
    //SCK --> PB6
    //SDA --> PB7
    xSPinTypeI2C(I2C1SCK, PB6);
    xSPinTypeI2C(I2C1SDA, PB7);    

    //Initialize I2C Module 100K
    I2CInit(I2C1_BASE, 100000);
    I2CEnable(I2C1_BASE);
        
    //Enable ADXL345 Measure Function
    I2CMasterWriteS1(I2C1_BASE, I2C_SLAVE_ADDR, 0x2D, xfalse); 
    I2CMasterWriteS2(I2C1_BASE, 0x08, xtrue);
    
    SysCtlDelay(100000);
    
    //Read Accelerometer XYZ data in continue mode
    I2CMasterWriteS1(I2C1_BASE, I2C_SLAVE_ADDR, 0x32, xfalse);    
    I2CMasterReadBufS1(I2C1_BASE, I2C_SLAVE_ADDR, RecvBuf, 6, xtrue);

    while(1);
}
Example #9
0
//*****************************************************************************
//
//! \brief Something should do before the test execute of xgpio001 test.
//!
//! \return None.
//
//*****************************************************************************
static void xgpio001Setup(void)
{
    xSysCtlClockSet(8000000, xSYSCTL_XTAL_8MHZ | xSYSCTL_OSC_MAIN);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_EXTI);
}
Example #10
0
//*****************************************************************************
//
//! \brief something should do before the test execute of VS1838B test.
//!
//! \return None.
//
//*****************************************************************************
static void VS1838BSetup(void)
{
    //
    // Set SysClk 72MHz using Extern 8M oscillator
    //
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN|xSYSCTL_XTAL_8MHZ);
    IRInit();
}
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 #12
0
//*****************************************************************************
//
//! Ininite the ADC 
//!
//! \param None
//!
//! This function ininite the ADC including clock source and enable ADC 
//!
//! \return none
//
//*****************************************************************************
void ADConvert(void)
{
  
    unsigned long ulAdcSeqNo[] = {0};

    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    xSysCtlDelay(10000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    //
    // configure GPIO pin as ADC function
    //
    xSPinTypeADC(ADC0, PA0);
    //
    // Reset ADC 
    //
    xSysCtlPeripheralReset(xSYSCTL_PERIPH_ADC1);

    //
    // Set ADC clock source
    //
    xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_MAIN, 4);

    //
    // Enable ADC clock 
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC1);
 
    //
    // Set the length of converter
    //
    ADCConverLenSet(ADC1_BASE, 1, 1);

    //
    // Set the Index of converter Sequence
    //
    ADCSequenceIndexSet(ADC1_BASE, ulAdcSeqNo, ulAdcSeqNo);

    ADCSampLenSet(ADC1_BASE, 0, 128);

    //
    // A/D interrupt enable 
    //
    ADCIntEnable(ADC1_BASE, ADC_INT_END_CONVERSION);
    xIntEnable(xINT_ADC0);
    xADCIntCallbackInit(ADC1_BASE, ADC0IntFucntion);
    //
    // Software trigger enable
    //
    ADCProcessorTrigger(ADC1_BASE);
    //
    // A/D configure 
    //
    ADCRegularConfigure(ADC1_BASE, ADC_OP_SINGLE, ADC_TRIGGER_PROCESSOR);
    ADCDataRegularGet(ADC1_BASE, ADC_MODE_NORMAL);
}
Example #13
0
//*****************************************************************************
//
//! \brief something should do before the test execute of di_adt75001 test.
//!
//! \return None.
//
//*****************************************************************************
static void adt75001Setup(void)
{
    //
    //Set the external 12MHZ clock as system clock 
    //
	xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN);
    
    ADT75Init(500, ADT75_POWER_SHOTDOWN); 
    
}
Example #14
0
//*****************************************************************************
//
//! \brief something should do before the test execute of AT25FS0x test.
//!
//! \return None.
//
//*****************************************************************************
static void AT25FS0xSetup(void)
{
    unsigned long i;
    //
    // Set SysClk 50MHz using Extern 12M oscillator
    //
    xSysCtlClockSet(50000000, xSYSCTL_OSC_MAIN|xSYSCTL_XTAL_12MHZ);
    AT25FS0xInit(2000000);
    for(i=0;i<Length;i++)
    {
        ucWriteData[i] = (unsigned char)(i); 
    }
}
Example #15
0
//*****************************************************************************
//
//! \brief something should do before the test execute of di_ad7417arz001 test.
//!
//! \return None.
//
//*****************************************************************************
static void di_ad7417arz001Setup(void)
{
    //
    //Set the external 12MHZ clock as system clock 
    //
    xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN);
    
    //
    // AD7417 device init
    //
    AD7417Init(10000, AD7417_POWER_NORMAL | AD7417_TRIGGER_DISABLE); 
    
    UART0Configuration();
}
Example #16
0
//*****************************************************************************
//
//! \brief something should do before the test execute of AT45DB161 test.
//!
//! \return None.
//
//*****************************************************************************
static void AT45DB161Setup(void)
{
    unsigned long i;
    //
    // Set SysClk 50MHz using Extern 12M oscillator
    //
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN|xSYSCTL_XTAL_8MHZ);

    for(i=0; i<Length; i++)
    {
        ucWriteData[i] = (unsigned char)(i);
    }
    AT45DB161_Init(16000000);
}
Example #17
0
//*****************************************************************************
//
//! \brief The example of the function of Dispaly.
//!
//! \param None
//!
//! \details The example of the function of Dispaly.
//! \return None.
//
//*****************************************************************************
void UC1601DispalyExample(void)
{
    //
    // Set SysClk 50MHz using Extern 12M oscillator
    //
    xSysCtlClockSet(50000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);
    UC1601Init(1500000);
    UC1601Clear();
    UC1601CharDispaly(0, 0, "I love google?");
    UC1601CharDispaly(1, 0, "Yes,I love!");
    UC1601ChineseDispaly(3, 0, 4, (char *)&HZ);
    HD44780DisplayN(2,0,5201314);
    xSysCtlDelay(1000000);
}
Example #18
0
//*****************************************************************************
//
//! \brief System and PWM Initialize.
//!
//! \param None
//!
//! \note None.
//!
//! \return None.
//
//*****************************************************************************
void xSysCtlAndPwmInit(void)
{
    unsigned long i = 0;
    unsigned long ulBit = 0;
    //
    // Set System clock is 48M
    //
    xSysCtlClockSet(48000000, (xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ));

    //
    // Enable GPIO and PWM
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOC);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOC);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOE);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOE);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_PWMB);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMB);


    //
    // Set PE2(DIR_CLK), PD3(DIR_SER), and PA6(DIR_LATCH) PD2(DIR_EN) as output
    //
    xGPIOSPinTypeGPIOOutput(sD4);
    xGPIOSPinTypeGPIOOutput(sD8);
    xGPIOSPinTypeGPIOOutput(sD12);
    xGPIOSPinTypeGPIOOutput(sD7);

    //
    // Set PWM Clock Source
    //
    xSysCtlPeripheralClockSourceSet(xSYSCTL_PWMA_MAIN, 4);
    xSysCtlPeripheralClockSourceSet(xSYSCTL_PWMB_MAIN, 4);

    //
    // Congigure the PWM pin(PWM7, sD11))
    //
    sD11PinTypePWM();
    //xGPIOSPinTypeGPIOOutput(sD11);
    //xGPIOSPinWrite(sD11, 1);

    //
    // 74HC595 operation
    // Output Enable
    //
    SendData74HC595(0x60);
}
Example #19
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xspi001 test.
//!
//! \return None.
//
//*****************************************************************************
static void xSpi004Setup(void)
{    
    //
    // Set SysClk 8MHz using Extern 8M oscillator
    //
    xSysCtlClockSet(8000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    //
    // Enable Peripheral SPI0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SPI0);  
	SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO); 
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); 
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); 
}
Example #20
0
int main()
{

    xSysCtlClockSet(72000000, (xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ));


	AMSDCMotorPWMInit(AMS_MOTOR_B, 100000, 50);
	AMSDCMotorPWMInit(AMS_MOTOR_A, 100000, 50);

	AMSDCMotorRun(AMS_MOTOR_B, AMS_RUN_FORWARD);

//	AMSStepMotorInit();
//	AMSStepMotorRun(AMS_RUN_FORWARD, 100);

	while(1);
}			  	
Example #21
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);
    		}
    	}
    }
}
Example #22
0
// Digital Compass
int main(void)
{
    uint8_t Res;
    int16_t Com_Data[3];
    uint16_t x0, y0;
    unsigned long angle = 0;
    double radian;
    
    /* Setup the microcontroller system. Initialize the Embedded Flash Interface,  
     initialize the PLL and update the SystemFrequency variable. */
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    xSysCtlDelay(10000);

    delay_init(72);
    Lcd_Init();
    HMC5883L_Init();
    HMC5883L_Cfg(MODE_SIG | GAIN_1090 | SAMPLE_8 | DATA_RATE_15);
    
    Lcd_Clear(GRAY0);
    //
    Gui_Circle(64, 80, 50, BLUE);
    Gui_DrawFont_GBK16(64,14,BLUE,GRAY0,"N"); 
    Gui_DrawFont_GBK16(64,132,BLUE,GRAY0,"S"); 
    Gui_DrawFont_GBK16(5,80,BLUE,GRAY0,"W"); 
    Gui_DrawFont_GBK16(116,80,BLUE,GRAY0,"E"); 
    while(1){
        Res = HMC5883L_DataGet(&Com_Data[0], &Com_Data[1], &Com_Data[2]);
        if(Res) break;
        angle = (unsigned long) (atan2((double)Com_Data[0],(double)Com_Data[1])*(180/3.14159265)+180);
        //angle = rand()%360;
    	radian = angle * 3.1415926 / 180;
        
        if(angle <= 180){
            x0 = 64 + (int16_t)(40 * sin(radian));
            y0 = 80 - (int16_t)(40 * cos(radian));
        } else {
            x0 = 64 + (int16_t)(40 * sin(radian));
            y0 = 80 - (int16_t)(40 * cos(radian));
        }
        Gui_DrawLine(64, 80, x0, y0, BLUE);   
        delay_ms(500);
        Gui_DrawLine(64, 80, x0, y0, GRAY0); 
    }
    return 0;
}
Example #23
0
//*****************************************************************************
//
//! The main function of the adt75 one-shot mode.
//
//! return none
//
//*****************************************************************************
void TemperatureGet(void)
{
    long lTemp;
    //
    //Set the external 12MHZ clock as system clock 
    //
    xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN);
    
    ADT75Init(10000, ADT75_POWER_NORMAL); 
    
    //
    // OS Int mode configure
    //
    ADT75IntModeConfig(ADT75_OPEMODE_CMP);
    
    //
    // OS pin active level is low, a pull-up register should add on this pin.
    //
    ADT75OSActiveLevelConfig(ADT75_OSALERT_LEVEL_LOW);
    
    //
    // Set the Faultqueue is 1
    //
    ADT75FaultQueueConfig(ADT75_FAULTQUE_1);
    
    //
    // Enable the one-shot mode
    //
    ADT75OneShotEnable();
        
    //
    // Configure the setpoint register
    //
    ADT75LowLimitSetLong(25);
    ADT75UpLimitSetLong(28);    

    while(1)
    {
        ADT75OneShotConvst();
        lTemp = ADT75TempReadLDC();      
    }
    
}
Example #24
0
void 
TestIOInit(void)
{    
    xSysCtlClockSet(50000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);

    SysCtlDelay(10000);

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

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1);

    xUARTConfigSet(UART0_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    xUARTEnable(UART0_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));
}
Example #25
0
//*****************************************************************************
//
//! The function is to set the i2c slave receive with poll mode
//
//! return none
//
//*****************************************************************************
void SlaveReceivePoll(void)
{
    //
    // Set system clock 
    //
    xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN);
    
    //
    // Congigure the i2c pin
    //
    xSPinTypeI2C(I2C0SCK, PD5);
    xSPinTypeI2C(I2C0SDA, PD4);
    
    //
    // Enable the i2c peripheral
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_I2C0);
    
    //
    // Init the I2C as slave 
    //
    xI2CSlaveInit(I2C0_BASE, SlaveAddress, I2C_GENERAL_CALL_DIS);
    
    WriteBuf[8] = '\0';
    
    //
    // I2C master transfer config
    //
    I2CSlaveRcCfg.pvWBuf = WriteBuf;
    I2CSlaveRcCfg.ulWLen = WriteLength;
    I2CSlaveRcCfg.ulWCount = 0;
    I2CSlaveRcCfg.pvRBuf = ReceiveBuf;
    I2CSlaveRcCfg.ulRLen = ReceiveLength;
    I2CSlaveRcCfg.ulRCount = 0;
    
    xI2CIntCallbackInit(I2C0_BASE, SlavaRecvFunc);
    
    //
    // I2C salve receive wiht polling mode
    //
    xI2CSlaveTransfer(I2C0_BASE, &I2CSlaveRcCfg, xI2C_TRANSFER_POLLING);
}
Example #26
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xpwm002 test.
//!
//! \return None.
//
//*****************************************************************************
static void xpwm002Setup(void)
{
    SysCtlKeyAddrUnlock();  
    xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN);
   
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMA);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMB);
    
    //
    // GPIO pin function set as pwm output
    //
    xSPinTypePWM(PWM0, PA12);    
    xSPinTypePWM(PWM1, PA13); 
    xSPinTypePWM(PWM2, PA14); 
    xSPinTypePWM(PWM3, PA15); 
    xSPinTypePWM(PWM4, PB11); 
    xSPinTypePWM(PWM5, PE5); 
    xSPinTypePWM(PWM6, PE0); 
    xSPinTypePWM(PWM7, PE1);     
}
Example #27
0
//show clock
int main()
{
	/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
	 initialize the PLL and update the SystemFrequency variable. */
	xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
	xSysCtlDelay(10000);

	delay_init(72);
	Lcd_Init();
	Lcd_Clear(GRAY0);

	Gui_DrawFont_GBK16(30,50,BLUE,GRAY0,"Show Clock");
	Gui_DrawFont_GBK16(36,70,BLUE,GRAY0,"@ CooCox");
	delay_ms(2000);
	Lcd_Clear(GRAY0);

	while(1){
		Show_Clock();
	}
}
Example #28
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xTimer002 test.
//!
//! \return None.
//
//*****************************************************************************
static void xTimer002Setup(void)
{
    int i;
    
    //
    //Set the external 8MHZ clock as system clock 
    //
    xSysCtlClockSet(8000000, xSYSCTL_XTAL_8MHZ | xSYSCTL_OSC_MAIN);
    
    //
    // Enable the tiemr0-3 peripheral
    //
    for(i = 0; i < 2; i++)
    {   
        
        xSysCtlPeripheralEnable(ulTimerID[i]);  
       
    }
    
}
Example #29
0
File: Wakeup.c Project: 0xc0170/cox
//*****************************************************************************
//
//! \brief Wdt wakeup example.
//!
//! \return None.
//
//*****************************************************************************
void Wakeup(void) 
{
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    SysCtlDelay(10000);
    //
    // Enable WDT wake up function.
    //
    xWDTFunctionEnable(xWDT_BASE, xWDT_INT_FUNCTION);

    //
    // Set WDT clock and interval time.
    //
    xWDTInit(xWDT_BASE, SYSCTL_PERIPH_WDG_S_EXTSL, 512);

    //
    // Set WDT interrupt and initionalize callback.
    //
    xWDTIntCallbackInit(xWDT_BASE, WdtCallback);
    xIntEnable(xINT_WDT);
}
Example #30
0
//////////////////////////////////////////////////////////////////////////////
// Platform (STM32F103X) initialization for peripherals as GPIO, SPI, UARTs //
//////////////////////////////////////////////////////////////////////////////
void platform_init(void)
{
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    xSysCtlDelay((xSysCtlClockGet()/1000)*50); // wait 50ms


    /**************************/
    /* GPIO_A For SPI CS PIN  */// It must be first to enable GPIO peripheral than other peripheral. (Otherwise, UART do not run in STM32F103X)
    /**************************/
    xSysCtlPeripheralEnable( xSYSCTL_PERIPH_GPIOA );
    xGPIODirModeSet(xGPIO_PORTA_BASE, xGPIO_PIN_4, xGPIO_DIR_MODE_OUT);


    /************/
    /* For UART */
    /************/
    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1);
    xSPinTypeUART(UART1TX,PA9);
    xSPinTypeUART(UART1RX,PA10);
    xUARTConfigSet(xUART1_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    xUARTEnable(xUART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));


    /***********/
    /* For SPI */
    /***********/
    xSysCtlPeripheralReset(WIZCHIP_SPI_PERIPH);
    xSysCtlPeripheralEnable(WIZCHIP_SPI_PERIPH);
    xSPinTypeSPI(WIZCHIP_SPI_CLK, WIZCHIP_SPI_CLK_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_5, GPIO_TYPE_AFOUT_STD, GPIO_OUT_SPEED_50M);
    xSPinTypeSPI(WIZCHIP_SPI_MOSI,WIZCHIP_SPI_MOSI_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_7, GPIO_TYPE_AFOUT_STD, GPIO_OUT_SPEED_50M);
    xSPinTypeSPI(WIZCHIP_SPI_MISO,WIZCHIP_SPI_MISO_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_6, GPIO_TYPE_IN_FLOATING, GPIO_IN_SPEED_FIXED);
    xSPIConfigSet(WIZCHIP_SPI_BASE, xSysCtlClockGet()/2, xSPI_MOTO_FORMAT_MODE_0 | xSPI_MODE_MASTER | xSPI_MSB_FIRST | xSPI_DATA_WIDTH8);

    xSPISSSet(WIZCHIP_SPI_BASE, SPI_SS_SOFTWARE, xSPI_SS_NONE);
    xSPIEnable(WIZCHIP_SPI_BASE);

    printf("HCLK = %dMHz\r\n", (unsigned int)(xSysCtlClockGet()/1000000));
}