/******************************************************************************* * Function Name: main ******************************************************************************** * * Summary: * Main function performs following functions: * 1. Starts used components. * 2. Waits for, then receives data sent by SPI master. * 3. Displays this data on Character LCD. * * Parameters: * None. * * Return: * None. * *******************************************************************************/ void main() { /* Start SPI Slave and Character LCD */ SPIS_Start(); LCD_Char_Start(); for(;;) { /* Check if RxBuffer is non-empty If true, the SPI slave has received * data. */ if(SPIS_GetRxBufferSize()) { /* Read and display received data on the LCD and verify this is same * as sent by master. */ LCD_Char_ClearDisplay(); LCD_Char_PrintString("0x"); LCD_Char_PrintInt16(SPIS_ReadRxData()); SPIS_ClearRxBuffer(); } } /* End forever loop */ } /* End main */
int main() { uint16 timerPeriod; int i; uint8 rxBuffer[SPIS_RX_PACKET_SIZE]; uint8 txBuffer[SPIS_TX_PACKET_SIZE]; char strBuffer[80]; CyGlobalIntEnable; /* Enable global interrupts. */ LCD_Char_Start(); LCD_Char_PrintString(TITLE_STR1); LCD_Char_Position(1, 0); LCD_Char_PrintString(TITLE_STR2); CyDelay(2000); IDAC8_Start(); Opamp_IV_Conv_Start(); LCD_Char_ClearDisplay(); LCD_Char_PrintString("Initialize OK."); CyDelay(1000); SPIS_Start(); Timer_Sampling_Start(); ISR_Timer_Sampling_StartEx(ISR_Saw_handler); frequency10 = 4400; squareDuty = 127; waveShape = WAVESHAPE_SAW; for(;;) { Pin_Check1_Write(1); if (Pin_SW1_Read() == 0u) { waveShape++; if (waveShape >= WAVESHAPE_N) { waveShape = WAVESHAPE_SQUARE; } switch (waveShape) { case WAVESHAPE_SQUARE: ISR_Timer_Sampling_StartEx(ISR_Square_handler); break; case WAVESHAPE_SAW: ISR_Timer_Sampling_StartEx(ISR_Saw_handler); break; } } squareDuty += (readRE() << 2); if (SPIS_RX_PACKET_SIZE <= SPIS_SpiUartGetRxBufferSize()) { // RX for (i = 0; i < SPIS_RX_PACKET_SIZE; i++) { rxBuffer[i] = SPIS_SpiUartReadRxData(); } frequency10 = ((uint16)rxBuffer[1] << 8) | rxBuffer[2]; // TX txBuffer[0] = rxBuffer[0]; txBuffer[1] = rxBuffer[1]; txBuffer[2] = rxBuffer[2]; SPIS_SpiUartPutArray(txBuffer, SPIS_TX_PACKET_SIZE); // コマンドの実行 timerPeriod = SAMPLING_CLOCK * 10 / (frequency10 * 256); Timer_Sampling_WritePeriod(timerPeriod); // LCDに表示 sprintf(strBuffer, "RX: %03u %03u %03u \r\n", rxBuffer[0], rxBuffer[1], rxBuffer[2]); UART_UartPutString(strBuffer); LCD_Char_ClearDisplay(); strBuffer[15] = 0; LCD_Char_Position(0, 0); LCD_Char_PrintString(strBuffer); sprintf(strBuffer, "%ld %d %d ", frequency10, timerPeriod, squareDuty); UART_UartPutString(strBuffer); LCD_Char_Position(1, 0); LCD_Char_PrintString(strBuffer); } Pin_Check1_Write(0); //CyDelay(200); } }