📄 uart.c
字号:
/* FUNCTION */
/* */
/* get_num get decimal number from hexa digit */
/* */
/* DESCRIPTION */
/* */
/* */
/* AUTHOR */
/* */
/* */
/* CALLED FROM */
/* */
/* Application routines */
/* */
/* ROUTINES CALLED */
/* */
/* */
/* INPUTS */
/* */
/* */
/* OUTPUTS */
/* */
/* return(c) return character */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* hbahn 10-16-1998 Created initial version 1.0 */
/************************************************************************/
uint32 get_num(void)
{
char RcvData[10] ;
unsigned RcvNum=0 ;
int i = 0 ;
while ( (RcvData[i] = get_byte() ) != CR )
{
if ( (RcvData[i] >= '0') && (RcvData[i] <= '9') )
RcvNum=(RcvNum<<4) + (RcvData[i]-'0') ;
else if ( (RcvData[i] >= 'A') && (RcvData[i] <= 'F') )
RcvNum=(RcvNum<<4) + (RcvData[i]-'A'+ 10) ;
else if ( (RcvData[i] >= 'a') && (RcvData[i] <= 'f') )
RcvNum=(RcvNum<<4) + (RcvData[i]-'a'+ 10) ;
i++ ;
}
return RcvNum ;
}
/************************************************************************/
/* */
/* FUNCTION */
/* */
/* get_digit get decimal number from ASCII data. */
/* */
/* DESCRIPTION */
/* */
/* ex) If input character is "123",get_digit()'s return value */
/* will be 123. */
/* */
/* AUTHOR */
/* */
/* */
/* CALLED FROM */
/* */
/* Application routines */
/* */
/* ROUTINES CALLED */
/* */
/* */
/* INPUTS */
/* */
/* */
/* OUTPUTS */
/* */
/* return(c) return character */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 10-16-1998 Created initial version 1.0 */
/************************************************************************/
uint32 get_digit(void)
{
uint8 RcvData[10] ;
int RcvNum=0 ;
int RcvDataSize=0 ;
int i ;
while ((RcvData[RcvDataSize] = get_byte()) != CR) RcvDataSize++ ;
for (i=0;i < RcvDataSize ; i++)
RcvNum = RcvNum*10 + (RcvData[i]-'0') ;
return RcvNum ;
}
/************************************************************************/
/* */
/* FUNCTION */
/* */
/* kbd_hit */
/* */
/* DESCRIPTION */
/* */
/* */
/* AUTHOR */
/* */
/* */
/* CALLED FROM */
/* */
/* Application routines */
/* */
/* ROUTINES CALLED */
/* */
/* */
/* INPUTS */
/* */
/* */
/* OUTPUTS */
/* */
/* return(c) return character */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* hbahn 10-16-1998 Created initial version 1.0 */
/************************************************************************/
uint32 kbd_hit(void)
{
uint32 KbdHit ;
int8 ch ;
#ifdef PORT1
if (UARTSTAT1 & USTAT_RCV_READY)
{
KbdHit = 1 ;
ch = UARTRXB1;
}
else KbdHit = 0 ;
#else
if (UARTSTAT0 & USTAT_RCV_READY)
{
KbdHit = 1 ;
ch = UARTRXB0;
}
else KbdHit = 0 ;
#endif
return KbdHit ;
}
/************************************************************************/
/* */
/* FUNCTION "BaudRateVal" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function return the value of UART baudrate divisior, */
/* UBRDIVn according to the baudrate. */
/* */
/* AUTHOR */
/* */
/* */
/* CALLED FROM */
/* */
/* UART_Initialize */
/* */
/* ROUTINES CALLED */
/* */
/* */
/* INPUTS */
/* */
/* baud UART baud rate(ex. 38400,57600,..) */
/* */
/* OUTPUTS */
/* */
/* baudrate divisor value */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 10-16-1998 Created initial version 1.0 */
/************************************************************************/
uint32 BaudRateVal(uint32 baud)
{
uint32 index;
for(index = 0; index < BAUD_TABLE; index++)
{
if(U_BaudRate[index].baud == baud) return(index);
}
return(0); /* baudrate data doesn't in table */
}
uint32 BaudRate(uint32 div)
{
uint32 index;
for(index = 0; index < BAUD_TABLE; index++)
{
if(U_BaudRate[index].div == div) return(index);
}
return(0); /* baudrate data doesn't in table */
}
/***********************************************************************/
/*
/***********************************************************************/
int Uart_Flush(int c)
{
char temp;
if(c == 0)
{
if(UARTSTAT0 & 0x20)
{
temp = UARTRXB0;
return 1;
}
else
return 0;
}
else
{
if(UARTSTAT1 & 0x20)
{
temp = UARTRXB1;
return 1;
}
else
return 0;
}
}
int Uart_Getch_Timeout(int timeout,int c)
{
int counter = timeout * 400;
if(c == 0)
{
while((!(UARTSTAT0 & 0x20)) && (counter > 0))
counter--;
if (!(UARTSTAT0 & 0x20))
return -1;
else
return UARTRXB0& 0xff;
}
else
{
while((!(UARTSTAT1 & 0x20)) && (counter > 0))
counter--;
if (!(UARTSTAT0 & 0x20))
return -1;
else
return UARTRXB1 & 0xff;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -