/** * @brief Text * @param None * @retval None */ void backgroundTask(void *pvParameters) { prvHardwareInit(); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); /* Create the blink timer */ prvBlinkTimer = xTimerCreate("RefreshTimer", 500 / portTICK_PERIOD_MS, pdTRUE, 0, prvBlinkTimerCallback); if (prvBlinkTimer != NULL) xTimerStart(prvBlinkTimer, portMAX_DELAY); UART1_Init(); vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); I2C_EEPROM_Init(); // I2C_EEPROM_WriteByte(0x00, 0xEC); // data = 0x00; // data = I2C_EEPROM_ReadByte(0x00); // if (data != 0xEC) // BUZZER_BeepNumOfTimes(20); // else // BUZZER_BeepNumOfTimes(5); while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); } }
int main(void) { uint32_t u32Item; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); do{ TestItem(); u32Item = getchar(); printf("%c\n",u32Item); switch(u32Item) { case '1': UART_FunctionTest(); break; case '2': IrDA_FunctionTest(); break; case '3': RS485_FunctionTest(); break; case '4': LIN_FunctionTest(); break; case '5': AutoFlow_FunctionTest(); break; case '6': LIN_FunctionTestUsingLinCtlReg(); break; default: break; } }while(u32Item != 27); }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART0_Init(); UART1_Init(); printf("\n\n"); printf("+------------------------------------------------------------+\n"); printf("| NuMicro USB Virtual COM Dual Port Sample Code |\n"); printf("+------------------------------------------------------------+\n"); USBD_Open(&gsInfo, VCOM_ClassRequest, NULL); /* Endpoint configuration */ VCOM_Init(); USBD_Start(); NVIC_EnableIRQ(USBD_IRQn); NVIC_EnableIRQ(UART0_IRQn); NVIC_EnableIRQ(UART1_IRQn); while(1) { VCOM_TransferData(); } }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS->REGWRPROT = 0x59; SYS->REGWRPROT = 0x16; SYS->REGWRPROT = 0x88; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS->REGWRPROT = 0x0; /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART RS485 sample master function */ RS485_9bitModeMaster(); while(1); }
/** * @brief Configure UART1 for the communication with HyperTerminal * @param None * @retval None */ void UART1_Config(void) { /* EVAL COM (UART) configuration -----------------------------------------*/ /* USART configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - Odd parity - Receive and transmit enabled - UART Clock disabled */ UART1_Init((uint32_t)115200, UART1_WORDLENGTH_8D,UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE); /* Enable the UART Receive interrupt: this interrupt is generated when the UART receive data register is not empty */ //UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE); /* Enable the UART Transmit complete interrupt: this interrupt is generated when the UART transmit Shift Register is empty */ UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE); /* Enable UART */ UART1_Cmd(ENABLE); /* Enable general interrupts */ // enableInterrupts(); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART RS485 sample master function */ RS485_FunctionTest(); while(1); }
void main() { int i; trisb=0; portb=0; Lcd_Init(); // Initialize LCD UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize while (1) // Endless loop { if (UART1_Data_Ready()) // If data is received, { for(i=0;i<100;i++) { uart_rd[i]= UART1_Read(); } for(i=0;i<100;i++) { Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,uart_rd[i]); delay_ms(10000); } } } }
void SetUp() { OSCCON = 0x70; OPTION_REG = 0x07; //タイマー0設定 ANSELA = 0x2F; ANSELB = 0x00; ANSELD = 0x00; ANSELE = 0x00; TRISA = 0x2F; TRISB = 0x20; TRISC = 0x00; TRISD = 0x00; TRISE = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; PORTE = 0x00; ADC_Init(); UART1_Init(9600); #if DEBUG_MODE Soft_UART_Init(&PORTB, 4, 6, 9600, 0); #else Soft_UART_Init(&PORTB, 6, 4, 9600, 0); #endif Delay_ms(10); }
int main(void) { /* Unlock protected registers */ SYS->REGWRPROT = 0x59; SYS->REGWRPROT = 0x16; SYS->REGWRPROT = 0x88; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS->REGWRPROT = 0x0; /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART auto flow sample slave function */ AutoFlow_FunctionRxTest(); while(1); }
// *************************** Capture image dimensions out of BMP********** int main(void){ TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz Output_Init(); ADC0_Init(); DAC_Init(); SysTick_Init(); Menu_Init(); Sound_Init(); UART1_Init(); Button0_Init(); Timer0_Init(Play, 80000000/11025); // 11.025 kHz 80000000/11025 Timer1_Init(Master_Funk, 80000000/60); //Timer2_Init(SomeUART function, high speed); //for UART /* ST7735_FillScreen(0x0000); // set screen to black ST7735_SetCursor(1, 1); ST7735_OutString("GAME OVER"); ST7735_SetCursor(1, 2); ST7735_OutString("Nice try,"); ST7735_SetCursor(1, 3); ST7735_OutString("Earthling!"); ST7735_SetCursor(2, 4); LCD_OutDec(1234); */ while(1){ } }
void PDMA_Example() { uint8_t unItem; /* Init System, IP clock and multi-function I/O */ SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register. /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for PDMA test */ UART1_Init(); do { /* PDMA Sample Code: UART1 Tx/Rx Loopback */ // printf("\n\n"); printf("+------------------------------------------------------------------------+\n"); printf("| PDMA Driver Sample Code |\n"); printf("| |\n"); printf("+------------------------------------------------------------------------+\n"); printf("| [1] Using TWO PDMA channel to test. < TX1(CH1)-->RX1(CH0) > |\n"); printf("| [2] Using ONE PDMA channel to test. < TX1-->RX1(CH0) > |\n"); printf("+------------------------------------------------------------------------+\n"); unItem = uart_getchar(); IsTestOver =FALSE; if((unItem=='1') || (unItem == '2')) { PDMA_UART(unItem); // printf("\n\n PDMA sample code is complete.\n"); } }while(unItem!=0x27); // return 0; }
void System_init(void) { System_Clock_init(); UART1_Init(); delay_init(16); HekrInit(UART1_SendChar); _asm("rim"); }
int main1(void){ TExaS_Init(); ADC_Init(); // turn on ADC, set channel to 1 ST7735_InitR(INITR_REDTAB); PortF_Init(); SysTick_Init(); // This makes things work UART1_Init(); while(1){} // do-nothing loop }
/********************************************** UART1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Receive and transmit enabled - Receive interrupt - UART1 Clock disabled *********************************************/ void Uart_Init(void) { UART1_DeInit(); UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, \ UART1_PARITY_NO , UART1_SYNCMODE_CLOCK_DISABLE , UART1_MODE_TXRX_ENABLE); UART1_ITConfig(UART1_IT_RXNE_OR,ENABLE ); UART1_Cmd(ENABLE ); }
//串口UART1初始化 void Init_UART(void) { //默认初始化 UART1_DeInit(); //设置波特率9600 8位数据 1位停止位 无校验 外部时钟不可用 模式接收发送 UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE); //设置接收寄存器溢出中断 UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE); }
void USART1_INIT(void) { // UART1_DeInit(); UART1_Init(9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1,UART1_PARITY_NO,UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE ); UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);//UART1_IT_RXNE_OR UART1->CR1 &= (uint8_t)(~UART1_CR1_UARTD); // UART1_Cmd(ENABLE); UART1_ClearFlag(UART1_FLAG_RXNE); }
void Config_UART1(void){ UART1_Init(9600); Delay_ms(100); /*UART1_Write_Text("Inicio"); UART1_Write(13); UART1_Write(10);*/ Lcd_Out(1, 1, "Inicia UART1"); delay_ms(2000); }
/** * @brief Example firmware main entry point. * @par Parameters: * None * @retval * None */ void main(void) { /*High speed internal clock prescaler: 1*/ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); /* Enable general interrupts */ enableInterrupts(); /* Deinitializes the UART1 and UART3 peripheral */ UART1_DeInit(); UART3_DeInit(); /* UART1 and UART3 configuration -------------------------------------------------*/ /* UART1 and UART3 configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - One Stop Bit - No parity - Receive and transmit enabled - UART1 Clock disabled */ /* Configure the UART1 */ UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE); /* Configure the UART3 */ UART3_Init((u32)9600, UART3_WORDLENGTH_8D, UART3_STOPBITS_1, UART3_PARITY_NO, UART3_MODE_TXRX_ENABLE); /* Enable UART3 Receive and UART1 Transmit interrupt */ UART3_ITConfig(UART3_IT_RXNE_OR, ENABLE); UART1_ITConfig(UART1_IT_TXE, ENABLE); /* Wait until end of transmission from UART1 to UART3 */ while (GetVar_RxCounter2() < GetVar_NbrOfDataToTransfer1()) { } /* Enable UART1 Receive and UART3 Transmit interrupt */ UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE); UART3_ITConfig(UART3_IT_TXE, ENABLE); /* Wait until end of transmission from UART3 to UART1 */ while (GetVar_RxCounter1() < GetVar_NbrOfDataToTransfer2()) { } /* Check the received data with the send ones */ TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, RxBufferSize1); /* TransferStatus1 = PASSED, if the data transmitted from UART3 and received by UART1 are the same */ /* TransferStatus1 = FAILED, if the data transmitted from UART3 and received by UART1 are different */ TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, RxBufferSize2); /* TransferStatus2 = PASSED, if the data transmitted from UART1 and received by UART3 are the same */ /* TransferStatus2 = FAILED, if the data transmitted from UART1 and received by UART3 are different */ while (1); }
/** * Hardware setup */ void setup(void) { Glcd_Init(); // Initialize GLCD Glcd_Fill(0x00); // Clear GLCD SREG_I_bit = 1; // Global interrupts enable UART1_Init(9600); // UART 1 baudrate UCSR0B = UCSR0B | 0b10000000; // Enable RX interrupt }
void BSP_Init(void) { SYSCLK_Init(); SysTick_Init(); LED_Config(); Out_GPIO_Init(); In_GPIO_Init(); UART1_Init(UART1_BAUD); UART2_Init(UART2_BAUD); }
void Initialize() { Delay_ms(2000); // Initialize USART UART1_Init(BAUD); Delay_ms(2000); // Initialize I2C Soft_I2C_Init(); Delay_ms(2000); }
static void init_usart1(void) { UART1_DeInit(); /* 波特率 115200 8位数据 1个停止位 。 无奇偶校验 */ UART1_Init((u32)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO,\ UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE); // UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE); // UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE); // UART1_ClearITPendingBit(UART1_IT_RXNE); // 清理中断标志位 }
void Init() { //-------Oscillator Configuration OSCCON=0b01100000; OSCTUNE.PLLEN=1; //-------AD Configuration ANCON0=0; ANCON1=0; //-------Port Configuration porta=0; portb=0; portc=0; portd=0; porte=0; trisa=0b11010111; trisb=0b11000000; trisc=0b10111101; trisd=0b01110000; trise=0b1111; //------TMR0 T0CON=0b10000001; //prescaler 4 TMR0H=0x63; TMR0L=0xBF; INTCON.b7=1; INTCON.T0IE=1; //------LCD Init LCD_Init(); //LCDSystem_Init(&LCD); LCD_cmd(_LCD_CURSOR_OFF); delay_ms(500); LCDBL=1; //-------UART UART1_Init(9600); //UART2_Init(9600); RC1IF_bit=0; RC1IE_bit=1; RC1IP_bit=1; PEIE_bit=1; UART_Set_Active(&UART1_Read, &UART1_Write, &UART1_Data_Ready, &UART1_Tx_Idle); //-------Signaling System SignalingSystem_Init(&SigSys); //-------Door Status DoorStatus=DOORSTATUS_Close; //-------LoadConfigs LoadConfig(); //-------RS485 RS485Slave_Init(NetworkAddress); }
void main() { int i=0; int j=0; int iu=0; DDRB = 0xFF; UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize while (1) { if (UART1_Data_Ready() == 1) { // if data is received UART1_Read_Text(packet, " ", 10); // reads text until 'OK' is found if ((packet[0] == 0x11)&&(packet[1] == 0x01) &&(packet[2] == 0x00)&&(packet[3] == 0x55) ) { packet[0] = 0x11; packet[1] = 0x01; packet[2] = 0x04; packet[3] = 0x00; packet[4] = 0x00; packet[5] = 0x01; packet[6] = 0x23; packet[7] = 0x59; packet[8] = 0xaa; UART1_Write(packet[0]); UART1_Write(packet[1]); UART1_Write(packet[2]); UART1_Write(packet[3]); UART1_Write(packet[4]); UART1_Write(packet[5]); UART1_Write(packet[6]); UART1_Write(packet[7]); UART1_Write(packet[8]); } } } // while (UART1_Data_Ready()) { // packet[i] = UART1_Read(); // i++; // } // Delay_ms(100); // j=0; // while (i>0) { // UART1_Write(packet[j]); // j++; // i--; // } }
/********************************************************************************************************* ** 函数名称: InitAllSP ** 函数功能: 对所有串口进行初始化 ** 入口参数: p_u32U2,p_u32U3,p_u32U5 串口2、3、5波特率 ** 出口参数: 无 ** 函数说明: 初始化网口 *********************************************************************************************************/ void InitAllSP(uint32 p_u32U2, uint32 p_u32U3, uint32 p_u32U5) { UART2Init(p_u32U2); //串口2 UART3Init(p_u32U3); //串口3 UART5Init(p_u32U5); //串口5 UART1_Init(); //串口1波特率为57600 memcpy(&g_sniLocal, (uint8 *)&SETUPALIAS.u32LocalIPAddress, sizeof(NetInfo)-2); InitializeW5100(&g_sniLocal);// }
void main() { UART1_Init(); ADC_Init(0xFF); while (1) { //UART1_Send_Char(ADC_Get_Result(1)); UART1_Send_Char(ADC_Get_Result(2)); Delay1000ms(); } }
void main (void) { UART1_Init(BAUDRATE); while(1) { SCON1 |= 0x01; printf("Received: %c\n",getchar1()); } }
void System_Init ( void ) { __set_PRIMASK ( 1 ); //¹Ø±Õ×ÜÖÐ¶Ï SYS_Init(); IO_Init(); I2C_Init(); // WDT_Init(); UART1_Init(); ADC_Init(); TMR0_Init(); __set_PRIMASK ( 0 ); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { SYS_Init(); UART0_Init(); UART1_Init(); GPIO_Init(); TMR0_Init(); TMR1_Init(); PWMA_Init(); PWMB_Init(); CKO_Init(); _GPIO_SET_PIN_MODE(PC, 12, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PE, 0, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PE, 2, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PE, 4, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PA, 10, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PA, 8, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PD, 9, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PD, 11, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PD, 13, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PB, 5, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PB, 7, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PE, 8, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PB, 0, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PB, 2, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PD, 6, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PD, 14, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PC, 5, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PC, 3, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PC, 1, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PE, 6, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PB, 11, GPIO_PMD_OUTPUT); /*_GPIO_SET_PIN_MODE(PA, 1, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PA, 2, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PA, 3, GPIO_PMD_OUTPUT); _GPIO_SET_PIN_MODE(PA, 4, GPIO_PMD_OUTPUT);*/ while (1) { } __WFI(); }
int main(void) { uint32_t u32Item; /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART sample LIN function */ do { TestItem(); u32Item = getchar(); printf("%c\n", u32Item); switch(u32Item) { case '1': LIN_FunctionTest(); break; case '2': LIN_FunctionTestUsingLinCtlReg(); break; default: break; } } while(u32Item != 27); while(1); }