📄 serial.c
字号:
/* 5416-c板:
使用直连的串口通信电缆;
启动"串口调试助手.exe";
PC机发送信息以一个"."为结束标志
*/
ioport unsigned int port0008,port0009,port000a,port000b,port000c,port000d,port000e,port000f;
#define RBR port0008
#define THR port0008
#define IER port0009
#define IIR port000a
#define FCR port000a
#define LCR port000b
#define MCR port000c
#define LSR port000d
#define MSR port000e
#define SCR port000f
#define DLL port0008
#define DLM port0009
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++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -