📄 uart.c
字号:
//**********************************************************************************************************
// The Software is proprietary, confidential, and valuable to Realtek Semiconductor
// Corporation ("Realtek"). All rights, including but not limited to copyrights,
// patents, trademarks, trade secrets, mask work rights, and other similar rights and interests,
// are reserved to Realtek. Without prior written consent from Realtek, copying, reproduction,
// modification, distribution, or otherwise is strictly prohibited. The Software shall be
// kept strictly in confidence, and shall not be disclosed to or otherwise accessed by
// any third party. @ <2003> - <2008> The Software is provided "AS IS" without any warranty of any kind,
// express, implied, statutory or otherwise.
//**********************************************************************************************************
//----------------------------------------------------------------------------------------------------
// ID Code : Uart.c No.0000
// Update Note :
//----------------------------------------------------------------------------------------------------
#define __UART__
#include "Common\Header\Include.h"
#if(_DEBUG_TOOL == _RS232)
//--------------------------------------------------
// Description : RS-232 initial
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CUartInitial(void)
{
// 221880Hz
PCON = 0x80; // If SMOD = 1 then Y = 2 else Y = 1
// PCON = 0x00; // If SMOD = 1 then Y = 2 else Y = 1
SCON = 0x52;
TMOD = 0x21;
//Set Y=2 , CRYSTAL = 27MHz , TH1=239 --> Baud Rate = 9600 bps
#if(_MCU_TYPE==_REALTEK_EMBEDDED)
#if(_SCALER_TYPE == _RTD2472D)
TH1 = 239; // TH1 = 256 - (Y*CRYSTAL/384*BAUD RATE) -->CRYSTAL = 27MHz
#elif((_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
TH1 = 256-(2*(_EMCU_XTAL*1000)/384/9600);//239; // TH1 = 256 - (Y*CRYSTAL/384*BAUD RATE) -->CRYSTAL = 27MHz
#endif
#endif
TL1 = 0;
IE = 0x82; // Enable interrupts of Timer0 and Timer1
EA = 1;
ET1 = 0;
TR1 = 1;
ES = 1;
PS = 1;
bUartCommandSuccess = _FALSE;
bUartCommandStart = _FALSE;
DebugPrintf("RS232 System Initial Success!!!\n", 0);
}
//-------------------------------------------------------------------------------------------------------------------
// Uart Main Loop
//-------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------
// Description : Uart handler
// Input Value : None
// Output Value : None
//--------------------------------------------------
// Uart Command:
// 1.into debug mode 0x5a,0x01,0x02,0x03,0x04
// 2.exit debug mode 0x5b,0x04,0x03,0x02,0x01
// 3.read RTD 0x5c,0x74,address,count,index
// 4.read other 0x5c,slave address,address,count,index
// 5.write rtd 0x5d,0x74,address,value,rever
// 6.write other 0x5d,slave address,address,value,rever
void CUartHandler(void)
{
BYTE cnt;
if(bUartCommandSuccess == _FALSE)
return;
if(pUartData[0] == 0x5a)
{
if((pUartData[1] == 0x01) && (pUartData[2] == 0x02) && (pUartData[3] == 0x03) && (pUartData[4] == 0x04))
{
//TxRxShow();
bDebugModeEnable = _TRUE;
}
}
while(bDebugModeEnable)
{
if(bUartCommandSuccess)
{
bUartCommandSuccess = 0;
if(pUartData[0] == 0x5b)
{
if((pUartData[1] == 0x04) && (pUartData[2] == 0x03) && (pUartData[3] == 0x02) && (pUartData[4] == 0x01))
{
//TxRxShow();
COsdFxDisableOsd();
bDebugModeEnable = _FALSE;
break;
}
}
switch(pUartData[0])
{
case 0x5c:
//TxRxShow();
if(pUartData[1] == 0x74)
{
CUartPutCharToScr(pUartData[3]);
CScalerRead(pUartData[2], pUartData[3], pData, pUartData[4]);
for(cnt=0;cnt<pUartData[3];cnt++)
{
//CScalerRead(pUartData[2], pUartData[3], pData, pUartData[4]);
CUartPutCharToScr(pData[cnt]);
}
}
else
{
CUartPutCharToScr(pUartData[3]);
for(cnt=0;cnt<pUartData[3];cnt++)
{
CI2cRead(pUartData[1], pUartData[2], pUartData[3], pData);
CUartPutCharToScr(pData[cnt]);
}
}
break;
case 0x5d:
//TxRxShow();
if(pUartData[1] == 0x74)
{
CScalerSetByte(pUartData[2], pUartData[3]);
}
else
{
pData[0] = pUartData[3];
CI2cWrite(pUartData[1], pUartData[2], LENGTH(1), pData);
}
break;
default:
break;
}
}
}
}
//--------------------------------------------------
// Description : Uart
// Input Value : ch
// Output Value : None
//--------------------------------------------------
void CUartPutCharToScr(BYTE ch)
{
ES = 0;
SBUF = ch; // transfer UART
while (!TI)
{
// wait buffer completing.
}
ES = 1;
while (TI)
{
// wait transfer completing.
}
}
void CUartEnable(void)
{
CScalerRead(_PAGE_SELECT_9F, 1, &ucPageInfo, _NON_AUTOINC);
// ucPageInfo = pData[0];
//change P3.0(Pin 58) is Rxd; P3.1(Pin 59) is Txd --> for UART used
#if(_SCALER_TYPE == _RTD2472D)
MCU_PIN_SHARE_CTRL02_FF96 = 0xB6;
#elif((_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
CScalerPageSelect(_PAGE10);
CScalerSetByte(_P10_PIN_SHARE_CTRL09_A9, 0x5B);
#endif
TR1 = 1;
ES = 1; //Reference IE (い耞璓
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -