📄 dsp281x_sci.c
字号:
//###########################################################################
//
// FILE: DSP281x_Sci.c
//
// TITLE: DSP281x SCI Initialization & Support Functions.
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 1.00| 11 Sep 2003 | L.H. | No change since previous version (v.58 Alpha)
//###########################################################################
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "FM25L512.h"
//---------------------------------------------------------------------------
// InitSPI:
//---------------------------------------------------------------------------
// This function initializes the SPI(s) to a known state.
//
unsigned char ascitab[] = "0123456789ABCDEF";
void InitSci(void)
{
// Initialize SCI-A:
SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all =0x0003;
SciaRegs.SCICTL2.bit.TXINTENA =1;
SciaRegs.SCICTL2.bit.RXBKINTENA =1;
SciaRegs.SCIHBAUD =0x0001;
SciaRegs.SCILBAUD =0x00B6; // '01B6' BAUD =9600
SciaRegs.SCICCR.bit.LOOPBKENA =0; // Enable loop back
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
// Initialize SCI-B:
//tbd...
}
void scia_xmit(int a)
{
while(SciaRegs.SCICTL2.bit.TXRDY != 1){FEED_WATCHDOG; }
SciaRegs.SCITXBUF=a;
}
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
}
void bcd2ascii(unsigned char dat) // ----- convert bcd to ascii and send to sci ----
{
unsigned char temp;
/*
temp = (dat >> 4) + 0x30;
if(temp>0x39)
temp = temp+7;
scia_xmit(temp);
temp = (dat & 0x0f) + 0x30;
if(temp>0x39)
temp = temp+7;
scia_xmit(temp);
*/
temp = ascitab[(dat >> 4) & 0x0f];
scia_xmit(temp);
temp = ascitab[ dat & 0x0f];
scia_xmit(temp);
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -