Exemple #1
0
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
*  Main function performs following functions:
*   1. Starts Character LCD and print project info
*   2. Starts SPI Master component
*   3. Configures the DMA transfer for RX and TX directions
*   4. Displays the results on Character LCD
*   
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
void main()
{
    uint8 i = 0u;
    CyGlobalIntEnable; 
    
    for(i=0u; i<8u; i++)
    {
        m_rxBuffer[i] = 0u;
    }
    
    LCD_Start();
    LCD_Position(0u,0u);
    LCD_PrintString("SPI Master");
    LCD_Position(1u,0u);
    LCD_PrintString("example");
    CyDelay(3000u);
    
    Dma_M_Tx_Configuration();
    Dma_M_Rx_Configuration();
    
    CyDmaChEnable(M_TxChannel, 1u); 
    CyDmaChEnable(M_RxChannel, 1u);
    
    LCD_Position(0u,0u);
    LCD_PrintString("Master Tx data:");
    LCD_Position(1u,0u);
    for(i=0u; i<8u; i++)
    {
        LCD_PrintHexUint8(m_txBuffer[i]);
    }
    
    CyDelay(5000u);
    SPIM_Start();
    
    while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE));
    
    LCD_ClearDisplay();
    LCD_PrintString("Master Rx data:");
    LCD_Position(1u,0u);
    
    for(i=0u; i<8u; i++)
    {
        LCD_PrintHexUint8(m_rxBuffer[i]);
    }
    CyDelay(5000u);
    LCD_ClearDisplay();
    LCD_PrintString("SPI Master");
    LCD_Position(1u,0u);
    LCD_PrintString("example complete.");
     
    for(;;)
    {
        
    }
}
void main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    uint16 adc, compare;
    
    LCD_Start();
    ADC_Start();
    PWM_Start();
    
    

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
    for(;;)
    {
        /* Place your application code here. */
//        LCD_ClearDisplay();
        LCD_Start();
        
        adc = 0;
        ADC_StartConvert();
        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
        ADC_StopConvert();
        adc = ADC_GetResult16();
        
        if(adc > 255)
        {
            if(adc == 0xFFFF) /* underflow correction */
            {
                adc = 0x00;
            }
            else
            adc = 0xFF; /* Overflow correction */
        }    
        
        LCD_Position(0,0);
        LCD_PrintHexUint8(adc);
                
        compare = (uint16)(1000 + ((float)((float)((float)adc / (float)255) * (float)1000)));
        LCD_Position(1,0);
        LCD_PrintDecUint16(compare);
        
        PWM_WriteCompare(compare);
        PWM_WritePeriod(compare + 39999);
    }
}
Exemple #3
0
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
*  Main function performs following functions:
*   1. Starts Character LCD and print project info
*   2. Starts SPI Master component
*   3. Configures the DMA transfer for RX and TX directions
*   4. Displays the results on Character LCD
*   
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
int main()
{
    uint8 i;
    
    LCD_Start();
    LCD_Position(0u,0u);
    LCD_PrintString("SPI Master");
    LCD_Position(1u,0u);
    LCD_PrintString("example");
    CyDelay(2000u);
    
    DmaTxConfiguration();
    DmaRxConfiguration();
    
    SPIM_Start();
    
    CyDmaChEnable(rxChannel, STORE_TD_CFG_ONCMPLT);
    CyDmaChEnable(txChannel, STORE_TD_CFG_ONCMPLT);

    while (0u == (SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE))
    {
    }
    
    LCD_ClearDisplay();
    LCD_PrintString("Master Rx data:");
    LCD_Position(1u,0u);
    
    for(i=0u; i<BUFFER_SIZE; i++)
    {
        LCD_PrintHexUint8(rxBuffer[i]);
    }

    for(;;)
    {
    }
}