#define UART_BASE_ADDR 0x90120000
#define OFFSET 2
#define RBR *((short *)(UART_BASE_ADDR+0*OFFSET))
#define THR *((short *)(UART_BASE_ADDR+0*OFFSET))
#define IER *((short *)(UART_BASE_ADDR+1*OFFSET))
#define IIR *((short *)(UART_BASE_ADDR+2*OFFSET))
#define FCR *((short *)(UART_BASE_ADDR+2*OFFSET))
#define LCR *((short *)(UART_BASE_ADDR+3*OFFSET))
#define MCR *((short *)(UART_BASE_ADDR+4*OFFSET))
#define LSR *((short *)(UART_BASE_ADDR+5*OFFSET))
#define MSR *((short *)(UART_BASE_ADDR+6*OFFSET))
#define SCR *((short *)(UART_BASE_ADDR+7*OFFSET))
#define DLL *((short *)(UART_BASE_ADDR+0*OFFSET))
#define DLM *((short *)(UART_BASE_ADDR+1*OFFSET))
#define CECTL1 *((long *)0x01800004)
void wait(int nWait);
char cString[17]={ "Hello PC!,Over|" },cReceive,cBuffer[17],cAnswer[16]={"Oh,you say"};
int bReceive,nLen;
main()
{
unsigned int uWork;
int i,k;
bReceive=0;
LCR = 0x80;
DLL = 0x18;
DLM = 0x00;
LCR = 0x03;
FCR = 0x01;
MCR = 0x20;
IER = 0x00;
while ( 1 )
{
if ( bReceive==0 )
{
for ( i=0;i<16;i++ )
{
do
{
uWork=LSR;
} while ( uWork&0x040 != 0x040 );
THR=cString[i];
wait(1024);
}
}
else
{
for ( i=0;i<10;i++ )
{
do
{
uWork=LSR;
} while ( uWork&0x040 != 0x040 );
THR=cAnswer[i];
wait(1024);
}
do
{
uWork=LSR;
} while ( uWork&0x040 != 0x040 );
THR='\"';
for ( i=0;i<nLen;i++ )
{
do
{
uWork=LSR;
} while ( uWork&0x040 != 0x040 );
THR=cBuffer[i];
wait(1024);
}
do
{
uWork=LSR;
} while ( uWork&0x040 != 0x040 );
THR='\"';
wait(1024);
for ( i=9;i<16;i++ )
{
do
{
uWork=LSR;
} while ( uWork&0x040 != 0x040 );
THR=cString[i];
wait(1024);
}
}
k=0; bReceive=0;
while ( 1 )
{
do
{
uWork=LSR;
} while ( (uWork&1)==0 );
cReceive=RBR;
cBuffer[k]=cReceive&0x0ff;
if ( cReceive=='.' )
{
cBuffer[k+1]='\0';
nLen=k+1;
bReceive=1;
break;
}
k++; k%=16;
}
}
}
void wait(int nWait)
{
int i,j,k=0;
for ( i=0;i<nWait;i++ )
for ( j=0;j<64;j++ )
k++;
}