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

📄 datafax.lst

📁 PHILIP LPC935MCU UART用于与传真模块通信,SPI用于与SL811的USB模块通信.该软件把U盘存储的文件通过传真发到对方相同的设备接收到U盘
💻 LST
📖 第 1 页 / 共 5 页
字号:
1001   2                 UARTBUF[i]=(byte)Cnt;
1002   2                 Cnt>>=8;
1003   2          }
1004   1          UARTBUF[0]=0X02;//读取文件命令
1005   1          SPI_Read_Point=0;
1006   1          SPI_Write_Point=0;
1007   1          Set_SPI_Master;
1008   1              SPI_SS=0;
1009   1              Delayms(2);
1010   1          for(i=0;i<37;i++) SPI_Send_Byte(UARTBUF[i]);        
1011   1          Set_SPI_Slave;
1012   1              temp_bit=SPI_SS;
1013   1              SPI_TI=0;  
1014   1      
1015   1      }
1016          //-------------------------------------------------
1017          //              向接收方发送请求
1018          //      入口参数:request-----请求
1019          //                        length------数据长度
1020          //--------------------------------------------------
1021          void Send_Request(byte request,ulong length)
1022          {
1023   1          byte i=0;
1024   1          word j=0;
1025   1          switch(request)
1026   1          { 
1027   2              case CREATE_FILE://创建文件
1028   2                  for(i=0;i<37;i++) UARTBUF[i]=0x00;
1029   2                  UARTBUF[0]=0X04;
1030   2                  for(i=5;i<31;i++)
1031   2                  {
1032   3                     UARTBUF[i]=File_Info[i-5];
1033   3                  }
1034   2                  for(i=0;i<37;i++) Com_Send_Byte(UARTBUF[i]);
1035   2              break;    
1036   2              case OPEN_FILE://打开文件
1037   2                  for(i=0;i<37;i++) UARTBUF[i]=0x00;
1038   2                  UARTBUF[0]=0X01;
1039   2                  for(i=5;i<16;i++)
1040   2                  {
1041   3                     UARTBUF[i]=File_Info[i-5];
1042   3                  }
1043   2                  for(i=0;i<37;i++) Com_Send_Byte(UARTBUF[i]);
1044   2              case FILE_SEEK://文件定位
C51 COMPILER V7.09   DATAFAX                                                               03/22/2005 01:42:11 PAGE 18  

1045   2                  for(i=0;i<37;i++) UARTBUF[i]=0x00;
1046   2                  for(i=4;i>0;i--)
1047   2                  {
1048   3                         UARTBUF[i]=(byte)length;
1049   3                         length>>=8;
1050   3                  }
1051   2                  UARTBUF[0]=0X03;
1052   2                  for(i=0;i<37;i++) Com_Send_Byte(UARTBUF[i]);
1053   2              break;    
1054   2              case WRITE_FILE://写文件
1055   2                  for(i=0;i<37;i++) UARTBUF[i]=0x00;
1056   2                  for(i=4;i>0;i--)
1057   2                  {
1058   3                         UARTBUF[i]=(byte)length;
1059   3                         length>>=8;
1060   3                  }
1061   2                  UARTBUF[0]=0X05;
1062   2                  for(i=0;i<37;i++) Com_Send_Byte(UARTBUF[i]);
1063   2              break;   
1064   2                      case FILE_EOF://End Of File
1065   2                  for(i=0;i<37;i++) UARTBUF[i]=0x00;
1066   2                  UARTBUF[0]=0X0F;
1067   2                  for(i=0;i<37;i++) Com_Send_Byte(UARTBUF[i]);
1068   2              break;   
1069   2              default:
1070   2              break;
1071   2          } 
1072   1                  
1073   1      }
1074          //--------------------------------------------------
1075          //         获取接收送方的响应
1076          //-------------------------------------------------
1077          bit Get_Response()
1078          {
1079   1              byte i=0; 
1080   1              Com_Read_Point=0;
1081   1              Com_Write_Point=0;
1082   1              Cnt_Long_1ms=0;
1083   1          while(Cnt_Long_1ms<_10S)
1084   1          {
1085   2              if(Flag_1ms)
1086   2                      {
1087   3                      Flag_1ms=false;
1088   3                      Capture_KEY_Event();
1089   3              }     
1090   2                      if(Key_Down.Active)
1091   2              {
1092   3                    Key_Down.Active=false;
1093   3                    if(Key_Down.Byte_data==KB_EXIT) 
1094   3                    {          
1095   4                              Do_Cancel(); 
1096   4                                          Flag_Exit=true;
1097   4                          Flag_KB_Enable=true; 
1098   4                                              return false;
1099   4                        }
1100   3              }
1101   2              //if( Com_Read_Point!=Com_Write_Point) break; 
1102   2                      if( Com_Write_Point>=4) break; 
1103   2          }
1104   1         if(Com_Recv_Buf[0]==0x00)
1105   1              {
1106   2                      Delayms(200);
C51 COMPILER V7.09   DATAFAX                                                               03/22/2005 01:42:11 PAGE 19  

1107   2                      Delayms(200);
1108   2                      return false;
1109   2         }
1110   1         else return true;
1111   1      
1112   1      }
1113          
1114          //-------------------------------------------------
1115          //      发送文件过程:
1116          // Open File 
1117          // Seek File
1118          // Send file first block ( block_size=Com_Buf_len-5)
1119          // Send file next block  ( block_size=Com_Buf_len-5)
1120          // Send file next ......
1121          // Send last block ( blocksize=fileSize-n*blocksize)
1122          //---------------------------------------------------
1123          void Do_Send_File()
1124          {
1125   1          ulong Block_Size=Recv_Buf_Len-37;
1126   1          ulong filesize=File_Size;
1127   1              ulong temp_point=0;
1128   1              ulong temp_size=0;
1129   1          word i=0;
1130   1              byte j=0;
1131   1          File_Point=0;
1132   1              Flag_Exit=false;
1133   1          if(MODEM_Status!=MODEM_CONNECTED_STATE)
1134   1          {
1135   2              Error_Display("MODEM DISCONNECT");
1136   2              return;
1137   2          }
1138   1          if(File_Name[0]==0x00)
1139   1          {
1140   2              Error_Display("NO FILE SELECTED");
1141   2              return;
1142   2          }
1143   1          Send_Finished.Active=false;
1144   1          Send_Request(CREATE_FILE,0);  
1145   1              for(i=0;i<37;i++) Com_Recv_Buf[i]=0x00;
1146   1              Com_Read_Point=0;
1147   1              Com_Write_Point=0;
1148   1              LCD_Show_Data(2,20,"Get create Response ");
1149   1              if(!Get_Response()) 
1150   1              {
1151   2                      j++;
1152   2                      if(j>3)
1153   2                      {
1154   3                              Error_Display("NO RESPONSE");
1155   3                              return;
1156   3                      }
1157   2                      Send_Request(CREATE_FILE,0);  
1158   2                      for(i=0;i<37;i++) Com_Recv_Buf[i]=0x00;
1159   2                      Com_Read_Point=0;
1160   2                      Com_Write_Point=0;
1161   2                      
1162   2              }
1163   1          if(Open_File()) 
1164   1          {                      
1165   2              i=0;  
1166   2              Send_Request(OPEN_FILE,0); 
1167   2                      for(i=0;i<37;i++) Com_Recv_Buf[i]=0x00;
1168   2                      Com_Read_Point=0;
C51 COMPILER V7.09   DATAFAX                                                               03/22/2005 01:42:11 PAGE 20  

1169   2                      Com_Write_Point=0;
1170   2                      LCD_Show_Data(2,20,"Get open Response ");
1171   2                  if(!Get_Response()) 
1172   2                      {
1173   3                              j++;
1174   3                              if(j>3)
1175   3                              {
1176   4                                      Error_Display("NO RESPONSE");
1177   4                                      return;
1178   4                              }
1179   3                              for(i=0;i<37;i++) Com_Recv_Buf[i]=0x00;
1180   3                              Com_Read_Point=0;
1181   3                              Com_Write_Point=0;
1182   3                              
1183   3                      }          
1184   2              while(filesize>0)
1185   2              {
1186   3                              if(Flag_1ms)
1187   3                      {
1188   4                              Flag_1ms=false;
1189   4                              Capture_KEY_Event();
1190   4                      }     
1191   3                              if(Key_Down.Active)
1192   3                  {
1193   4                      Key_Down.Active=false;
1194   4                      if(Key_Down.Byte_data==KB_EXIT) 
1195   4                      {          
1196   5                              Do_Cancel();  
1197   5                                          Flag_Exit=true;
1198   5                              Flag_KB_Enable=true; 
1199   5                              }
1200   4                  }
1201   3                              if(Flag_Exit) return;
1202   3                              LCD_Show_Data(2,20,"FILE SEEKING..");
1203   3                  if(File_Seek(File_Point))
1204   3                  {   
1205   4                                      temp_point=File_Point;
1206   4                                      temp_size=filesize;
1207   4                      Send_Request(FILE_SEEK,File_Point);
1208   4                                      for(i=0;i<37;i++) Com_Recv_Buf[i]=0x00;
1209   4                                      Com_Read_Point=0;
1210   4                                      Com_Write_Point=0;
1211   4                                      LCD_Show_Data(2,20,"Get seek Response ");
1212   4                      if(Get_Response()) 
1213   4                                      {
1214   5                                              if (filesize<=Block_Size) Block_Size=filesize; //last Block;
1215   5                                              LCD_Show_Data(2,20,"READING DATA..");
1216   5                              Read_File(Block_Size);
1217   5                                          SPI_Read_Point=0;
1218   5                                              SPI_Write_Point=0;
1219   5                              Cnt_Long_1ms=0;
1220   5                              while(Cnt_Long_1ms<_5S)
1221   5                              {
1222   6                                                      if(Flag_1ms)
1223   6                                              {
1224   7                                                              Flag_1ms=false;
1225   7                                                              Capture_KEY_Event();
1226   7                                              }     
1227   6                                                      if(Key_Down.Active)
1228   6                                      {
1229   7                                      Key_Down.Active=false;
1230   7                                      if(Key_Down.Byte_data==KB_EXIT) 
C51 COMPILER V7.09   DATAFAX                                                               03/22/2005 01:42:11 PAGE 21  

1231   7                                      {          
1232   8                                              Do_Cancel();   
1233   8                                                                  Flag_Exit=true;
1234   8                                              Flag_KB_Enable=true; 
1235   8                                                                      return;
1236   8                                                      }
1237   7                                      }
1238   6                                                      while(SPI_Read_Point!=SPI_Write_Point)
1239   6                                                      {
1240   7                                                              if(Flag_1ms)
1241   7                                                      {
1242   8                                                              Flag_1ms=false;
1243   8                                                              Capture_KEY_Event();
1244   8                                                      }     
1245   7                                                              if(Key_Down.Active)
1246   7                                              {
1247   8                                              Key_Down.Active=false;
1248   8                                              if(Key_Down.Byte_data==KB_EXIT) 
1249   8                                              {          
1250   9                                                      Do_Cancel();   
1251   9                               

⌨️ 快捷键说明

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