예제 #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
파일: T00006x.c 프로젝트: AlexGora/cox
//*****************************************************************************
//
//! \brief Init the ADC with the corresponding configuration in the
//! LPR5150AL_Configure gorup.
//!
//! \return None.
//
//*****************************************************************************
void
LPR5150ALInit()
{
	//
	// Select the ADC clock source
	//
    xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_HCLK, 3);

    //
    // Enable Peripheral ADC0
    //
    xSysCtlPeripheralEnable2(LPR5150AL_ADC_BASE);

    //
    // Configure Some GPIO pins as ADC Mode
    //
    XAXIS_PIN_IN_CFG();
    YAXIS_PIN_IN_CFG();

    //
    // Enable the ADC
    //
    xADCEnable(LPR5150AL_ADC_BASE);

    //
    // ADC Channel0 convert once, Software tirgger.
    //
    xADCConfigure(LPR5150AL_ADC_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR);

    //
    // Enable the channel2/3
    //
    xADCStepConfigure(LPR5150AL_ADC_BASE, 0, xADC_CTL_CH2);
    xADCStepConfigure(LPR5150AL_ADC_BASE, 1, xADC_CTL_CH3);

    //
    // ADC start Convert
    //
    xADCProcessorTrigger(LPR5150AL_ADC_BASE);
}
예제 #3
0
파일: main.c 프로젝트: ptLong/Embedded-Pi
int main()
{
    unsigned long i;
    unsigned char ucRet = 0;
    unsigned long ulValueLength;
    unsigned long ulData[10];


    xPWMotorControl();

    HD44780Init();

    //
    // 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 end of conversion interrupt
    //
    //xADCIntEnable(xADC0_BASE, xADC_INT_END_CONVERSION);

    //
    // install the call back interrupt
    //
    //xADCIntCallbackInit(xADC0_BASE, ADCCallback);

    //
    // Enable the NVIC ADC interrupt
    //
    //xIntEnable(xINT_ADC0);

    //
    // Enable the adc
    //
    xADCEnable(xADC0_BASE);

    //
    // start ADC convert
    //
    xADCProcessorTrigger( xADC0_BASE );

    HD44780LocationSet(0, 0);
    HD44780DisplayString("Hello Nuvoton!");
    HD44780LocationSet(0, 1);
    HD44780DisplayString("Hello CooCox! ");

    SysCtlDelay(10000000);

    while(1)
    {
        SysCtlDelay(1000000);
        //
        // Read the convert value
        //
        ulValueLength = xADCDataGet(xADC0_BASE, ulData);


        if (ulData[0] < 0x30100)
        {
            HD44780DisplayClear();
            HD44780LocationSet(0, 0);
            HD44780DisplayString("right");
            SendData74HC595(0x60);
            sD11PinTypePWM();
            xPWMStart(xPWMB_BASE, xPWM_CHANNEL7);
            xGPIOSPinWrite(sD3, 1);
        }
        else if(ulData[0] < 0x30300)
        {
            HD44780DisplayClear();
            HD44780LocationSet(0, 0);
            HD44780DisplayString("up");
            ulDuty++;
            xPWMDutySet(xPWMB_BASE, xPWM_CHANNEL7, ulDuty);
            sD11PinTypePWM();
            xPWMStart(xPWMB_BASE, xPWM_CHANNEL7);
            xGPIOSPinWrite(sD3, 1);
            SysCtlDelay(100000);
        }
        else if(ulData[0] < 0x30600)
        {
            HD44780DisplayClear();
            HD44780LocationSet(0, 0);
            HD44780DisplayString("dowm");
            ulDuty--;
            xPWMDutySet(xPWMB_BASE, xPWM_CHANNEL7, ulDuty);
            sD11PinTypePWM();
            xPWMStart(xPWMB_BASE, xPWM_CHANNEL7);
            xGPIOSPinWrite(sD3, 1);
            SysCtlDelay(100000);

        }
        else if(ulData[0] < 0x30900)
        {
            HD44780DisplayClear();
            HD44780LocationSet(0, 0);
            HD44780DisplayString("left");
            SendData74HC595(0x18);
            sD11PinTypePWM();
            xPWMStart(xPWMB_BASE, xPWM_CHANNEL7);
            xGPIOSPinWrite(sD3, 1);
        }
        else if(ulData[0] < 0x30E00)
        {
            HD44780DisplayClear();
            HD44780LocationSet(0, 0);
            HD44780DisplayString("select");
            SendData74HC595(0x60);
            sD11PinTypePWM();
            xPWMStart(xPWMB_BASE, xPWM_CHANNEL7);
            xGPIOSPinWrite(sD3, 1);
        }
        else
        {
            HD44780DisplayClear();
            HD44780LocationSet(0, 0);
            HD44780DisplayString("Nothing");
            xPWMStop(xPWMB_BASE, xPWM_CHANNEL7);
            xGPIOSPinTypeGPIOOutput(sD11);
            xGPIOSPinTypeGPIOOutput(sD3);
            xGPIOSPinWrite(sD11, 0);
            xGPIOSPinWrite(sD3, 0);
        }
        if(ulDuty >= 99)
        {
            ulDuty = 99;
        }
        if(ulDuty <= 1)
        {
            ulDuty = 1;
        }
    }

    //
    // SD Card Init
    //
    ucRet = SDInit();

    //
    // write a block to the card
    //
    ucRet = SDBlockWrite(pucBuf, 0);

    //
    // Re-init the test buffer to 0
    //
    for(i = 0; i < 512; i++)
    {
        pucBuf[i] = 0;
    }

    //
    // Read 1 block from the card
    //
    ucRet = SDBlockRead(pucBuf, 0);

    while(1);
}
예제 #4
0
//*****************************************************************************
//
//! \brief Init the sensor shield board.
//!
//! \param None.
//!
//! Init the sensor shield board.
//!
//! \return None
//
//*****************************************************************************
void
SensorShieldInit(void)
{
#if(SENSOR_SHIELD_OUT_USED > 0)
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O0);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O1);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O2);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O3);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O4);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O5);

