?? uart_function.c
字號:
/************************************************************************/
/* FileName: Uart_Function.c */
/* Function: Define writting function of uart on chip */
/************************************************************************/
#include <csl.h>
#include <csl_uart.h>
#include "Timer.h"
#include "Uart_Function.h"
/* Function/ISR prototypes */
interrupt void UartIsr(void);
Uint16 DestData[LENGTH];
Uint16 DataCount = 0;
CSLBool PctoDsp = FALSE;
/****************************************************************/
/* 函數名: Write_Uart() */
/* 功能: 通過UART向PC發指定長度的數據 */
/* 參數: */
/* 無 */
/* 返回值: */
/* 無 */
/****************************************************************/
extern void Write_Uart(unsigned int longth)
{
UART_FSET(URLCR, DLAB, 0);
Counter = 0; // 字符發送計數器清0
GPT_start(hGpt); // 啟動定時器,開始計時
while(!(Counter>=longth)); // 等待數據發送完畢
GPT_stop(hGpt); // 停止定時器
}
/****************************************************************/
/* 函數名: Uart_Config() */
/* 功能: 配置UART控制寄存器 */
/* 參數: */
/* 無 */
/* 返回值: */
/* 無 */
/****************************************************************/
extern void Uart_Config(void)
{
/* Set BSR to disable SP2MODE */
CHIP_FSET(XBSR, SP2MODE,0) ;
/* Disable all UART events */
UART_FSET(URLCR,DLAB,0);
UART_RSET(URIER, UART_RINT);
/* Reset and disable FIFOs */
UART_RSET(URFCR, 0x7);
UART_RSET(URFCR, 0);
/* Set DLL and DLM to values appropriate for the required baudrate */
UART_FSET(URLCR, DLAB, 1); // DLAB = 1
//UART_RSET(URDLL, 0x45); // 9600bps
UART_RSET(URDLL, 0xE8); // 9600bps
UART_RSET(URDLM, 0x01);
UART_FSET(URLCR, DLAB, 0); // DLAB = 0
/* Setup word size, stop bits, parity */
UART_RSET(URLCR, 0x0B); // 8 data bits, odd parity, one stop bit
/* Disable loopback control */
UART_RSET(URMCR, 0);
/* UART out of reset */
UART_FSET(URPECR,URST,1);
/* Temporarily disable all maskable interrupts */
IRQ_globalDisable();
/* Clear interrupt enable bit */
IRQ_disable(IRQ_EVT_RINT2);
/* Clear any pending Timer interrupts */
IRQ_clear(IRQ_EVT_RINT2);
/* Place interrupt service routine address at */
/* associated vector location */
IRQ_plug(IRQ_EVT_RINT2, &UartIsr);
/* Enable Timer interrupt */
IRQ_enable(IRQ_EVT_RINT2);
/* Enable all maskable interrupts */
IRQ_globalEnable();
}
/*UART的中斷程序*/
interrupt void UartIsr(void)
{
// Transimit seriz of serial debugger on pc is:
// 1112131415161718191A1B1C1D1E1F2021222324
UART_FSET(URLCR, DLAB, 0);
/* wait for RX empty */
while(!UART_FGET(URLSR,DR)); //在此行設置斷點
DestData[DataCount++] = UART_RGET(URRBR);
if(DataCount>=LENGTH)
{
DataCount = 0;
PctoDsp = TRUE;
}
}
/*****************************************************************************************/
// No more
/*****************************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -