⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serial.lst

📁 可用于51单片机中控制SPI传输的程序源代码
💻 LST
字号:
C51 COMPILER V8.02   SERIAL                                                                04/21/2008 23:41:26 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE SERIAL
OBJECT MODULE PLACED IN serial.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE serial.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          
   2          #include<string.h>
   3          #include<conio.h>
*** WARNING C318 IN LINE 3 OF serial.c: can't open file 'conio.h'
   4          #include<dos.h>
*** WARNING C318 IN LINE 4 OF serial.c: can't open file 'dos.h'
   5          #include<io.h>
*** WARNING C318 IN LINE 5 OF serial.c: can't open file 'io.h'
   6          #include<math.h>
   7          #include<stdio.h>
   8          #include<stdlib.h>
   9          void sport(char ch)
  10              {while(!(bioscom(3,0,0)&0x2000));
*** WARNING C206 IN LINE 10 OF SERIAL.C: 'bioscom': missing function-prototype
*** ERROR C267 IN LINE 10 OF SERIAL.C: 'bioscom': requires ANSI-style prototype
  11   1           if(bioscom(1,ch,0)&0x800)
  12   1             {printf("超时错误!\n");
  13   2               exit(1);
  14   2               }
  15   1               }
  16          rport()
  17            {int a;
  18   1          while(!(bioscom(3,0,0)&0x0100))
  19   1             {if(kbhit())
  20   2                 {getch();
  21   3                   exit(1);
  22   3                   }
  23   2       a=bioscom(2,0,0)&0x00f;
  24   2       return(a);
  25   2       }
  26   1       }
  27          
  28          void sendf(char *fname)
  29               {FILE *fp;
  30   1            char ch;
  31   1            int handle,count,sum=0;
  32   1            if((fp=fopen(fname,"r"))==NULL)
  33   1               {printf("不能打开输入文件!\n");
  34   2                exit(1);
  35   2                }
  36   1            handle=fileno(fp);
  37   1            count=filelength(handle);
  38   1           printf("准备发送文件...\n");
  39   1            do
  40   1               {ch='?';
  41   2                  sport(ch);
  42   2                  }while(rport()!='.');
  43   1            sport(count);
  44   1            rep:
  45   1              for(;count;count--)
  46   1                {ch=getc(fp);
  47   2                 sum=sum+ch;
  48   2                 if(ferror(fp))
  49   2                   {printf("读文件有误\n");
  50   3                    break;
C51 COMPILER V8.02   SERIAL                                                                04/21/2008 23:41:26 PAGE 2   

  51   3                    }
  52   2             sport(ch);
  53   2             }
  54   1             sport(sum);
  55   1             if(rport()=='F')
  56   1                {count=filelength(handle);                         /*filelenth(handle); */
  57   2                 sum=0;
  58   2                 fseek(fp,-count,1);
  59   2                 goto rep;
  60   2                 }
  61   1             else
  62   1                 {fclose(fp);
  63   2                  printf("发送文件结束\n");
  64   2                  }
  65   1                  }
  66          
  67            void receivef(char *fname)
  68               {FILE *fp;
  69   1            char ch;
  70   1            int count,temp,sum=0;
  71   1            remove(fname);
  72   1            if((fp=fopen(fname,"w"))==NULL)
  73   1               {printf("不能打开文件\n");
  74   2               exit(1);
  75   2      
  76   2               }
  77   1          printf("接收文件名:%s\n",fname);
  78   1          while(rport()!='?');
  79   1          sport('$');
  80   1          ch='.';
  81   1          sport(ch);
  82   1          temp=rport();
  83   1          count=temp;
  84   1        rep:
  85   1            for(;count;count--)
  86   1              {ch=rport();
  87   2               putc(ch,fp);
  88   2               sum=sum+ch;
  89   2            if(ferror(fp))
  90   2              {printf("写文件有误\n");
  91   3              exit(1);
  92   3              }
  93   2              }
  94   1         if(rport()!=sum)
  95   1            {ch='F';
  96   2            sport(ch);
  97   2            count=temp;
  98   2            sum=0;
  99   2            fseek(fp,-count,1);
 100   2            goto rep;
 101   2            }
 102   1         else
 103   1              {ch='0';
 104   2               sport(ch);
 105   2                fclose(fp);
 106   2                printf("接收文件结束\n");
 107   2                }
 108   1                }
 109          
 110          
 111           main(int argc,char *argv[])
 112            {while(argc!=3)
C51 COMPILER V8.02   SERIAL                                                                04/21/2008 23:41:26 PAGE 3   

 113   1          {printf("命令行命令不对,again!\n");
 114   2          exit(1);
 115   2          }
 116   1          bioscom(0,0x83,0);
 117   1          if(tolower(*argv[1])=='s')
 118   1            sendf(argv[2]);
 119   1              else if (tolower(*argv[1])=='r');
 120   1                 receivef(argv[2]);
 121   1      
 122   1      
 123   1      
 124   1      
 125   1                 }
 126          

C51 COMPILATION COMPLETE.  4 WARNING(S),  1 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -