|
#include <reg52.h>
#include <INTRINS.H>
#define BAUDBASE 0x30
/***4800bps->hex***/
sfr16 DPP = 0x82;
sbit ACC0=ACC^0;
sbit ACC1=ACC^1;
sbit ACC2=ACC^2;
sbit ACC3=ACC^3;
sbit ACC4=ACC^4;
sbit ACC5=ACC^5;
sbit ACC6=ACC^6;
sbit ACC7=ACC^7;
code unsigned char ST554_AddrHigh[4]={0x80,0x90,0xa0,0xb0};
bit fECG_Run=1;
bit fSPO2_Run=1;
/***********************************************************
初始化ST554
3.6864mhz
***********************************************************/
void Init_St554(unsigned char Location,unsigned char mBps,unsigned char mode)
{
DPH=ST554_AddrHigh[Location];
DPL=0x1;
/***IER***/
*(unsigned char xdata *)DPP=0x5; /***接收保持和中
断允许.*/
DPL=0x2;
/***FIFO控制器***/
*(unsigned char xdata *)DPP=0xcf; /***set FCR.FIFO
允许,RXD复位,TXD复位,DMAmode=1,触发为14***/
_nop_();
*(unsigned char xdata *)DPP=0xc9; /***set FCR.RXD
复位,TXD复位***/
DPL=0x4;
/***Modem状态***/
*(unsigned char xdata *)DPP=0x8; /***set MCR.中断
A-D开***/
DPL=0x03;
*(unsigned char xdata *)DPP=0x83|mode; /***set LCR.8BIT,1STOP,ODDPARITY,选
择
特殊寄存器***/
/***特殊寄存器已打开,设置BPS***/
DPL=0;
*(unsigned char xdata *)DPP=BAUDBASE/mBps; /***时间常数***/
DPL=1;
*(unsigned char xdata *)DPP=0; /***高位***/
DPL=0x3;
*(unsigned char xdata *)DPP=0x03|mode; /***set LCR.8BIT,1STOP,ODDPARITY,关
特
殊寄存器***/
DPL=0;
ACC=*(unsigned char xdata *)DPP; /***空读一次***/
CY=1;
while(CY){
DPL=0x5; /*读空*/
ACC=*(unsigned char xdata *)DPP; /***检查接收状态
***/
if(ACC0){
DPL=0x0;
ACC=*(unsigned char xdata *)DPP;
CY=1;
}
else CY=0;
}
}
/***********************************************************
检查554的接收
出口:CY=1,成功 返回接收值
CY=0,失败
***********************************************************/
unsigned char Check0_Rxd_ST554()
{
DPH=ST554_AddrHigh[0];
DPL=0x5;
ACC=*(unsigned char xdata *)DPP; /***检查接收状态
***/
if(ACC0){
DPL=0x0;
CY=1;
fECG_Run=1;
return(*(unsigned char xdata *)DPP);
}
else CY=0;
}
/***********************************************************
554的发送
出口:CY=1,成功
CY=0,失败
***********************************************************/
void Check0_Txd_ST554(unsigned char mTxd)
{
DPH=ST554_AddrHigh[0];
DPL=0x5;
ACC=*(unsigned char xdata *)DPP; /***检查接收状态
***/
if(ACC5){
DPL=0;
*(unsigned char xdata *)DPP=mTxd;
CY=1;
}
else CY=0;
}
/***********************************************************
检查554的接收
出口:CY=1,成功 返回接收值
CY=0,失败
***********************************************************/
unsigned char Check1_Rxd_ST554()
{
DPH=ST554_AddrHigh[1];
DPL=0x5;
ACC=*(unsigned char xdata *)DPP; /***检查接收状态
***/
if(ACC0){
DPL=0x0;
CY=1;
return(*(unsigned char xdata *)DPP);
}
else CY=0;
}
/***********************************************************
554的发送
出口:CY=1,成功
CY=0,失败
***********************************************************/
void Check1_Txd_ST554(unsigned char mTxd)
{
if(EX0){
DPH=ST554_AddrHigh[1];
DPL=0x5;
ACC=*(unsigned char xdata *)DPP; /***检查接收状态
***/
if(ACC5){
DPL=0;
*(unsigned char xdata *)DPP=mTxd;
CY=1;
}
else CY=0;
}
else CY=1;
}
/***********************************************************
检查554的接收
出口:CY=1,成功 返回接收值
CY=0,失败
***********************************************************/
unsigned char Check2_Rxd_ST554()
{
DPH=ST554_AddrHigh[2];
DPL=0x5;
ACC=*(unsigned char xdata *)DPP; /***检查接收状态
***/
if(ACC0){
DPL=0x0;
fSPO2_Run=1;
CY=1;
return(*(unsigned char xdata *)DPP);
}
else CY=0;
}
/***********************************************************
554的发送
出口:CY=1,成功
CY=0,失败
***********************************************************/
void Check2_Txd_ST554(unsigned char mTxd)
{
DPH=ST554_AddrHigh[2];
DPL=0x5;
ACC=*(unsigned char xdata *)DPP; /***检查接收状态
***/
if(ACC5){
DPL=0;
*(unsigned char xdata *)DPP=mTxd;
CY=1;
}
else CY=0;
}
|
|