| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1544 人关注过本帖
标题:用TC2.0编译没有问题。使用也很正常。为什么用TC3.1编译就出现错误请各位老 ...
只看楼主 加入收藏
lidq
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-2-17
结帖率:100%
收藏
已结贴  问题点数:0 回复次数:3 
用TC2.0编译没有问题。使用也很正常。为什么用TC3.1编译就出现错误请各位老师帮看看
源程序:
#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 in function read4017 类似有11个地方错。请各位老师帮我看看 如何修改 谢谢。本人在线等。
搜索更多相关主题的帖子: 没有问题 源程序 老师 
2011-02-18 09:23
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
收藏
得分:4 
因为3。1在语法上有很大改变。
2011-02-18 21:14
rainbow1
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:277
专家分:839
注 册:2010-5-19
收藏
得分:4 
在函数read4017的函数里面调用其他的函数应该有返回值。
2011-02-19 10:21
olliezhou
Rank: 1
等 级:新手上路
帖 子:7
专家分:9
注 册:2010-5-18
收藏
得分:0 
在每个函数声名之前加个 void
2011-03-05 16:57
快速回复:用TC2.0编译没有问题。使用也很正常。为什么用TC3.1编译就出现错误请各 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018544 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved