?? uart16c550.c
字號:
//###########################################################################
//
// FILE: UART16C550.c
//
// TITLE: UART 16C550 Initialization & Support Functions.
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 1.0 | 20 May 2005 | CY.L.| release
//###########################################################################
#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
//===========================================================================
// followed the routines to UART 16C550.
//===========================================================================
void InitUART16C550(void)
{
Uint32 baud,BRR;
Uint16 DLL,DLM;
Uint16 tmp,cy,ErrPc;
*(unsigned char *)ADD_16C550_LCR=0x80;
delay_loop();
switch(FiberBaudrate)
{
case 0x00: baud=2400; //2400
break;
case 0x01: baud=4800; //4800
break;
case 0x02: baud=9600; //9600
break;
case 0x03: baud=19200; //19200
break;
case 0x04: baud=38400; //38400
break;
case 0x05: baud=115200; //115200 clk=16000000
break;
default: baud=9600; //9600
break;
}
BRR=(16000000/16/baud); //(16000000/16/baud);
DLM =BRR/256;
DLL =BRR-256*DLM;
*(unsigned char *)ADD_16C550_DLL=DLL;
delay_loop();
*(unsigned char *)ADD_16C550_DLM=DLM;
delay_loop();
*(unsigned char *)ADD_16C550_LCR=0x03;
delay_loop();
*(unsigned char *)ADD_16C550_IER=0x03;
delay_loop();
tmp=*(unsigned char *)ADD_16C550_RHR;
ErrPc=0;
cy=1;
while((cy)&&(ErrPc++<50))
{
tmp=*(unsigned char *)ADD_16C550_ISR;
delay_loop();
tmp=*(unsigned char *)ADD_16C550_LSR;
if(tmp&0x01)
{
tmp=*(unsigned char *)ADD_16C550_RHR;
cy=1;
}
else
cy=0;
}
// FiberErrMark=0;
// if(ErrPc>=50)
// FiberErrMark=0xAA;
}
void UART16C550_TX(Uint16 SendChar)
{
Uint16 *p;
Uint16 status=0;
p=(Uint16 *)ADD_16C550_LSR;
status=*p & 0x00ff;
while((status&0x20)==0) { };
p=(Uint16 *)ADD_16C550_THR;
*p=SendChar;
}
//===========================================================================
// No more.
//===========================================================================
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -