51单片机各类源程序集锦
源代码在线查看: isr.h
/*
//*************************************************************************
//
// ZLGMCU
// www.zlgmcu.com
// File Name: ISR.h
// Revision: V0.2(2002-04-08)
// Use library: USB51S.LIB
// Note: USB51S.LIB不带DMA控制功能
//*************************************************************************
*/
#ifndef __ISR_H__
#define __ISR_H__
/*
//*************************************************************************
// D12控制引脚定义
//*************************************************************************
*/
sbit MCU_D12CS = P1^5;
sbit MCU_D12RST = P3^4;
//sbit MCU_D12RST = P3^5;
sbit D12SUSPD = P3^5;
/*
//*************************************************************************
// basic #defines
//*************************************************************************
*/
#define DISABLE EA=0
#define ENABLE EA=1
#define MAX_ENDPOINTS (unsigned char)0x3
#define EP0_TX_FIFO_SIZE 16
#define EP0_RX_FIFO_SIZE 16
#define EP0_PACKET_SIZE 16
#define EP1_TX_FIFO_SIZE 4
#define EP1_RX_FIFO_SIZE 4
#define EP1_PACKET_SIZE 4
#define EP2_TX_FIFO_SIZE 64
#define EP2_RX_FIFO_SIZE 64
#define EP2_PACKET_SIZE 64
#define D12_NOLAZYCLOCK 0x02
#define D12_CLOCKRUNNING 0x04
#define D12_INTERRUPTMODE 0x08
#define D12_SOFTCONNECT 0x10
#define D12_ENDP_NONISO 0x00
#define D12_ENDP_ISOOUT 0x40
#define D12_ENDP_ISOIN 0x80
#define D12_ENDP_ISOIO 0xC0
#define D12_CLOCK_12M 0x03
#define D12_CLOCK_4M 0x0b
#define D12_SETTOONE 0x40
#define D12_SOFONLY 0x80
/*
//*************************************************************************
// masks
//*************************************************************************
*/
#define USB_RECIPIENT (unsigned char)0x1F
#define USB_RECIPIENT_DEVICE (unsigned char)0x00
#define USB_RECIPIENT_INTERFACE (unsigned char)0x01
#define USB_RECIPIENT_ENDPOINT (unsigned char)0x02
#define USB_REQUEST_TYPE_MASK (unsigned char)0x60
#define USB_STANDARD_REQUEST (unsigned char)0x00
#define USB_CLASS_REQUEST (unsigned char)0x20
#define USB_VENDOR_REQUEST (unsigned char)0x40
#define USB_REQUEST_MASK (unsigned char)0x0F
#define DEVICE_ADDRESS_MASK 0x7F
#define USB_ENDPOINT_DIRECTION_MASK 0x80
/*
//*************************************************************************
// macros
//*************************************************************************
*/
#define SWAP(x) ((((x) & 0xFF) > 8) & 0xFF))
#define MSB(x) (((x) >> 8) & 0xFF)
#define LSB(x) ((x) & 0xFF)
#define FALSE 0
#define TRUE (!FALSE)
/*
//*************************************************************************
// basic typedefs
//*************************************************************************
*/
typedef unsigned char UCHAR;
typedef unsigned short USHORT;
typedef unsigned long ULONG;
typedef unsigned char BOOL;
/*
//*************************************************************************
// structure and union definitions
//*************************************************************************
*/
typedef union _epp_flags
{
struct _flags
{
unsigned char timer : 1;
unsigned char bus_reset : 1;
unsigned char suspend : 1;
unsigned char setup_packet : 1;
unsigned char remote_wakeup : 1;
unsigned char in_isr : 1;
unsigned char control_state : 2;
unsigned char configuration : 1;
unsigned char command : 1;
unsigned char ep1_rxdone : 1;
unsigned char ep2_rxdone : 1; //Add by Liu Ying Bin
} bits;
unsigned short value;
} EPPFLAGS;
typedef union _rom_addr
{
struct _bytes
{
unsigned char high;
unsigned char low;
}byte;
unsigned int word;
}rom_addr;
typedef struct _device_request
{
unsigned char bmRequestType;
unsigned char bRequest;
unsigned short wValue;
unsigned short wIndex;
unsigned short wLength;
} DEVICE_REQUEST;
typedef struct _IO_REQUEST {
unsigned short uAddressL;
unsigned char bAddressH;
unsigned short uSize;
unsigned char bCommand;
} IO_REQUEST, *PIO_REQUEST;
#define MAX_CONTROLDATA_SIZE 8
typedef struct _control_xfer
{
DEVICE_REQUEST DeviceRequest;
unsigned short wLength;
unsigned short wCount;
unsigned char * pData;
unsigned char dataBuffer[MAX_CONTROLDATA_SIZE];
} CONTROL_XFER;
/*
//*************************************************************************
// USB utility functions
//*************************************************************************
*/
extern void disconnect_USB(void);
extern void connect_USB(void);
extern void reconnect_USB(void);
extern void init_unconfig(void);
extern void init_config(void);
extern void single_transmit(unsigned char * pData, unsigned char len);
extern void code_transmit(unsigned char code * pRomData, unsigned short len);
extern void control_handler(void);
extern void reserved(void);
extern void fn_usb_isr(void);
extern void usbserve(void);
extern void D12_SetMode(unsigned char bConfig, unsigned char bClkDiv);
extern void D12_SetDMA(unsigned char bMode);
extern unsigned char D12_ReadLastTransactionStatus(unsigned char bEndp);
extern unsigned char D12_ReadEndpoint(unsigned char endp, unsigned char len, unsigned char * buf);
extern unsigned char D12_WriteEndpoint(unsigned char endp, unsigned char len, unsigned char * buf);
#endif