int main() { uint8 ch; /* Data sent on the serial port */ uint8 count = 0u; /* Initializing the count value */ uint8 pos = 0u; CyGlobalIntEnable; isr_1_Start(); /* Initializing the ISR */ UART_1_Start(); /* Enabling the UART */ LCD_Char_1_Start(); /* Enabling the LCD */ for(ch = START_CHAR_VALUE; ch <= END_CHAR_VALUE; ch++) { UART_1_WriteTxData(ch); /* Sending the data */ count++; if(count % LCD_NUM_COLUMNS == 0u) /* If the count value reaches the count 16 start from first location */ { pos = 0u; /* resets the count value */ LCD_Char_1_WriteControl(LCD_Char_1_CLEAR_DISPLAY); /* Display will be cleared when reached count value 16 */ } LCD_Char_1_Position(0u, pos++); /* LCD position to the count++ */ LCD_Char_1_PutChar(ch); /* print the value in the LCD */ LCD_Char_1_Position(1u, 0u); LCD_Char_1_PrintInt8(count); /* prints the count in the LCD */ CyDelay(200u); } for(;;) {} }
/******************************************************************************* * 初始化函数 ********************************************************************************/ void init() { CyGlobalIntEnable; //全局中断开启 ADC_DelSig_1_Start(); /* 配置并开启ADC */ ADC_DelSig_1_StartConvert(); /* 开始进行转换 */ Uart_Rx_ISR_StartEx(RxInterruptHandler); /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */ Uart_Tx_ISR_StartEx(TxInterruptHandler); /* 开启 Uart Tx 并连接到 TxInterruptHandler */ UART_Start(); /* 开启 UART */ Uart_Rx_ISR_1_StartEx(Rx_1_InterruptHandler); /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */ Uart_Tx_ISR_1_StartEx(Tx_1_InterruptHandler); /* 开启 Uart Tx 并连接到 TxInterruptHandler */ UART_1_Start(); /* 开启 UART1 */ Uart_Rx_ISR_2_StartEx(Rx_1_InterruptHandler); /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */ Uart_Tx_ISR_2_StartEx(Tx_1_InterruptHandler); /* 开启 Uart Tx 并连接到 TxInterruptHandler */ UART_2_Start(); /* 开启 UART2 */ Timer_ISR_StartEx(TimerInterruptHandler); /* 开启 Timer 中断并连接到 TimerInterruptHandler */ Timer_Start(); /* 开启定时器 */ LCD_Char_1_Start(); /* 初始化并清除LCD */ //LCD_Char_1_PrintString("init"); }
void main(){ UART_1_Start(); /* choose when we receive interrupts from tx and rx */ UART_1_SetTxInterruptMode(UART_1_TX_STS_COMPLETE); UART_1_SetRxInterruptMode(UART_1_RX_STS_FIFO_NOTEMPTY); CyGlobalIntEnable; UART_1_ClearTxBuffer(); UART_1_ClearRxBuffer(); LCD_Char_1_Start(); LCD_Char_1_Position(0,0); /* initialize our source data to index */ int j; for(j = 0; j < DATA_SIZE; ++j){ sourceData[j] = j; } /* enable our interrupt routines */ isr_1_StartEx(tx_int); isr_2_StartEx(rx_int); /* idle loop until we finish our transmission */ while(!rx_done){} int k; int errors = 0; /* data validation */ for(k = 0; k < DATA_SIZE; ++k) if(sourceData[k] != receiveData[k]) ++errors; /* print errors to lcd */ LCD_Char_1_PrintString("errors: "); LCD_Char_1_PrintNumber(errors); LCD_Char_1_Position(1,0); LCD_Char_1_PrintString("tx:"); LCD_Char_1_PrintNumber(tx_cnt); LCD_Char_1_PrintString(" rx:"); LCD_Char_1_PrintNumber(rx_cnt); for(;;){ } }
void main(){ /* initialize UART */ UART_1_Start(); /* disable interrupts */ UART_1_DisableRxInt(); UART_1_DisableTxInt(); UART_1_ClearTxBuffer(); UART_1_ClearRxBuffer(); LCD_Char_1_Start(); LCD_Char_1_Position(0,0); /* initialize or source array */ int j; for(j = 0; j < DATA_SIZE; ++j){ sourceData[j] = j; } /* loop to transmit all 4096 bytes of our source array */ int i; for(i = 0; i < DATA_SIZE; ++i){ UART_1_WriteTxData(sourceData[i]); /* we check the receiver FIFO to see when we get the data */ while(UART_1_ReadRxStatus() != UART_1_RX_STS_FIFO_NOTEMPTY){} /* if FIFO is not empty, save the data */ receiveData[i] = UART_1_ReadRxData(); } int k; int errors = 0; /* loop through received data to verify it */ for(k = 0; k < DATA_SIZE; ++k) if(sourceData[k] != receiveData[k]) ++errors; /* print errors */ LCD_Char_1_PrintString("errors: "); LCD_Char_1_PrintNumber(errors); for(;;){ } }
/******************************************************************************* * Function Name: main ******************************************************************************** * * Summary: * Main function performs following functions: * 1: Initializes the LCD * 2: Get the temperature of the Die * 3: Print the Die Temperature value in LCD * 4: Print the Status value in the LCD * * Parameters: * None. * * Return: * None. * *******************************************************************************/ int main() { cystatus Status; int16 temperature; /* Initializing the LCD */ LCD_Char_1_Start(); while(1) { /* Providing some delay */ CyDelay(50); /* Reading the Die Temperature value */ Status = DieTemp_1_GetTemp(&temperature); /* Displaying the Die Temperature value on the LCD */ LCD_Char_1_Position(0u, 0u); LCD_Char_1_PrintString("Temp = "); if (temperature >= 0) { LCD_Char_1_PrintString("+"); } else { /* If the temperature value is negative, display "-" sign and make value positive */ LCD_Char_1_PrintString("-"); temperature = (uint16)(~temperature + 1u); } LCD_Char_1_PrintNumber((uint16) (temperature)); LCD_Char_1_PrintString(" "); LCD_Char_1_PutChar(LCD_Char_1_CUSTOM_7); LCD_Char_1_PrintString("C"); /* Displaying the status value on the LCD */ LCD_Char_1_Position(1u, 0u); LCD_Char_1_PrintString("Status = "); LCD_Char_1_PrintInt8((uint8) Status); } }
/*main*/ void main(void) { /*Preliminary parts not important*/ LCD_Char_1_Start(); ADC_DelSig_1_Start(); ADC_DelSig_1_StartConvert(); Configure_DMA(); isr_1_StartEx(Buffer_complete); isr_2_StartEx(LPF_buffer_complete); ADC_DelSig_1_SetCoherency(ADC_DelSig_1_COHER_MID); Filter_SetDalign(Filter_STAGEA_DALIGN,Filter_ENABLED); Filter_SetDalign(Filter_HOLDA_DALIGN,Filter_ENABLED); Filter_SetCoherency(Filter_STAGEA_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_HOLDA_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_CHANNEL_A,Filter_KEY_MID); Filter_SetDalign(Filter_STAGEB_DALIGN,Filter_ENABLED); Filter_SetDalign(Filter_HOLDB_DALIGN,Filter_ENABLED); Filter_SetCoherency(Filter_STAGEB_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_HOLDB_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_CHANNEL_B,Filter_KEY_MID); CyGlobalIntEnable; Filter_Start(); /*Writes ADC values to ADC_samples array*/ while(1){ if (isr_BC_flag==1){ arm_cfft_q15(&arm_cfft_sR_q15_len256, Buffer_samples, 0, 1); arm_cmplx_mag_q15(Buffer_samples, magoutput, fftlength); CyDmaChEnable(DMA_2_Chan, 1); isr_BC_flag=0; isr_1_ClearPending(); } } }
void main() { CYGlobalIntEnable; /* Enable global interrupts */ ADC_DelSig_1_Start();/* Configure and power up ADC */ LCD_Char_1_Start(); /* Initialize and clear the LCD */ /* Move the cursor to Row 0 Column 0 */ LCD_Char_1_Position(ROW_0,COLUMN_0); /* Print Label for the pot voltage raw count */ LCD_Char_1_PrintString("TEMP NOW: C"); LCD_Char_1_Position(ROW_1,COLUMN_0); LCD_Char_1_PrintString("TEMP SET: C"); ADC_DelSig_1_StartConvert(); /* Force ADC to initiate a conversion */ /* Start capsense and initialize baselines and enable scan */ CapSense_Start(); CapSense_InitializeAllBaselines(); CapSense_ScanEnabledWidgets(); /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */ //Start the pwm; PWM_1_Start(); for(;;) { /* If scanning is completed update the baseline count and check if sensor is active */ while(CapSense_IsBusy()); /* Update baseline for all the sensors */ CapSense_UpdateEnabledBaselines(); CapSense_ScanEnabledWidgets(); /* Test if button widget is active */ stateB_1 = CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN); stateB_2 = CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN); /* Wait for end of conversion */ ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT); /* Get converted result */ voltageRawCount = ADC_DelSig_1_GetResult16(); //Change voltageRawCount to Temperature; temp = voltageRawCount / 3.870 * 0.1017 + 0.5; cold = (9999 - (temp > temp_set ? temp - temp_set : 0) * 50); if(cold < 1000) cold = 1000; if(cold > 9999) cold = 9999; //Change the pwm; PWM_1_WriteCompare(cold); /* Set range limit */ if (temp > 0x7FFF) { temp = 0; } else { /* Continue on */ } if(show < 10) { show++; } else { show = 0; UpdateDisplay(temp, 0); /* Print result on LCD */ UpdateButtonState(stateB_1, stateB_2); } } }