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

开发环境:mplab 3.45 harmony 1.09 xc32 1.42

源代码下载:http://download.csdn.net/detail/zn2857/9712707

源代码分析:

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;
        }
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值