usbbootloader.c

来自「PSOC usb-bootloader实现代码 用于在PSOC上通过USB口实现」· C语言 代码 · 共 55 行

C
55
字号
//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include "usb.h"
#include "bootloader.h"

#pragma interrupt_handler EP2InterruptHandler
void EP2InterruptHandler(void);

BYTE ReadBuffer[8];
WORD wCount;
BYTE bCount;

BYTE Ep2Count;

void main()
{
int x;

   PWM_Start();
   M8C_EnableGInt;
   USBFS_1_Start(0,3);
   while(!(USBFS_1_bGetConfiguration())); 
   USBFS_1_INT_REG |= (USBFS_1_INT_EP1_MASK | USBFS_1_INT_EP2_MASK);
   USBFS_1_EnableOutEP(2);
   while(1)
   {
      if(Ep2Count != 0)
      {
        wCount = USBFS_1_wGetEPCount(2);
        bCount = USBFS_1_bReadOutEP(2, ReadBuffer, 8);
         Ep2Count = 0;
         USBFS_1_EnableOutEP(2);
         if((ReadBuffer[0]==0x75) && (ReadBuffer[1]==0x20))
         {
            M8C_DisableGInt;
            PWM_Stop();
            USB_Stop();
            EnterBootloader();
         }
      }
   }
}

void EP2InterruptHandler(void)
{
    Ep2Count++;
}    

#pragma abs_address 0x3FFE
const int Checksum = 0xDD12;
#pragma end_abs_address

⌨️ 快捷键说明

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