正在学习在mc9s08dz32的板子上移植操作系统。现在是能跑起来了,身边没有板子,想要利用SCI进行串口的模拟调试,在CODEWARRIORV6.2的版本中好像不再支持HCS08了,于是自己写了SCI的驱动,代码如下:
void TERMIO_Init(void)
{
/* SCI1C1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
SCI1C1=0x00; /* Configure the SCI */
/* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
SCI1C3=0x00; /* Disable error interrupts */
/* SCI1S2: LBKDIF=0,RXEDGIF=0,??=0,RXINV=0,RWUID=0,BRK13=0,LBKDE=0,RAF=0 */
SCI1S2=0x00;
/* SCI1C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
SCI1C2=0x00; /* Disable all interrupts */
SCI1BDH = 0x00; /* Set high divisor register (enable device) */
SCI1BDL = 0x4E; /* Set low divisor register (enable device) */
SCI1C2_TE = 0x01; /* Enable transmitter */
SCI1C2_RE = 0x01; /* Enable receiver */
}
byte TERMIO_GetChar(byte *Chr)
{
byte Result = ERR_OK; /* Return error code */
byte StatReg = SCI1S1; /* Read status register */
if (StatReg & (SCI1S1_OR_MASK|SCI1S1_NF_MASK|SCI1S1_FE_MASK|SCI1S1_PF_MASK)) { /* Is any error set? */
Result = ERR_COMMON; /* If yes then set common error value */
} else if (!(StatReg & SCI1S1_RDRF_MASK)) { /* Is the reciver empty and no error is set? */
return ERR_RXEMPTY; /* If yes then error */
} else { /* Intentionally left empty due to compatibility with MISRA rule 60*/
}
*Chr = SCI1D; /* Read data from the receiver */
return Result; /* Return error code */
}
byte TERMIO_PutChar(byte Chr)
{
if (!SCI1S1_TDRE) { /* Is the transmitter empty? */
return ERR_TXFULL; /* If no then error */
}
SCI1D = (byte)Chr; /* Store char to the transmitter register */
return ERR_OK; /* OK */
}
可是在程序的调用中,借助SCDO命令显示的数据不是很正确,显示的位置也不是执行完输出语句就显示的,我是个新手,所以很多地方还不是很明白,哪位高手给点指点,这种做法是不是正确,该怎么做没有板子的情况下的程序调试呀,谢谢了
此帖出自
小平头技术问答
一周热门 更多>