技术|PIC32单片机harmony开发环境 - uart例程和代码分析

开发环境:mplab 3.45 harmony 1.09 xc32 1.42


源代码下载:http://download.csdn.net/detail/zn2857/9712707
源代码分析:
【技术|PIC32单片机harmony开发环境 - uart例程和代码分析】

void APP_Tasks ( void ) {/* Check the application's current state. */ switch ( appData.state ) { /* Application's initial state. */ case APP_STATE_INIT: { bool appInitialized = true; if (appInitialized) { /* Open the USART Driver for USART1 Client*/ appData.drvUartHandle = DRV_USART_Open( DRV_USART_INDEX_0,DRV_IO_INTENT_READWRITE ); appData.state = APP_STATE_CHECK_DRVR_STATE; } break; }case APP_STATE_CHECK_DRVR_STATE: { /* Check the USART1 driver handler */ if (appData.drvUartHandle == DRV_HANDLE_INVALID ) { /* Set the uart state to Ready */ appData.state = APP_STATE_INIT; return; } DRV_USART_ByteReceiveCallbackSet(DRV_USART_INDEX_0, (DRV_USART_BYTE_EVENT_HANDLER)Uart_LoopBack); appData.state = APP_STATE_IDLE; break; }case APP_STATE_SERVICE_TASKS: { uint8_t numBytes = 0; while( numBytes < 1 ) { numBytes++; if( !(DRV_USART_TRANSFER_STATUS_TRANSMIT_FULL & DRV_USART_TransferStatus(appData.drvUartHandle)) ) { DRV_USART_WriteByte(appData.drvUartHandle, temp); } } appData.state = APP_STATE_IDLE; break; }case APP_STATE_IDLE: { break; } /* TODO: implement your application state machine.*//* The default state should never be executed. */ default: { /* TODO: Handle error in application's state machine. */ break; } } }



    推荐阅读