Beispiel #1
0
/***********************************Main***********************************/
int main()
{
    int16 mav_data;
    ADC_ISR_StartEx(ADC_interrupt);
    CyGlobalIntEnable;
    UART_Start();                       /* Initialize ADC */    
    ADC_Start();                        /* Initialize ADC */
    ADC_StartConvert();                 /* Start ADC conversions */
    ADC_IRQ_Enable();                   /* Enable ADC interrupts */    
    
    for (;;)
    {      
        if(data_ready)
        {  
            mav_data = mavg_filter(accgroen);
            gradergroen = grader(mav_data);
            //UART_UartPutChar(mav_data);
            //UART_UartPutChar(mav_data>>8);
            UART_UartPutChar(gradergroen);
            UART_UartPutChar(gradergroen>>8);

            data_ready = FALSE;
        }
    }
}
/*******************************************************************************
* Function Name: ADC_IRQ_StartEx
********************************************************************************
*
* Summary:
*  Sets up the interrupt and enables it. This function disables the interrupt,
*  sets the interrupt vector based on the address passed in, sets the priority 
*  from the value in the Design Wide Resources Interrupt Editor, then enables 
*  the interrupt to the interrupt controller.
*  
*  When defining ISR functions, the CY_ISR and CY_ISR_PROTO macros should be 
*  used to provide consistent definition across compilers:
*  
*  Function definition example:
*   CY_ISR(MyISR)
*   {
*   }
*   Function prototype example:
*   CY_ISR_PROTO(MyISR);
*
* Parameters:  
*   address: Address of the ISR to set in the interrupt vector table.
*
* Return:
*   None
*
*******************************************************************************/
void ADC_IRQ_StartEx(cyisraddress address)
{
    /* For all we know the interrupt is active. */
    ADC_IRQ_Disable();

    /* Set the ISR to point to the ADC_IRQ Interrupt. */
    ADC_IRQ_SetVector(address);

    /* Set the priority. */
    ADC_IRQ_SetPriority((uint8)ADC_IRQ_INTC_PRIOR_NUMBER);

    /* Enable it. */
    ADC_IRQ_Enable();
}
Beispiel #3
0
void main()
{
	ISR_UpBuff_Start(); //Start the Interrupt Component.
	ISR_UpBuff_SetVector(BufferUpdate);//Set Vector to the above ISR.
	
    CyGlobalIntEnable;//Enable Global Interrupts,EzI2C ad ADC require them.
	
	EZI2C_Start();//Start the EzI2C component.
	EZI2C_SetBuffer1(BUFFER_SIZE,BUFFER_RW_AREA_SIZE,(void *) (&EZI2C_Buffer));//Configure the Buffer for the EzI2C Component.
	
	ADC_Start();//Start the ADC
	ADC_IRQ_Enable();//Enable the EOC Interrupt
	ADC_StartConvert();//Start the Conversion
	
    for(;;);//Everything is done in the ISR.
}
/*******************************************************************************
* Function Name: int  main( void )
********************************************************************************/
int main(void)
{
    uint32  i;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    EZI2C_Start();
    #ifdef ENABLE_TUNER
    EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),(uint8 *)&CapSense_dsRam);        
    #else
    EZI2C_EzI2CSetBuffer1(sizeof(I2Cbuf), RW, (void *) &I2Cbuf);     
    #endif   
    
    SmartIO_Start();    
    VDAC_Start();
    PVref_ALS_Start();
    Opamp_ALS1_Start();
    Opamp_ALS2_Start();
    PVref_Therm_Start();
    Opamp_Therm_Start();    
    ADC_Start();
    ADC_IRQ_Enable();
    
    CapSense_Start();   
    /* Over-ride IDAC values for buttons but keep auto for Prox and Humidity */
    CapSense_BUTTON0_IDAC_MOD0_VALUE =          7u;
    CapSense_BUTTON0_SNS0_IDAC_COMP0_VALUE =    6u;
    CapSense_BUTTON1_IDAC_MOD0_VALUE =          7u;
    CapSense_BUTTON1_SNS0_IDAC_COMP0_VALUE =    7u;
    CapSense_BUTTON2_IDAC_MOD0_VALUE =          9u;
    CapSense_BUTTON2_SNS0_IDAC_COMP0_VALUE =    7u;
    CapSense_BUTTON3_IDAC_MOD0_VALUE =          9u;
    CapSense_BUTTON3_SNS0_IDAC_COMP0_VALUE =    8u;
    /* Setup first widget and run the scan */    
    CapSense_SetupWidget(CapSense_BUTTON0_WDGT_ID);
    CapSense_Scan();      
    
    /* Start SysTick Timer to give a 1ms interrupt */
    CySysTickStart();
    /* Find unused callback slot and assign the callback. */
    for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
    {
        if (CySysTickGetCallback(i) == NULL)
        {
            /* Set callback */
            CySysTickSetCallback(i, SysTickISRCallback);
            break;
        }
    }
    
    /* Initialize I2C and local data registers to 0's */
    I2Cbuf.dacVal = 0.0;
    I2Cbuf.ledVal = 0x00;
    I2Cbuf.ledControl = 0x00;
    I2Cbuf.buttonVal = 0x00;
    I2Cbuf.temperature = 0.0;
    I2Cbuf.humidity = 0.0;
    I2Cbuf.illuminance = 0.0;
    I2Cbuf.potVal = 0.0;
    
    LocData.dacVal = 0.0;
    LocData.ledVal = 0x00;
    LocData.ledControl = 0x00;
    LocData.buttonVal = 0x00;
    LocData.temperature = 0.0;
    LocData.humidity = 0.0;
    LocData.illuminance = 0.0;
    LocData.potVal = 0.0;
    
    for(;;)
    {
        processButtons();  /* Mechanical buttons and bootloader entry */
        processCapSense(); /* CapSense Scanning */
        processDAC();      /* VDAC output voltage setting */
        processADC();      /* Process ADC results after each scan completes */
        processI2C();      /* Copy date between I2C registers and local operating registers */
    }
} /* End of main */