コード例 #1
0
ファイル: main.c プロジェクト: Kledal/semesterprojekt3
int main()
{
    CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */
    isr_1_StartEx(nunchuck_isr);
   
    VDAC_Start();
    
    
    I2C_1_Start();
    SendHandshake();
    for(;;)
    {
        GetDataFromNunChuck();
        CyDelay(1);
        int test = GetJoystickY();
        VDAC_SetValue(test + 126);
    }
}
コード例 #2
0
/*******************************************************************************
* Function Name: void processDAC( void )
********************************************************************************
*
* Summary:
*  This function sets the DAC output voltage based on the value copied from the I2C register.
*******************************************************************************/
void processDAC(void)
{
    static int32   dacValPrev = 0;
    float32 dacVal;
    int32   dacCode;

    /* Set VDAC value if it has changed */
    dacVal = LocData.dacVal;
    if(dacValPrev != dacVal)
    {
        dacValPrev = dacVal;
        // DAC range is 2.4V, Valid inputs are -4096 to 4094
        dacCode = (int32)(((dacVal * 8192.0)/2.4) - 4096.0);
        if (dacCode < -4096)
        {
            dacCode = -4096;
        }
        VDAC_SetValue(VDAC_SaturateTwosComp(dacCode));
    }
}