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

📄 d12.lst

📁 单片机和D12通讯的C程序.实现了单片机通过USB口和电脑通讯.
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.01  D12                                                                    02/17/2006 15:09:23 PAGE 4   

                                              #endif
 180   4                                      pBuffer++;
 181   4                              }
 182   3                              #ifndef _INT_MODE_      
                                              #ifdef _Debug_  
                                                      printf("\n");
                                              #endif
                                      #endif
 187   3                      }
 188   2                      else
 189   2                      {
 190   3                              //When received data length is longer than expected length,it show an error happneed.
 191   3                              //For PDIUSBD12,no endpoint buffer length is longer than 64,so we return 0xff to 
 192   3                              //flag an error happened.
 193   3                              bByteCount = D12_BUFFER_LENGTH_ERROR;
 194   3                      }       
 195   2                      //whether error is happened or not,we should clear buffer
 196   2                      D12_COMMAND_ADDRESS =  D12_CLEAR_BUFFER_SELECTED_ENDPOINT;                      //after read buffer finished,clear buffer
 197   2      
 198   2      
 199   2              }
 200   1      
 201   1              return bByteCount;              
 202   1      }
 203          
 204          //
 205          //*************************************************************************
 206          //      Parameter:
 207          //              In : bEndpointIndex     : the endpoint index of PDIUSBD12
 208          //                       bLength                : data byte count that will write to transmit buffer
 209          //                       pBuffer                : pointer,start address of data source,which data 
 210          //                                                        will  write to transmit buffer
 211          //              Out: None
 212          //      Function:
 213          //              PDIUSBD12 Register: 0xF0H
 214          //              Write data to transmit buffer and validae it. When received a corresponding IN token in
 215          //              interrupt routine,those data will be transmit to HOST.
 216          void D12WriteBuffer(unsigned char bEndpointIndex,unsigned char bLength, unsigned char * pBuffer)
 217          {
 218   1              unsigned char i;
 219   1      
 220   1              D12_COMMAND_ADDRESS =  bEndpointIndex;  //select endpoint,the optional read one byte is not read
 221   1      
 222   1              D12_COMMAND_ADDRESS =  0xF0;                    //write endpoint buffer
 223   1              D12_DATA_ADDRESS = 0;                                   //first byte is reserved,should wirte 0x00
 224   1              D12_DATA_ADDRESS = bLength;                             //the second byte is the data length that will be 
 225   1                                                                                              //write to buffer
 226   1              #ifdef _Debug_
 227   1              printf("write buffer:");
 228   1              #endif
 229   1              for(i=0; i<bLength; i++)                                //write buffer
 230   1              {
 231   2                      D12_DATA_ADDRESS = *pBuffer;
 232   2                      #ifdef _Debug_
 233   2                      printf("%x,",(unsigned int)(*pBuffer));
 234   2                      #endif
 235   2                      pBuffer++;
 236   2              }
 237   1              #ifdef _Debug_  
 238   1              printf("\n");
 239   1              #endif
 240   1              D12_COMMAND_ADDRESS =  0xFA;                    //validate buffer
C51 COMPILER V7.01  D12                                                                    02/17/2006 15:09:23 PAGE 5   

 241   1      }
 242          
 243          //
 244          //*************************************************************************
 245          //      Parameter:
 246          //              In : bEndpointIndex : The endpoint index number of  PDIUSBD12 
 247          //                       bStalled               : If 1, this index endpoint will be set STALL status
 248          //              Out: None
 249          //      Function:
 250          //              PDIUSBD12 Register: bEndpointIndex
 251          //              Set USB address of PDIUSBD12,and if bEanble is 1,the address will 
 252          //              be valid immediately.
 253          void D12SetEndpointStatus(unsigned char bEndpointIndex, unsigned char bStalled)
 254          {
 255   1              D12_COMMAND_ADDRESS = bEndpointIndex;
 256   1              D12_DATA_ADDRESS = bStalled;
 257   1      }
 258          
 259          //
 260          //*************************************************************************
 261          //      Paremeter:
 262          //              In : bAddress   : The USB address that PDIUSBD12 will be set
 263          //                       bEnable        : If 1, bAddress will be enabled,vice visa
 264          //              Out: None
 265          //      Function:
 266          //              PDIUSBD12 Register: 0xD0H
 267          //              Set USB address of PDIUSBD12,and if bEanble is 1,the address will 
 268          //              be validata immediately.
 269          void D12AcknowledgeSetup(void)
 270          {
 271   1              D12_COMMAND_ADDRESS =  D12_SELECT_ENDPOINT_CONTROL_OUT;                 //select endpoint0 OUT
 272   1              D12_COMMAND_ADDRESS =  D12_ACKNOWLEDGE_SETUP_SELECTED_ENDPOINT; //acknowledge Setup command
 273   1              D12_COMMAND_ADDRESS =  D12_CLEAR_BUFFER_SELECTED_ENDPOINT;              //setup packet is 8 byte,clear it after read 
             -it
 274   1              D12_COMMAND_ADDRESS =  D12_SELECT_ENDPOINT_CONTROL_IN;                  //select endpoint0 IN
 275   1              D12_COMMAND_ADDRESS =  D12_ACKNOWLEDGE_SETUP_SELECTED_ENDPOINT; //acknowledge Setup command
 276   1      
 277   1      }
 278          
 279          //
 280          //*************************************************************************
 281          //      Parameter:
 282          //              In :
 283          //              Out:
 284          //      Function:
 285          //              PDIUSBD12 Register: 0xF2H
 286          //              It is very simple and no necessary to implement it as an function
 287          /*
 288          D12ClearBuffer()
 289          {
 290          ;
 291          }
 292          */
 293          //
 294          //*************************************************************************
 295          //      Parameter:
 296          //              In :
 297          //              Out:
 298          //      Function:
 299          //              PDIUSBD12 Register: 0xFAH
 300          //              It is very simple and no necessary to implement as an function
 301          /*
C51 COMPILER V7.01  D12                                                                    02/17/2006 15:09:23 PAGE 6   

 302          D12VaidateBuffer()
 303          {
 304          ;
 305          }
 306          */
 307          
 308          //
 309          //*************************************************************************
 310          //      Parameter:
 311          //              In :
 312          //              Out:
 313          //      Function:
 314          //              PDIUSBD12 Register: 0xF6H
 315          //              If remote wake is enabled,and Host is in suspend state,this function
 316          //              will awake Host. 
 317          //              Interface studio USB1.1 develop board does not implement this function
 318          //              in main program,so here comment out this function.User can use it
 319          //              if necessary.
 320          /*
 321          void D12SendResume(void)
 322          {
 323                  D12_COMMAND_ADDRESS = 0xF6;
 324          }
 325          */
 326          
 327          //
 328          //*************************************************************************
 329          //      Parameter:
 330          //              In :
 331          //              Out:
 332          //      Function:
 333          //              PDIUSBD12 Register: 0xF5H
 334          //              Although this firmware does not support isochronous transfer,
 335          //              synchronization frame request still is implementated.
 336          
 337          void D12ReadCurrentFrameNumber(unsigned char *pBuffer)
 338          {
 339   1              
 340   1              D12_COMMAND_ADDRESS = D12_READ_CURRENT_FRAME_NUMBER;
 341   1              *pBuffer = D12_DATA_ADDRESS;
 342   1              *(pBuffer+1) = D12_DATA_ADDRESS;
 343   1      
 344   1      }
 345          
 346          
 347          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    321    ----
   CONSTANT SIZE    =     20    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       8
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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