在TC2.0编译很好但用TC3.0就出现问题不知道如何解决
源程序:#include <stdio.h>
#include <math.h>
#include <dos.h>
#include <conio.h>
#define TIME_OUT 300000
#define ID 13
static int base0=0x3f8;
static int base1=0x2f8;
static unsigned char SendData[108];
int rec4017[60];
int rec4052[10];
unsigned char ComRecData[11]={""};
int RecLen =0;
int ComDataReady=0;
static char cmd01[4]={'#','0','1',0x0d};
static char cmd02[5]={'$','0','2','6',0x0d};
unsigned char CMD=0;
read4017()
{
int i;
char flag;
long timeout;
i=0;
flag=1;
while (flag)
{
outportb(base1,cmd01[i]);
if(cmd01[i] == 0x0d)
{
flag=0;
i=0;
}
i++;
}
flag=1;
timeout=TIME_OUT;
i=0;
while (flag)
{
if ((inportb(base1+5) & 1) !=0)
{
rec4017[i]=inportb(base1);
if (rec4017[i] == 0x0d)
{
/*rec4017[i+1]='\0';*/
flag=0;
}
i++;
}
else
{
timeout--;
if (timeout == 0)
{
printf("\nTimeout01(read4017)\n");
flag = 0;
}
}
}
}
read4052()
{
int i;
char flag;
long timeout;
i=0;
flag=1;
while (flag)
{
outportb(base1,cmd02[i]);
if (cmd02[i] == 0x0d)
{
flag=0;
i=0;
}
i++;
}
flag=1;
timeout=TIME_OUT;
i=0;
while (flag)
{
if ((inportb(base1+5) & 1) !=0)
{
rec4052[i]=inportb(base1);
if (rec4052[i] == 0x0d)
{
/*rec4052[i+1]='\0';*/
flag=0;
}
i++;
}
else
{
timeout--;
if (timeout == 0)
{
printf("\nTimeout02(read4052)\n");
flag = 0;
}
}
}
}
readcom()
{
int i=0;
int flag=1;
int timeout=TIME_OUT;
while (flag)
{
if ((inportb(base0+5) & 1) !=0)
{
ComRecData[i]=inportb(base0);
i++;
if(i>=9)
{
ComRecData[i+1]='\0';
printf("Received ID is:%d\n",ComRecData[7]);
if(ComRecData[7]==ID)
{
ComDataReady=1;
CMD=ComRecData[4];
}
flag=0;
}
}
else
{
timeout--;
if (timeout == 0)
{
flag = 0;
ComDataReady=0;
}
}
}
}
/*void interrupt com1()
{
char i;
disable();
ComRecData[RecLen]=inportb(0x3f8);
RecLen++;
if(RecLen==10)
{
if((ComRecData[0]==69 && ComRecData[1]==84 && ComRecData[7]==ID) )
{
ComDataReady=1;
ComRecData[11]='\0';
if(ComRecData[4]==130 || ComRecData[4]==131)
{
CMD=ComRecData[4];
}
}
else
{
strcpy(ComRecData,"");
RecLen=0;
ComDataReady=0;
CMD=0;
}
}
enable();
EOI();
}
set_com1_vect()
{
setvect(0xc, com1);
}
EOI()
{
outport(0xff22,0x8FFC);
}
enable_com1_irq()
{
outport(0xff28,inport(0xff28) & 0xffef);
}
disable_com1_irq()
{
outport(0xff28,inport(0xff28) | 0x0010);
} */
wdt_on()
{
outport(0xff76,inport(0xff76) | 0x2000); /* output mode */
outport(0xff78,inport(0xff78) & 0xDFFF); /* 10 */
outport(0xff7A,inport(0xff7A) | 0x2000); /* WDI =1 */
}
wdt_clear()
{
outport(0xff7A,inport(0xff7A) & 0xDFFF); /* WDI = 0 */
outport(0xff7A,inport(0xff7A) | 0x2000); /* WDI = 1 */
}
wdt_off()
{
outport(0xff76,inport(0xff76) & 0xDFFF); /* normal mode */
outport(0xff78,inport(0xff78) & 0xDFFF); /* 00 */
}
led_init()
{
outport(0xff76,inport(0xff76) | 0x0400); /* output mode */
outport(0xff78,inport(0xff78) & 0xFBFF); /* 10 */
}
led_on()
{
outport(0xff7A,inport(0xff7A) | 0x0400); /* LED = 1 */
}
led_off()
{
outport(0xff7A,inport(0xff7A) & 0xFBFF); /* LED = 0 */
}
InitSerial()
{
outportb((0x3f8+2),0x03); /* enable COM1 FIFO */
outportb((0x2f8+2),0x03); /* enable COM2 FIFO */
outportb(0x3f8+3,0x80); /* set DLAB=1 */
outportb(0x3f8 ,0x0c); outportb(0x3f8+1,0x0); /* set buad = 9600 */
outportb(0x3f8+3,0x03); /* set data=8 stop=1 no parity */
outportb(0x3f8+1,0x00); /* enable COM1 interrupt */
outportb(0x2f8+3,0x80); /* set DLAB=1 */
outportb(0x2f8 ,0x0C); outportb(0x2f8+1,0x0); /* set buad = 9600 */
outportb(0x2f8+3,0x03); /* set data=8 stop=1 no parity */
outportb(0x2f8+1,0x00); /* disable COM2 interrupt */
}
InitSendData()
{
SendData[0]=69;
SendData[1]=84;
SendData[2]=0;
SendData[3]=0;
SendData[4]=130;
SendData[5]=4;
SendData[6]=0;
SendData[7]=ID;
SendData[8]=0;
SendData[9]=0;
}
void main()
{
int i=0;
char ch;
long int j=0;
disable();
/*set_com1_vect();*/
InitSerial();
InitSendData();
enable();
/*enable_com1_irq();*/
led_init();
printf("StationID is: %d\n",ID);
printf("System is listing on Com1 Port....... \n");
while(1)
{
if(kbhit())
{
ch=getch();
if((ch=='Q')||(ch=='q'))
{
exit(0);
}
}
wdt_on();
readcom();
if(ComDataReady==1 && ComRecData[7]==ID)
{
led_off();
ComDataReady=0;
printf("CMD is: %d\n",CMD);
SendData[4]=CMD;
CMD=0;
printf("Receive CMD OK!!! \n");
read4017();
for(i=0;i<=56;i++)
SendData[10+i]=rec4017[i];
read4052();
for(i=0;i<=7;i++)
{
SendData[67+i]=rec4052[i];
}
for(j=0;j<65535;j++)
{
}
for(i=0;i<=108;i++)
{
outportb(0x3f8,SendData[i]);
while((inportb(0x3f8+5) & 0x60)!=0x60);
}
printf("Transmite Done!!! \n");
printf("Press 'Q' or 'q' to Quit......\n");
strcpy(rec4017,"");
strcpy(rec4052,"");
led_on();
}
wdt_off();
}
}
出错信息Function should return a value 我是新手 请老师给看看 谢谢
有11条都是同样的错误信息
[ 本帖最后由 lidq 于 2011-2-17 16:17 编辑 ]