⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.c

📁 Sensorless Field Oriented Control of PMSM Motors
💻 C
字号:
#include "Motor.h"
#include "UART.h"


void DumpBuffer(WORD iNum, short *pBuf, short iNumCol)
{
    SendUARTShort( 0xFFAA );    // tag
    SendUARTShort( iNumCol );
    while( iNum-- )
        SendUARTShort( *pBuf++ );
}



//---------------------------------------------------------------------
// Setup UART baudrate and init UART.
#define BAUD 115200
void SetupUART(void)
{
    U1MODE = 0;
    U1STA  = 0;
    U1BRG = (((14745600/BAUD) / 16) -1);
    ResetUART();
}

//---------------------------------------------------------------------
// Setup UART baudrate and init UART.
#define BAUD1 230400
void SetupUARTFast(void)
{
    U1MODE = 0;
    U1STA  = 0;
    U1BRG = (((7372800/BAUD1) / 16) -1);
    ResetUART();
}


//---------------------------------------------------------------------
// Reset UART due to error or on startup.  Clears all pending bytes, 
// resets all error conditions and re-enables UART
void ResetUART(void)
{
    U1MODEbits.UARTEN = 0;
    U1MODEbits.UARTEN = 1;      // Enable UART
    U1STAbits.UTXEN = 1;        // Enable UART TX
}

//---------------------------------------------------------------------
// Sent byte
void SendUARTByte( BYTE b )
{
    while( U1STAbits.UTXBF );      // buffer full

    U1TXREG = b;
}

//---------------------------------------------------------------------
// Send short
void SendUARTShort( short s )
{
    while( U1STAbits.UTXBF );      // buffer full
    U1TXREG = (BYTE)s;
    while( U1STAbits.UTXBF );      // buffer full
    U1TXREG = *((BYTE *)&s + 1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -