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

📄 xxgmain.lst

📁 200元买来的D12开发资料,包括上位机驱动和应用程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 210          
 211          //----------------------------------
 212          void check_key_LED(void)
 213          {
 214   1              static unsigned char c, last_key = 0xf;
 215   1      
 216   1              c = MCU_SWM0 & MCU_SWM1;
 217   1              c &= 0x0f;
 218   1              if (c != last_key) {
 219   2                      D12_WriteEndpoint(3, 1, &c);
 220   2              }
 221   1      
 222   1              last_key = c;
 223   1      
 224   1              if(bEPPflags.bits.ep1_rxdone) {
 225   2                      DISABLE;
 226   2                      bEPPflags.bits.ep1_rxdone = 0;
 227   2                      ENABLE;
 228   2                      MCU_LED0 = !(GenEpBuf[3] & 0x1);
 229   2                      MCU_LED1 = !(GenEpBuf[3] & 0x2);
 230   2              }
 231   1      }
 232          //--------------------------
 233          void init_unconfig(void)
 234          {
 235   1              //unsigned char i;
 236   1      
 237   1              D12_SetEndpointEnable(0);       /* Disable all endpoints but EPP0. */
 238   1      }
 239          
 240          void init_config(void)
 241          {
C51 COMPILER V7.02b   XXGMAIN                                                              03/17/2005 23:11:50 PAGE 5   

 242   1              D12_SetEndpointEnable(1);       /* Enable  generic/iso endpoints. */
 243   1      }
 244          //--------------------------
 245          
 246          void single_transmit(unsigned char * buf, unsigned char len)
 247          {
 248   1              if( len <= EP0_PACKET_SIZE) {
 249   2                      D12_WriteEndpoint(1, len, buf);
 250   2              }
 251   1      }
 252          
 253          void code_transmit(unsigned char code * pRomData, unsigned short len)
 254          {
 255   1              ControlData.wCount = 0;
 256   1              if(ControlData.wLength > len)
 257   1                      ControlData.wLength = len;
 258   1      
 259   1              ControlData.pData = pRomData;
 260   1              if( ControlData.wLength >= EP0_PACKET_SIZE) {   // 如果发送代码大于包长度
 261   2                      D12_WriteEndpoint(1, EP0_PACKET_SIZE, ControlData.pData);
 262   2                      ControlData.wCount += EP0_PACKET_SIZE;
 263   2      
 264   2                      DISABLE;
 265   2                      bEPPflags.bits.control_state = USB_TRANSMIT;
 266   2                      ENABLE;
 267   2              }
 268   1              else {                                          //发送代码小于包长度
 269   2                      D12_WriteEndpoint(1, ControlData.wLength, pRomData);
 270   2                      ControlData.wCount += ControlData.wLength;
 271   2                      DISABLE;
 272   2                      bEPPflags.bits.control_state = USB_IDLE;
 273   2                      ENABLE;
 274   2              }
 275   1      }
 276          
 277          //---------------------------
 278          
 279          void setup_dma()
 280          {
 281   1              ioSize = ioRequest.uSize;
 282   1              ioCount = 0;
 283   1      
 284   1              DISABLE;
 285   1              bEPPflags.bits.dma_state = DMA_RUNNING;
 286   1              ENABLE;
 287   1      
 288   1              single_transmit(0, 0);
 289   1      
 290   1              if(ioRequest.bCommand & 0x1) {
 291   2                      if(ioSize > 64 || ioSize == 0) {
 292   3                              //if(bNoRAM)
 293   3                                      D12_WriteEndpoint(5, 64, EpBuf);
 294   3                              //else
 295   3                              //      D12_WriteEndpoint(5, 64, MainEpBuf);
 296   3                              ioCount += 64;
 297   3                      }
 298   2                      else {
 299   3                              //if(bNoRAM)
 300   3                                      D12_WriteEndpoint(5, ioSize, EpBuf);
 301   3                              //else
 302   3                              //      D12_WriteEndpoint(5, ioSize, MainEpBuf);
 303   3                              ioCount += ioSize;
C51 COMPILER V7.02b   XXGMAIN                                                              03/17/2005 23:11:50 PAGE 6   

 304   3                      }
 305   2              }
 306   1      }
 307          
 308          //------------------------------
 309          void control_handler()
 310          {
 311   1              unsigned char type, req;
 312   1      
 313   1              type = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_TYPE_MASK; //0x60
 314   1              req = ControlData.DeviceRequest.bRequest & USB_REQUEST_MASK;            //0x0F
 315   1      
 316   1              //help_devreq(type, req); // print out device request
 317   1      
 318   1              if (type == USB_STANDARD_REQUEST)
 319   1                      (*StandardDeviceRequest[req])();
 320   1              else if (type == USB_VENDOR_REQUEST)
 321   1                      (*VendorDeviceRequest[req])();
 322   1              else
 323   1                      stall_ep0();
 324   1      
 325   1      }
 326          
 327          
 328          //-------------------------------------------
 329          
 330          //-------------------------------------------
 331          
 332          void main()
 333          {
 334   1              unsigned char key, i;
 335   1              //bNoRam=1;
 336   1              //DISABLE;
 337   1              MCU_D12RST = 1;
 338   1              init_port();
 339   1              init_serial();
 340   1              init_timer0();
 341   1              EA = 0;
 342   1              //for test
 343   1              MCU_LED0=0;
 344   1              MCU_LED1=0;
 345   1              MCU_LED0=1;
 346   1              MCU_LED1=1;
 347   1              //--------------
 348   1              //printf("Re-connect PDIUSBD12 evaluation board to USB.\n");
 349   1              IE0=0;
 350   1              IT0=0;
 351   1              EX0=1;
 352   1              //--------------------------
 353   1      //      MCU_D12RST = 0;
 354   1      //      MCU_D12RST = 1;
 355   1              //--------------------
 356   1      
 357   1      //      MCU_D12CS = 0x1;
 358   1              //-----------------------
 359   1      
 360   1              //for(i = 0; i < 16; i ++)
 361   1              //      MainEpBuf[i] = i;
 362   1              //for(i = 0; i < 16; i ++) {
 363   1              //      if(MainEpBuf[i] != i)
 364   1              //              break;
 365   1              //      }
C51 COMPILER V7.02b   XXGMAIN                                                              03/17/2005 23:11:50 PAGE 7   

 366   1              //if(i < 16)
 367   1                      bNoRAM = TRUE;
 368   1              //else
 369   1              //      bNoRAM = FALSE;
 370   1      
 371   1              //--------------------------
 372   1      //      MCU_D12CS = 0x0;
 373   1      
 374   1      
 375   1      
 376   1              //bNoRam=TRUE;
 377   1              //---------------------------
 378   1      
 379   1              //----------------------------
 380   1              /*
 381   1              if(MCU_SWM0 == 0 && MCU_SWM1 == 0) {
 382   1                      MCU_D12RST = 0;
 383   1                      MCU_D12RST = 1;
 384   1                      D12_SetDMA(0x0);
 385   1              }
 386   1              */
 387   1              //if((i = D12_GetDMA()) == 0xC3)
 388   1      //              {D12_SendResume();}
 389   1              //else {
 390   1              //      bEPPflags.value = 0;
 391   1      
 392   1                      /* Power on reset, lightup LEDs for 1 sec,
 393   1                         disconnect and reconnect Soft-Connect */
 394   1                      //printf("\nPDIUSBD12 SMART evaluation board firmware V3.0.\n");
 395   1              i=D12_ReadInterruptRegister();
 396   1              i=0;
 397   1              //i=D12_ReadEndpointStatus(0);
 398   1              i=D12_ReadLastTransactionStatus(0);
 399   1              i=D12_ReadLastTransactionStatus(1);
 400   1              i=D12_ReadLastTransactionStatus(2);
 401   1              i=D12_ReadLastTransactionStatus(3);
 402   1              i=D12_ReadLastTransactionStatus(4);
 403   1              i=D12_ReadLastTransactionStatus(5);
 404   1              ENABLE;
 405   1              reconnect_USB();
 406   1              ENABLE;
 407   1       //             }
 408   1              //=======================================
 409   1              /* Main program loop */
 410   1      
 411   1              while( TRUE ){
 412   2      
 413   2                      if (bEPPflags.bits.timer){
 414   3                              DISABLE;
 415   3                              bEPPflags.bits.timer = 0;
 416   3                              ENABLE;
 417   3      
 418   3                              if(bEPPflags.bits.configuration)
 419   3                                      check_key_LED();
 420   3                      }
 421   2      
 422   2                      if (bEPPflags.bits.bus_reset) {
 423   3                              DISABLE;
 424   3                              bEPPflags.bits.bus_reset = 0;
 425   3                              ENABLE;
 426   3                              // Release D12's SUSPEND pin after bus reset
 427   3                              // Enable 74HCT123 pulse generation before disconnect

⌨️ 快捷键说明

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