DX们,帮忙看一个程序!!
这个程序我在书上抄的,但程序运行的有问题,同学说是它程序的问题,请帮忙侃侃!#include"stdio.h"
#include"dos.h"
#include"bios.h"
#define Esc 0x11b
#define COM1 0
#define COM2 1
#define SETTINGS (0xa0|0x00|0x00|0x03)
int com;
int array[17];
void senddata(void)
{
int i,m;
unsigned int test;
printf("pc will sedn data! please intput <16 data!\n");
printf("the end number is 255! <esc------quit> \n");
m=0;
do{
scanf("%d",&array[m]);
m++;
}while(array[m-1]!=255);
printf("receive data:");
for(i=0;i <m;i++)
{
while((inportb(com+5)&0x20)!=0x20);
outportb(com,array[i]);
while((inportb(com+5)&0x01)==0)
{
if(bioskey(0)==Esc)
return;
}
test=inportb(com);
printf("%ld",test);
}
printf("\n transport completed!\n\n");
getch();
}
main()
{
char m;
char c;
char comm;
for(;;)
{
clrscr();
printf("\n\n please select com1 or com2:(1/2)");
comm=getch();
if(comm=='1')com=0x3f8;
if(comm=='2')com=0x2f8;
if (comm!='1'&&comm!='2')continue;
clrscr();
printf(" s-------send data\n");
printf(" q-------quit process\n\n");
printf("now is com%c\n",comm);
printf("now ples sel a mode(s/q):\n\n");
c=getch();
if(com==0x3f8)
{
bioscom(0,SETTINGS,COM1);
}
if (com==0x2f8)
{
bioscom(0,SETTINGS,COM2);
}
if (c=='s'||c=='S')
{
outportb(com,0);
while((inportb(com+5)&0x20)!=0x20);
while((inportb(com+5)&0x01)==0);
m=inportb(com);
if (m==0)
{
printf(" 8c51will receive data!\n");
senddata();
}
}
}
}
上面是PC程序,下面是单片机程序!
org 0000h
ljmp main
org 0100h
main:
mov tmod,#20h
mov th1,#0f4h
mov tl1,#0f4h
mov scon,#50h
mov pcon,#00h
mov r1,#10h
setb tr1
l2:
jbc ri,l1
sjmp l2
l1:
mov a,sbuf
jz rece
jnz main
rece:
mov r0,#20h
mov sbuf,a
rex:
jbc ti,re1
sjmp rex
re1: nop
re:
jbc ri,re2
sjmp re
re2:
mov a,sbuf
mov @r0,a
mov sbuf,a
re3:
jbc ti,re4
sjmp re3
re4:
cjne @r0,#0ffh,re5
ljmp main
re5:
inc r0
ljmp re
发表时间:2003年7月1日9:02:31