示例#1
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]);
        }
    }
}
示例#2
0
文件: hd44780.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief Write data or command to the HD44780.
//!
//! \param ucRS determines if the IR or DR to select.
//!
//! The parameter of ucRS can be:
//! - HD44780_RS_COMMAND - select the IR.
//! - HD44780_RS_DATA - select the DR.
//!
//! \return None.
//
//*****************************************************************************
void 
HD44780Write(unsigned char ucRS, unsigned char ucInstruction)
{
	int i;
    //
    // Check Arguments.
    //
    xASSERT((ucRS == HD44780_RS_COMMAND) || (ucRS == HD44780_RS_DATA));

    //
    // RS:Command, RW:Write, E:Enable
    //
    _digitalWrite(ucRsPin, ucRS);
    _digitalWrite(ucEnablePin, HD44780_E_ENABLE);

    //
    // Output Data
    //
    for ( i = 0; i < 4; i++)
    {
        _digitalWrite(ucDataPin[i], (ucInstruction >> (i+4)) & 0x01);
    }
    PulseEnable();
    xSysCtlDelay(10);
    _digitalWrite(ucEnablePin, HD44780_E_ENABLE);
    for ( i = 0; i < 4; i++)
    {
        _digitalWrite(ucDataPin[i], (ucInstruction >> (i)) & 0x01);
    }
    xSysCtlDelay(10);
    PulseEnable();
}
示例#3
0
文件: main.c 项目: xinyun/test
void GPIO_Example_LED_Blink(void)
{

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

    // Enable LED PORT
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

    // Configure LED(PC3) pin into output mode.
    xGPIOSPinTypeGPIOOutput(PC3);
    xGPIOSPinDirModeSet(PC3,xGPIO_DIR_MODE_OUT);

    while(1)
    {
        // LED ON
        xGPIOSPinWrite(PC3,1);
        xSysCtlDelay(10*TICK_SLOW);

        // LED OFF
        xGPIOSPinWrite(PC3,0);
        xSysCtlDelay(10*TICK_SLOW);
    }
}
示例#4
0
void Lcd_Reset(void)
{
    LCD_RST_CLR;
    xSysCtlDelay(xSysCtlClockGet()/20);
    LCD_RST_SET;
    xSysCtlDelay(xSysCtlClockGet()/20);
}
示例#5
0
文件: st7735.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief Read the state or data from the ST7735.
//!
//! \param ucRS determines if the IR or DR to select.
//!
//! The parameter of ucDC can be:
//! - ST7735_RS_COMMAND - select the IR.
//! - ST7735_RS_DATA - select the DR.
//!
//! \return None.
//
//*****************************************************************************
unsigned long 
ST7735Read(unsigned char ucRS)
{
    unsigned long ulData = 0;

    //
    // Set D7 - D0 direction to GPIO Input
    //      
    xGPIOSPinTypeGPIOInput(ST7735_PIN_D7);
    xGPIOSPinTypeGPIOInput(ST7735_PIN_D6);
    xGPIOSPinTypeGPIOInput(ST7735_PIN_D5);
    xGPIOSPinTypeGPIOInput(ST7735_PIN_D4);
    xGPIOSPinTypeGPIOInput(ST7735_PIN_D3);
    xGPIOSPinTypeGPIOInput(ST7735_PIN_D2);
    xGPIOSPinTypeGPIOInput(ST7735_PIN_D1);
    xGPIOSPinTypeGPIOInput(ST7735_PIN_D0);       

    //
    // DC:Command, RD:Write/Read, CS:Enable
    //
    xGPIOSPinWrite(ST7735_PIN_RS, ucRS);
    xGPIOSPinWrite(ST7735_PIN_WR, ST7735_WR_HIGH);	
    xGPIOSPinWrite(ST7735_PIN_CS, ST7735_CS_ENABLE);

    xSysCtlDelay(100);
    
    //
    // Read the Data
    //
		xGPIOSPinWrite(ST7735_PIN_RD, ST7735_RD_LOW);
    xSysCtlDelay(100);
    xGPIOSPinWrite(ST7735_PIN_RD, ST7735_RD_HIGH);
    ulData |= xGPIOSPinRead(ST7735_PIN_D7) << 7;
    ulData |= xGPIOSPinRead(ST7735_PIN_D6) << 6;
    ulData |= xGPIOSPinRead(ST7735_PIN_D5) << 5;
    ulData |= xGPIOSPinRead(ST7735_PIN_D4) << 4;
    ulData |= xGPIOSPinRead(ST7735_PIN_D3) << 3;
    ulData |= xGPIOSPinRead(ST7735_PIN_D2) << 2;
    ulData |= xGPIOSPinRead(ST7735_PIN_D1) << 1;
    ulData |= xGPIOSPinRead(ST7735_PIN_D0) << 0;
    
    xGPIOSPinWrite(ST7735_PIN_CS, ST7735_CS_DISABLE); 

    //
    // At the End, set D7 - D0 direction to GPIO OutPut
    //  
    xGPIOSPinTypeGPIOOutput(ST7735_PIN_D7);
    xGPIOSPinTypeGPIOOutput(ST7735_PIN_D6);
    xGPIOSPinTypeGPIOOutput(ST7735_PIN_D5);
    xGPIOSPinTypeGPIOOutput(ST7735_PIN_D4);
    xGPIOSPinTypeGPIOOutput(ST7735_PIN_D3);
    xGPIOSPinTypeGPIOOutput(ST7735_PIN_D2);
    xGPIOSPinTypeGPIOOutput(ST7735_PIN_D1);
    xGPIOSPinTypeGPIOOutput(ST7735_PIN_D0);   
    
    return ulData;
}
示例#6
0
文件: PTC08.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief Initializes the PTC08 device.
//!
//! Initializes the PTC08 device,it will set the baud rate 115200,image size 
//! 320*240,ziprate 36 and non-save power.
//!
//! \return None.
//
//*****************************************************************************
xtBoolean 
PTC08Init(void)
{
    xSysCtlPeripheralEnable2(PTC08_UART);
    xSysCtlPeripheralEnable2(xGPIOSPinToPeripheralId(PTC08_PIN_UART_RX));
    xSysCtlPeripheralEnable2(xGPIOSPinToPeripheralId(PTC08_PIN_UART_TX));
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART1_MAIN, 1);

    xSPinTypeUART(PTC08_UART_RX, PTC08_PIN_UART_RX);
    xSPinTypeUART(PTC08_UART_TX, PTC08_PIN_UART_TX);

    xUARTConfigSet(PTC08_UART, 38400, (xUART_CONFIG_WLEN_8 |
    		                           xUART_CONFIG_STOP_1 |
                                       xUART_CONFIG_PAR_NONE));

    xUARTEnable(PTC08_UART, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));

    //
    // Must wait for 2.5s before the camera can received Command
    //
    xSysCtlDelay(25000000); 
    
    if(!PTC08PhotoReset())
    {
        return xfalse;
    }
    if(!PTC08PhotoSizeSet(PTC08_SIZE_320_240))
    {
        return xfalse;
    }
    if(!PTC08ZipRateSet(0x36))
    {
        return xfalse;
    }
    xSysCtlDelay(10);
    
    if(!PTC08SavePowerSet(PTC08_SAVE_POWER_DIS))
    {
        return xfalse;
    } 
    if(!PTC08BaudRateSet(PTC08_BAUDRATE_115200))
    {
        return xfalse;
    } 
    xUARTConfigSet(PTC08_UART, 115200, (UART_CONFIG_WLEN_8 | 
                                        UART_CONFIG_STOP_ONE | 
                                        UART_CONFIG_PAR_NONE));
    return xtrue;
}
示例#7
0
void DeltaAngleGet()
{
	tLPR5150ALData g_XYAxisCurrentVoltage;
	tLPR5150ALData g_XYAxisNullVoltage;
	tLPR5150ALData g_XYAxisAngle;
	tLPR5150ALData g_XYAxisRate;

    xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);
    xSysCtlDelay(1000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(sD13));
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1);

    sPinTypeUART(sUART_DBG_BASE);
    xUARTConfigSet(sUART_DBG_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    xUARTEnable(sUART_DBG_BASE, (UART_BLOCK_UART | UART_BLOCK_RX));

    //automatically added by CoIDE
	//ADConvert();


    xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);

    LPR5150ALInit();

	while(1)
    {
		g_XYAxisAngle = LPR5150ALXYAxisAngleGet();
		printf("The roll angle is: %f   ", g_XYAxisAngle.fXAxisData);
		printf("The pitch angle is: %f \r\n", g_XYAxisAngle.fYAxisData);
		//DelayMS(500);
    }
}
示例#8
0
//*****************************************************************************
//
//! \brief HT24Cxx test execute main body.
//!
//! \return None.
//
//*****************************************************************************
static void HT24CxxExecute(void)
{
    unsigned long i;
    TestIOPut('0');
    HT24CxxByteWrite(ucWriteData, ucWriteAddr);
    TestIOPut('1');
    HT24CxxWaitEepromStandbyState();
    TestIOPut('2');
    HT24CxxBufferRead(ucReadData, ucReadAddr , 1);
    TestIOPut('3');
    TestAssert((ucWriteData[0] == ucReadData[0]), 
               "HT24Cxx API \"HT24CxxByteWrite() and HT24CxxBufferRead()\"error!");
   
    TestIOPut('4');
    xSysCtlDelay(1000000);
    HT24CxxBufferWrite(ucWriteData, ucWriteAddr, Length);
    TestIOPut('5');
    HT24CxxBufferRead(ucReadData, ucReadAddr, Length);
    TestIOPut('6');
    for(i = 0; i < Length ; i++)
    {
      TestAssert((ucWriteData[i] == ucReadData[i]), 
                 "HT24Cxx API \"HT24CxxBufferWrite() and HT24CxxBufferRead()\"error!");
    }    
}
示例#9
0
文件: UartPrintf.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \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]);
    }
}
示例#10
0
文件: T00006x.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief Get the XYAxis Null voltage.
//!
//! \param None.
//!
//! \return The data of channel Current voltage.
//
//*****************************************************************************
tLPR5150ALData
LPR5150ALXYAxisNullVoltageGet()
{
	tLPR5150ALData XYAxisCurVoltage = {0, 0};
	tLPR5150ALData XYAxisNullVoltage = {0, 0};

	float fXAxisDataTemp = 0, fYAxisDataTemp = 0;
	unsigned char i;

	for(i = 0; i < 50; i++)
	{
		XYAxisCurVoltage = LPR5150ALXYAxisCurVoltageGet();
		fXAxisDataTemp += XYAxisCurVoltage.fXAxisData;
		fYAxisDataTemp += XYAxisCurVoltage.fYAxisData;

		//
		// delay a little time
		//
		xSysCtlDelay(10);
	}

	//
	// Get the Null voltage.
	//
	XYAxisNullVoltage.fXAxisData = fXAxisDataTemp / 50;
	XYAxisNullVoltage.fYAxisData = fYAxisDataTemp / 50;

	return XYAxisNullVoltage;

}
示例#11
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);
    }
}
示例#12
0
unsigned char nRF24L01_debug(void)
{
#ifdef nRF24L01_RX_Debug
    unsigned char RxBuf[RX_PLOAD_WIDTH]={0};
    SetRX_Mode();
    while(1){
        SetRX_Mode();
        if(nRF24L01_RxPacket(RxBuf)){ 
            //add your code
            return 1;
        }
    } 
#endif
    
#ifdef nRF24L01_TX_Debug   
    unsigned char sta=0; 
    unsigned char TxBuf[TX_PLOAD_WIDTH]={0};
    nRF24L01_TxPacket(TxBuf);
    while(1){ 
        nRF24L01_TxPacket(TxBuf);
        sta = SPI_Read(STATUS);
        if(sta == 0x2e){
            //add your code
            return 1;
        }
        SPI_RW_Reg(WRITE_REG+STATUS, 0xff);
        xSysCtlDelay(10000);
    }
#endif
}
示例#13
0
文件: CH376.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief delay specified ms.
//!
//! \param n specify how many ms you want to delay
//!
//! \details approximately delay for n ms depends on your system clock
//!
//! \return None
//
//*****************************************************************************
void mDelaymS(unsigned int n)
{
    while(n--)
    {
        xSysCtlDelay(30000);
    }
}
示例#14
0
//*****************************************************************************
//
//! \brief AT45DB161 test execute main body.
//!
//! \return None.
//
//*****************************************************************************
static void AT45DB161Execute(void)
{
    unsigned long i;
    unsigned char ucChipID[4];

    AT45DB161_Write(ucWriteData, 0, Length);
    xSysCtlDelay(5000000);
    AT45DB161_Read(ucReadData, 0, Length);

    AT45DB161_GetChipID(ucChipID);
    TestAssert((ucChipID[0] == 0x1F)&&(ucChipID[1] == 0x26),
               "AT45DB161 API \"AT45DB161_GetChipID()\"error!");
    for(i = 0; i < Length; i++)
    {
        if(ucWriteData[i] != ucReadData[i])break;
        TestAssert((ucWriteData[i] == ucReadData[i]),
                   "AT45DB161 API \"AT45DB161_Write() and AT45DB161_Read()\"error!");
    }


    AT45DB161_ErasePage(1);
    AT45DB161_Read(ucReadData, 528, 512);
    for(i = 0; i < 512; i++)
    {
        TestAssert((255 == ucReadData[i]),
                   "AT45DB161 API \"AT45DB161_EraseChip()\"error!");
    }
    AT45DB161_EraseChip();
    AT45DB161_Read(ucReadData, 1000, Length);
    for(i = 0; i < Length; i++)
    {
        TestAssert((255 == ucReadData[i]),
                   "AT45DB161 API \"AT45DB161_EraseChip()\"error!");
    }

    AT45DB161_WriteBuffer(1, ucWriteData, 0, 500);
    xSysCtlDelay(50000);
    AT45DB161_ReadBuffer(1, ucReadData, 0, 500);
    for(i = 0; i < 500; i++)
    {
        if(ucWriteData[i] != ucReadData[i])break;
        TestAssert((ucWriteData[i] == ucReadData[i]),
                   "AT45DB161 API \"AT45DB161_WriteBuffer() and AT45DB161_ReadBuffer()\"error!");
    };
}
示例#15
0
文件: ADConvert.c 项目: 0xc0170/cox
//*****************************************************************************
//
//! 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);
}
示例#16
0
文件: main.c 项目: ptLong/Embedded-Pi
void SendData74HC595(unsigned char ucData)
{
    unsigned long i = 0;
    unsigned long ulBit = 0;
    xGPIOSPinTypeGPIOOutput(sD4);
    xGPIOSPinTypeGPIOOutput(sD8);
    xGPIOSPinTypeGPIOOutput(sD7);

    //
    // 74HC595 operation
    // Output Enable
    //
    xGPIOSPinWrite(sD7, 1);
    xGPIOSPinWrite(sD7, 0);

    //
    // Send Data 0xF7 to 74HC595
    //
    xGPIOSPinWrite(sD4, 0);
    for(i=0; i<8; i++)
    {
        if((ucData & (1<<i)))
        {
            xGPIOSPinWrite(sD8, 1);
        }
        else
        {
            xGPIOSPinWrite(sD8, 0);
        }
        xGPIOSPinWrite(sD4, 1);
        xSysCtlDelay(1);
        xGPIOSPinWrite(sD4, 0);
    }
    //
    // Latch Data to 74HC595
    //
    xGPIOSPinWrite(sD12, 0);
    xSysCtlDelay(1);
    xGPIOSPinWrite(sD12, 1);
    xSysCtlDelay(1);
    xGPIOSPinWrite(sD12, 0);
}
示例#17
0
文件: AT45DB161.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief Initialize AT45DB161 and SPI
//!
//! \param ulSpiClock specifies the SPI Clock Rate
//!
//! This function initialize the mcu SPI as master and specified SPI port.
//! After SPI and port was configured, the mcu send a AT45DB161_CMD_SRRD command
//! to get the page size of AT45DB161 to get prepareed for the followed read and
//! write operations.
//!
//! \return None.
//
//*****************************************************************************
void AT45DB161_Init(unsigned long ulSpiClock)
{
    unsigned char tmp;
    xASSERT((ulSpiClock > 0) && (ulSpiClock < AT45DB161_MAX_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_SCK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_CS_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_MISO));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_MOSI));
    xSysCtlPeripheralEnable2(AT45DB161_SPI_PORT);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    xGPIOSPinDirModeSet(AT45DB161_CS_PIN, xGPIO_DIR_MODE_OUT);