#endif

#if((SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG))

    xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_HCLK, 3);
    //
    // Enable Peripheral ADC0
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC0);

    //
    // Configure Some GPIO pins as ADC Mode
    //

    //
    // Enable the adc
    //
    xADCEnable(xADC0_BASE);

    //
    // ADC Channel0 convert once, Software tirgger.
    //
    xADCConfigure(xADC0_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR);

    //
    // Enable the channel0
    //

    //
    // Set Compare Condition(Moisture Sensor Limited Value)
    //
    xADCCompConditionConfig(ADC_BASE, 0, xADC_COMP_INT_LOW);
    ADCCompDataSet(ADC_BASE, 0, 1600, 1);
    xADCCompEnable(ADC_BASE, 0);
    //
    // Enable the ADC end of conversion interrupt
    //
    xADCIntEnable(xADC0_BASE, xADC_INT_COMP);

    //
    // install the call back interrupt
    //
    xADCIntCallbackInit(xADC0_BASE, ADCCallback);

    //
    // Enable the NVIC ADC interrupt
    //
    xIntEnable(xINT_ADC0);

    xADCProcessorTrigger(xADC0_BASE);

#endif

#if(SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG)
    sA0PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH0);

#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A0);
#endif

#if(SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG)
    sA1PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH1);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A1);
#endif

#if(SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG)
    sA2PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH2);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A2);
#endif

#if(SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG)
    sA3PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH3);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A3);
#endif

#if(SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG)
    sA4PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH4);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A4);
#endif

#if(SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG)
    sA5PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH5);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A5);
#endif

