- #define UARTA_BASE_ADDR 0x90080000
- #define ORDER 1
- #define RBR *((unsigned char *)(UARTA_BASE_ADDR+0*ORDER))
- #define THR *((unsigned char *)(UARTA_BASE_ADDR+0*ORDER))
- #define IER *((unsigned char *)(UARTA_BASE_ADDR+1*ORDER))
- #define IIR *((unsigned char *)(UARTA_BASE_ADDR+2*ORDER))
- #define FCR *((unsigned char *)(UARTA_BASE_ADDR+2*ORDER))
- #define LCR *((unsigned char *)(UARTA_BASE_ADDR+3*ORDER))
- #define MCR *((unsigned char *)(UARTA_BASE_ADDR+4*ORDER))
- #define LSR *((unsigned char *)(UARTA_BASE_ADDR+5*ORDER))
- #define MSR *((unsigned char *)(UARTA_BASE_ADDR+6*ORDER))
- #define SCR *((unsigned char *)(UARTA_BASE_ADDR+7*ORDER))
- #define DLL *((unsigned char *)(UARTA_BASE_ADDR+0*ORDER))
- #define DLM *((unsigned char *)(UARTA_BASE_ADDR+1*ORDER))
- 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;
- LCR = 0x80;
- DLL =10;
- DLM = 0x00;
- LCR = 0x03;
- FCR = 0x57;
- IER = 0x00; /*8 bit data 115200 bps 1 bit stop 1 bit start */
- bReceive=0;
- /* for(;;)
- {
- while(LSRA & 0x40 == 0);
- THRA=;
- }
- */
- 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]=' ';
- 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++;
- }