#if (AT45DB161_WRITE_PROTECT < 1)
    xGPIOSPinDirModeSet(FLASH_PIN_WRITE_PROTECT, xGPIO_DIR_MODE_OUT);
    xGPIOSPinWrite(FLASH_PIN_WRITE_PROTECT, 0);
#endif
    //
    // PD1 as SPI2.CLK
    //
    xSPinTypeSPI(SPI_CLK, AT45DB161_SCK);
    //
    // PD2 as SPI2.MISO
    // MISO20 => SPI0MISO
    //
    xSPinTypeSPI(SPI_MISO, AT45DB161_MISO);
    //
    // PD3 as SPI2.MOSI
    // MOSI20 => SPI0MISO
    //
    xSPinTypeSPI(SPI_MOSI, AT45DB161_MOSI);

    //xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    //
    //! Set SPI mode.
    //
    xSPIConfigSet(AT45DB161_SPI_PORT, ulSpiClock, SPI_MODE_MASTER |
                  SPI_MSB_FIRST |
                  SPI_2LINE_FULL |
                  SPI_DATA_WIDTH8 |
                  SPI_FORMAT_MODE_4);
    SPISSModeConfig(AT45DB161_SPI_PORT, SPI_CR1_SSM);
    SPISSIConfig(AT45DB161_SPI_PORT, SPI_CR1_SSI);
    SPIEnble(AT45DB161_SPI_PORT);
    AT45DB161_CS = 1;
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xFF);
    xSysCtlDelay(100000);
    AT45DB161_CS = 0;
    //
    //! Read AT45DB161 state register to get the page size.
    //
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_SRRD);
    tmp = xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xFF);
    if(tmp & AT45DB161_PGSZ) AT45DB161_PageSize = 512;
    AT45DB161_CS = 1;
}
示例#18
0
int main() {

	//
	// Disable the watchdog
	//
	WDTimerDisable();

	xSysCtlClockSet32KhzFLLExt(); //48mhz from 32768khz external clock

	xSysTickPeriodSet(xSysCtlClockGet()/SYSTICKS_PER_SECOND); //1ms
	xSysTickIntEnable();
	xSysTickEnable(); // End of SysTick init
	ulClockMS = xSysCtlClockGet() / (3 * 1000);

	pwmInit();

	// Setup and configure rf radio
	RF24 radio = RF24();
	rf24_init(radio);

	while (1) {

		// if there is data ready
		report_t gamepad_report;
		if (!getNRF24report(&radio, &gamepad_report))
		{

			drive(&gamepad_report);

			//			if (gamepad_report.reportid == 1) {
			//				// Delay just a little bit to let the other unit
			//				// make the transition to receiver
			//				xSysCtlDelay(ulClockMS * 10);
			//
			//				radio.stopListening();
			//				uint8_t response = 0;
			//				radio.write(&response, sizeof(uint8_t));
			//				radio.startListening();
			//			}


			timeoutcounter = millis();

		} else {
			if ((millis() - timeoutcounter) > TIMEOUT) {
				stopall();
				xSysCtlDelay(ulClockMS * 10);
			}
		}
	}

	return 0;
}
示例#19
0
文件: splc780d.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief Read the state or data from the SPLC780D.
//!
//! \param ucRS determines if the IR or DR to select.
//!
//! The parameter of ucRS can be:
//! - \ref SPLC780_RS_COMMAND - select the IR.
//! - \ref SPLC780_RS_DATA - select the DR.
//!
//! \return None.
//
//*****************************************************************************
unsigned char 
SPLC780Read(unsigned char ucRS)
{
    unsigned char ucTemp, ucData = 0;

    //
    // Check Arguments.
    //
    xASSERT((ucRS == SPLC780_RS_COMMAND) || (ucRS == SPLC780_RS_DATA));

    //
    // RS:Command, RW:Write, E:Enable
    //
    ucTemp = (ucRS | SPLC780_RW_READ | SPLC780_E_DISABLE | ucBacklightState);
    xI2CMasterWriteS1(ulMaster, SPLC780_I2C_Addr, ucTemp, xfalse);
    xSysCtlDelay(20);
    ucTemp = (ucRS | SPLC780_RW_READ | SPLC780_E_ENABLE | ucBacklightState);
    xI2CMasterWriteS2(ulMaster, ucTemp, xfalse);

    //
    // Read the Data
    //
    xI2CMasterReadS2(ulMaster, &ucData, xfalse);

	
    ucTemp = (ucRS | SPLC780_RW_READ | SPLC780_E_DISABLE | ucBacklightState);
    xI2CMasterWriteS2(ulMaster, ucTemp, xfalse);
    xSysCtlDelay(20);
    ucTemp = (ucRS | SPLC780_RW_READ | SPLC780_E_ENABLE | ucBacklightState);
    xI2CMasterWriteS2(ulMaster, ucTemp, xfalse);

    //
    // Read the Data
    //
    xI2CMasterReadS2(ulMaster, &ucTemp, xtrue);
    
    ucData = ((ucData << 4) & 0xf0) | (ucTemp & 0x0f);
	
    return ucData;
}
示例#20
0
//*****************************************************************************
//
//! \brief Peripheral Initialization.
//!
//! \param None.
//!
//! This function is to Initialize joystick, LED, USART1, CH376, USB flash disk and VS1003.
//!
//! \return None.
//
//*****************************************************************************
void PeriphInit()
{
	unsigned char s;
	JoystickInit();
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(LED_PIN));
	xGPIOSPinDirModeSet(LED_PIN, xGPIO_DIR_MODE_OUT);
	xGPIOSPinWrite( LED_PIN, 0 );
	mInitSTDIO( );
	s = mInitCH376Host( );
	mStopIfError( s );
	while ( CH376DiskConnect( ) != USB_INT_SUCCESS )
	{
		xSysCtlDelay( 1000000 );
		printf("Waiting for USB flash disk to plug in...\n\r");
	}
	xSysCtlDelay( 2000000 );
	for ( s = 0; s < 10; s ++ )
	{
		xSysCtlDelay( 500000 );
	    if ( CH376DiskMount( ) == USB_INT_SUCCESS ) break;
	}
	VS10xxInit();
}
示例#21
0
文件: adt75.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief One shot convert 
//!  
//! \return None
//
//*****************************************************************************
void ADT75OneShotConvst(void)
{
    //
    // Write 0x04 to address register to trigger one convert
    //
    ADT75RegWrite(ADT75_REGISTER_ONTSHOT, 0);  
    
    //
    // Wait for a minimum of 60 ms after writing to the one-shot register before 
    // reading back the temperature. This time ensures the ADT75 has time to 
    // power up and do a conversion.
    //
    xSysCtlDelay(100);
}
示例#22
0
文件: Example.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \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);
}
示例#23
0
文件: splc780d.c 项目: AlexGora/cox
//*****************************************************************************
//
//! \brief Write 4-bit data or command to the SPLC780D through PCA8574.
//!
//! \param ucRS determines if the IR or DR to select.
//!
//! \return None.
//
//*****************************************************************************
void 
SPLC780Write4Bit(unsigned char ucDat)
{
    ucDat = ucDat | ucBacklightState | SPLC780_RW_WRITE;

    //
    //! input the 4-bit data 
    //
    xI2CMasterWriteS1(ulMaster, SPLC780_I2C_Addr, ucDat, xfalse);
	
    //
    //! latch the 4-bit data
    //
    xI2CMasterWriteS2(ulMaster, (ucDat | SPLC780_E_ENABLE), xfalse);
    xSysCtlDelay(200);
    xI2CMasterWriteS2(ulMaster, (ucDat | SPLC780_E_DISABLE), xtrue); 
}
示例#24
0
文件: main.c 项目: bprewit/embeddedpi
// 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;
}
示例#25
0
文件: main.c 项目: bprewit/embeddedpi
//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();
	}
}
示例#26
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));
}
示例#27
0
文件: hd44780.c 项目: AlexGora/cox
void
_digitalWrite(unsigned char p, unsigned char d)
{
	int i;
	unsigned char ucData;
    if (d == 1)
      _SPIbuff |= (1 << p);
    else
      _SPIbuff &= ~(1 << p);

    ucData = _SPIbuff;
#if HD44780_SPI_MODE == SPIMODE_HARDWARE
    xGPIOSPinWrite(HD44780_PIN_CS, 0);
    xSPISingleDataReadWrite((HD44780_SPI),ucData);
    xGPIOSPinWrite(HD44780_PIN_CS, 1);
#else

    xGPIOSPinWrite(HD44780_PIN_CS, 0);
    for(i = 0; i < 8; i++)
	{
		//ucData = (0xF7 & (1<<i)) >> i;
		if(ucData & 0x80)
		{
			xGPIOSPinWrite(HD44780_PIN_MOSI, 1);

		}
		else
		{
			xGPIOSPinWrite(HD44780_PIN_MOSI, 0);
		}
		ucData = ucData << 1;

		xGPIOSPinWrite(HD44780_PIN_CLK, 0);
		xSysCtlDelay(1);
		xGPIOSPinWrite(HD44780_PIN_CLK, 1);
	}
    xGPIOSPinWrite(HD44780_PIN_CS, 1);
#endif
}
示例#28
0
文件: uartprintf.c 项目: Karplyak/cox
void uartprinntf()
{
    xSysCtlClockSet(84000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);
    xSysCtlDelay(10000);

    xSPinTypeUART(UART0RX,PG1);
    xSPinTypeUART(UART0TX,PG2);

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);

    //
    // Config 8 bit word length, 1 stop bit, 
    // and none parity bit, receive FIFO 1 byte.
    //
    xUARTConfigSet(xUART0_BASE, 115200, (xUART_CONFIG_WLEN_8   | \
                                         xUART_CONFIG_STOP_1   | \
                                         xUART_CONFIG_PAR_NONE));

    xUARTEnable(xUART0_BASE, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));

    UARTBufferWrite(UART0_BASE, "NUC1xx.UART.BAUDRATE EXAMPLE \r\n", sizeof("NUC1xx.UART.BAUDRATE EXAMPLE \r\n")); 
}
示例#29
0
文件: UartPrintf.c 项目: 0xc0170/cox
//*****************************************************************************
//
//! \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);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    xSPinTypeUART(UART0RX, PA8);
    xSPinTypeUART(UART0TX, PA9);

    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0);
    //
    // Set UART0 clock source.
    //
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_HCLK, 1);

    //
    // Configure 8 bit word length, 1 stop bit, 
    // and none parity bit, receive FIFO 1 byte.
    //
    xUARTConfigSet(UART0_BASE, 115200, (xUART_CONFIG_WLEN_8 | 
                                        xUART_CONFIG_STOP_1 | 
                                        xUART_CONFIG_PAR_NONE));

    xUARTEnable(UART0_BASE, (UART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));
    
    for(i = 0; i < sizeof("HT32F125x.UART Example of CoX \r\n"); i++)
    {
        xUARTCharPut(UART0_BASE, ucData[i]);
    }
}
示例#30
0
//*****************************************************************************
//
//! \brief AT25FS0x test execute main body.
//!
//! \return None.
//
//*****************************************************************************
static void AT25FS0xExecute(void)
{
    unsigned long i;
    unsigned long ulID;
    unsigned char ulStatusVal;
    
    AT25FS0xPageWrite(ucWriteData,138,Length);
    xSysCtlDelay(50000000);
    AT25FS0xDataRead(ucReadData, 138, Length);
    for(i = 0; i < Length; i++)
    {
        TestAssert((ucWriteData[i] == ucReadData[i]), 
                 "w25xxx API \"AT25FS0xWrite() and AT25FS0xDataRead()\"error!");
    };
    
    ulID = AT25FS0xIDcodeGet();
    TestAssert((ulID == 0x202017), 
                 "w25xxx API \"W25XxxReadIDTest()\"error!");
    AT25FS0xChipErase();
    AT25FS0xDataRead(ucReadData, 0, Length);
    for(i = 0; i < Length; i++)
    {
        TestAssert((255 == (unsigned long)ucReadData[i]), 
                 "AT25FS0x API \"EraseChipTest()\"error!");
    } 
    
    //
    // Test AT25FS0x Read and write Status Register
    //
    AT25FS0xStatusRegWrite(0x1f);
    ulStatusVal = AT25FS0xStatusRegRead();
    TestAssert((ulStatusVal == 0x1f), 
                 "AT25FS0x API \"AT25FS0xRWSRTest()\"error!");
    

    
}