#if(SENSOR_SHIELD_I2C_USED > 0)
    //
    // Enable the GPIOx port which is connected with I2C
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SDA));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SCK));

    //
    // Enable the I2Cx which is connected with device
    //
    xSysCtlPeripheralEnable2(sI2C_BASE);

    //
    // Set BH1750_PIN_I2C_CLK as CLK
    //
    sPinTypeI2C(sI2C_BASE);

    //
    // Configure MCU as a master device and Set Clcok Rates
    //
    xI2CMasterInit(sI2C_BASE, 100000);
    xI2CMasterEnable(sI2C_BASE);
#endif

#if(SENSOR_SHIELD_UART_USED > 0)
    xSysCtlPeripheralEnable2(sUART_BASE);
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART1_MAIN, 1);
    sPinTypeUART(sUART_BASE);
    xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 |
                                        xUART_CONFIG_STOP_1 |
                                        xUART_CONFIG_PAR_NONE));
#endif
}
예제 #5
0
//*****************************************************************************
//
//! \brief Initialize the sensor shield board.
//!
//! \param None.
//!
//! Initialize the sensor shield board.
//!
//! \return None
//
//*****************************************************************************
void
SensorShieldInit(void)
{
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O0));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O1));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O2));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O3));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O4));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O5));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I0));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I1));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I2));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I3));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I4));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I5));
#if(SENSOR_SHIELD_OUT_USED > 0)

    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O0);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O1);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O2);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O3);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O4);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O5);
    //xSysCtlPeripheralEnable2();
#endif

#if((SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG))

    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(sD45));

    //
    // Set ADCCLK prescaler, ADCCLK=PCLK2(max 72MHz)/Div(Div:2,4,6,8)
    // You should set ADCCLK < 14MHz to ensure the accuracy of ADC
    //
    xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_MAIN, 8);
    //
    // Enable Peripheral ADC clock
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC1);


    //
    // Enable the ADC conversion
    //
    xADCEnable(sADC_BASE);

    //
    // The two sentences below configure ADC to scan mode, continuous convert, software trigger.
    //
    xADCConfigure(sADC_BASE, xADC_MODE_SCAN_SINGLE_CYCLE, ADC_TRIGGER_PROCESSOR);
    xADCConfigure(sADC_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR);

    //
    // Configure channel step by step.(Max 4 steps, the 2nd parameter start from 0, max is 3)
    // Must not jump over a step, or the ADC result may be in wrong position.
    //
    xADCStepConfigure(sADC_BASE, 0, sADC_CH0);
    xADCStepConfigure(sADC_BASE, 1, sADC_CH1);
    xADCStepConfigure(sADC_BASE, 2, sADC_CH2);
    xADCStepConfigure(sADC_BASE, 3, sADC_CH3);

#endif

#if(SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG)
    sA0PinTypeADC();
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I0);
#endif

#if(SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG)
    sA1PinTypeADC();
#elif (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I1);
#endif

#if(SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG)
    sA2PinTypeADC();
#elif (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I2);
#endif

#if(SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG)
    sA3PinTypeADC();
#elif (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I3);
#endif

#if(SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG)||  \
       (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I4);
#endif

#if(SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG)||  \
	   (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I5);
#endif

#if(SENSOR_SHIELD_I2C_USED > 0)
    //
    // Enable the GPIOx port which is connected with I2C
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SDA));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SCK));

    //
    // Enable the I2Cx which is connected with device
    //
    xSysCtlPeripheralEnable2(sI2C_BASE);

    //
    // Set BH1750_PIN_I2C_CLK as CLK
    //
    sPinTypeI2C(sI2C_BASE);

    //
    // Configure MCU as a master device and Set Clcok Rates
    //
    xI2CMasterInit(sI2C_BASE, 100000);
    xI2CMasterEnable(sI2C_BASE);
#endif

#if(SENSOR_SHIELD_UART_USED > 0)
    xSysCtlPeripheralEnable2(sUART_BASE);
//    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART1_MAIN, 1);
    sPinTypeUART(sUART_BASE);
    xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 |
                                        xUART_CONFIG_STOP_1 |
                                        xUART_CONFIG_PAR_NONE));
#endif
}