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

📄 uart.c

📁 2009.02.13 (Chiron.ylq) ------------------------------ 该工程用于Analog Devices VisualDSP++ V5.0开发环境
💻 C
字号:
/*
****************************************************************************************************
* File name:   Uart.c
* Description: This is a BF533 Uart debug driver.
****************************************************************************************************
* Company:     WASION METERS GROUP
* Created by:  Chiron.ylq
* Date:        2009.02.13
* Description: VisualDSP++ uart driver for use for program debug.
****************************************************************************************************
*/

#ifndef __UART_C__
#define __UART_C__

/*
****************************************************************************************************
*                                             INCLUDE FILES
****************************************************************************************************
*/

#include <cdefBF533.h>
#include <string.h>
#include <stdio.h>

typedef unsigned int    BOOLEAN;    /* Unsigned  8 bit quantity         */
typedef unsigned char   INT8U;      /* Unsigned  8 bit quantity         */
typedef signed   char   INT8S;      /* Signed    8 bit quantity         */
typedef unsigned short  INT16U;     /* Unsigned 16 bit quantity         */
typedef signed   short  INT16S;     /* Signed   16 bit quantity         */
typedef unsigned int    INT32U;     /* Unsigned 32 bit quantity         */
typedef signed   int    INT32S;     /* Signed   32 bit quantity         */
typedef float           FP32;       /* Single precision floating point  */
typedef double          FP64;       /* Double precision floating point  */

typedef unsigned int    U32;
typedef   signed int    S32;
typedef unsigned short  U16;
typedef   signed short  S16;
typedef unsigned char   U8;
typedef   signed char   S8;

#define  Fosc  (24576000u)
#define  Fcclk (Fosc*48/2)
#define  Fpclk (Fcclk/10)

//--------------------------------------------------------------------------//
// Function:    Init_Clock                                                  //
//                                                                          //
// Parameters:  None                                                        //
//                                                                          //
// Return:      None                                                        //
//                                                                          //
// Description: Initialize system clock to Fcclk & Fpclk                    //
//--------------------------------------------------------------------------//
void Init_Clock(void)
{
    INT32U imask;

    *pPLL_CTL = SET_MSEL((Fcclk/Fosc)*2)|DF;
    imask     = cli();
    idle();
    sti( imask );

    *pVR_CTL  = 0x00DB;
    imask     = cli();
    idle();
    sti( imask );

    *pPLL_DIV = CCLK_DIV1|SET_SSEL(Fcclk/Fpclk);
}

//--------------------------------------------------------------------------//
// Function:    Init_UART                                                   //
//                                                                          //
// Parameters:  None                                                        //
//                                                                          //
// Return:      None                                                        //
//                                                                          //
// Description: Initialize system clock to Fcclk & Fpclk                    //
//--------------------------------------------------------------------------//

#define  UART_BAUD_RATE (115200u)

void Init_UART(void)
{
    INT16S  temp;
    INT32S  divisor;
    INT32U  sys_freq;

    sys_freq     = Fpclk;
    divisor      = sys_freq >> 4;
    divisor     /= UART_BAUD_RATE;      /* divisor = SCLK/(16*baud_rate)               */

    *pUART_GCTL  = UCEN;                /* Enable UART clock                           */
    *pUART_LCR   = DLAB;
    *pUART_DLL   = divisor;             /* Write result to the two 8-bit DL            */
    *pUART_DLH   = divisor >> 8;        /* registers (DLH:DLL)                         */
    *pUART_LCR   = WLS(8);              /* Clear DLAB again and set UART frame to      */
                                        /* 8 bits, no parity, 1 stop bit.Clear any     */
                                        /* interrupts already pending                  */
    temp         = *pUART_RBR;
    temp         = *pUART_LSR;
    temp         = *pUART_IIR;

    *pUART_IER   = 0x00;//ELSI|ERBFI;//|ETBEI  // Enalbe Uart Interrupt
    //*pSIC_IMASK |= SIC_MASK(15) |SIC_MASK(14) | SIC_MASK(6);
}

//--------------------------------------------------------------------------//
// Function:    UART_TX                                                     //
//                                                                          //
// Parameters:  *pStr,  INT16U  Num                                         //
//                                                                          //
// Return:      None                                                        //
//                                                                          //
// Description:                                                             //
//--------------------------------------------------------------------------//

void UART_TX(char *pStr, unsigned int nNum)
{
    unsigned int i;
    for (i = 0; i < nNum; i++)
    {
        while (!(*pUART_LSR & THRE));
        *pUART_THR = pStr[i];
    }
}

#endif // __UART_C__
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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