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

📄 user.pre

📁 USB的开发例子,用PIC18F4550实现.可以和电脑用USB控制连接.
💻 PRE
📖 第 1 页 / 共 4 页
字号:
unsigned :8;
unsigned EPNum:4;
unsigned :3;
unsigned EPDir:1;
unsigned :8;
unsigned :8;
unsigned :8;
} j;


} CTRL_TRF_SETUP;

# 179
typedef union _CTRL_TRF_DATA
{

struct
{
byte _byte[8];
} a;


struct
{
byte _byte0;
byte _byte1;
byte _byte2;
byte _byte3;
byte _byte4;
byte _byte5;
byte _byte6;
byte _byte7;
} b;
struct
{
word _word0;
word _word1;
word _word2;
word _word3;
} c;

} CTRL_TRF_DATA;

# 70 "C:\MCHPFSUSB\fw\Cdc\system\usb\usbmmap.h"
typedef union _USB_DEVICE_STATUS
{
byte _byte;
struct
{
unsigned RemoteWakeup:1;
unsigned ctrl_trf_mem:1;
} a;
} USB_DEVICE_STATUS;

typedef union _BD_STAT
{
byte _byte;
struct{
unsigned BC8:1;
unsigned BC9:1;
unsigned BSTALL:1;
unsigned DTSEN:1;
unsigned INCDIS:1;
unsigned KEN:1;
unsigned DTS:1;
unsigned UOWN:1;
} a;
struct{
unsigned BC8:1;
unsigned BC9:1;
unsigned PID0:1;
unsigned PID1:1;
unsigned PID2:1;
unsigned PID3:1;
unsigned :1;
unsigned UOWN:1;
} b;
struct{
unsigned :2;
unsigned PID:4;
unsigned :2;
} c;
} BD_STAT;

typedef union _BDT
{
byte _byte[4];

struct
{
BD_STAT Stat;
byte Cnt;
byte ADRL;
byte ADRH;
} a;
struct
{
byte StatWhole;
byte Cnt;
byte* ADR;
} b;
} BDT;


extern byte usb_device_state;
extern USB_DEVICE_STATUS usb_stat;
extern byte usb_active_cfg;
extern byte usb_alt_intf[1];

# 146
static volatile far BDT ep0Bo @ 0x400;
static volatile far BDT ep0Bi @ 0x404;


static volatile far BDT ep1Bo @ 0x408;
static volatile far BDT ep1Bi @ 0x40C;



static volatile far BDT ep2Bo @ 0x410;
static volatile far BDT ep2Bi @ 0x414;



static volatile far BDT ep3Bo @ 0x418;
static volatile far BDT ep3Bi @ 0x41C;

# 225
static volatile far CTRL_TRF_SETUP SetupPkt @ 0x480;
static volatile far CTRL_TRF_DATA CtrlTrfData @ 0x4C0;

static volatile far unsigned char cdc_notice[8] @ 0x500;
static volatile far unsigned char cdc_data_rx[64] @ 0x600;
static volatile far unsigned char cdc_data_tx[64] @ 0x700;

# 207 "C:\MCHPFSUSB\fw\Cdc\system\usb\usbdrv\usbdrv.h"
void USBCheckBusStatus(void);
void USBDriverService(void);
void USBRemoteWakeup(void);
void USBSoftDetach(void);

void ClearArray(byte* startAdr,byte count);

# 68 "C:\MCHPFSUSB\fw\Cdc\system\usb\usbctrltrf\usbctrltrf.h"
extern byte ctrl_trf_session_owner;

extern POINTER pSrc;
extern POINTER pDst;
extern WORD wCount;


void USBCtrlEPService(void);
void USBCtrlTrfTxService(void);
void USBCtrlTrfRxService(void);
void USBCtrlEPServiceComplete(void);
void USBPrepareForNextSetupTrf(void);

# 92 "C:\MCHPFSUSB\fw\Cdc\system\usb\usb9\usb9.h"
void USBCheckStdRequest(void);

# 41 "C:\MCHPFSUSB\fw\Cdc\user\user.h"
void UserInit(void);
void ProcessIO(void);

# 41 "C:\MCHPFSUSB\fw\Cdc\user\temperature.h"
extern WORD temperature;
extern char tempString[10];


void InitTempSensor(void);
BOOL AcquireTemperature(void);
void UpdateCelsiusASCII(void);

# 68 "C:\MCHPFSUSB\fw\Cdc\user\user.c"
byte old_sw2,old_sw3;

char input_buffer[64];
char output_buffer[64];

const char welcome[]={"PIC18F4550 Full-Speed USB - CDC RS-232 Emulation Demo\r\n\r\n"};
const char ansi_clrscr[]={"\x1b[2J"};


void InitializeUSART(void);
void BlinkUSBStatus(void);
BOOL Switch2IsPressed(void);
BOOL Switch3IsPressed(void);

void Exercise_Example(void);

void Exercise_01(void);
void Exercise_02(void);
void Exercise_03(void);
void Exercise_04(void);
void Exercise_05(void);

# 95
void UserInit(void)
{
LATD &= 0xF0; TRISD &= 0xF0;;
TRISB4=1;TRISB5=1;;
old_sw2 = RB4;
old_sw3 = RB5;

InitTempSensor();

InitializeUSART();

}

void InitializeUSART(void)
{

TRISC7=1;
TRISC6=0;

# 118
SPBRG = 0x71;
SPBRGH = 0x02;
TXSTA = 0x24;
RCSTA = 0x90;
BAUDCON = 0x08;
}

# 141
void ProcessIO(void)
{
BlinkUSBStatus();


if((usb_device_state < 6)||(SUSPND==1)) return;

Exercise_Example();

Exercise_01();
Exercise_02();
Exercise_03();
Exercise_04();
Exercise_05();

}

void Exercise_Example(void)
{
static byte start_up_state = 0;

if(start_up_state == 0)
{
if(Switch2IsPressed())
start_up_state++;
}
else if(start_up_state == 1)
{
if((cdc_trf_state == 0))
{
putrsUSBUSART(ansi_clrscr);
start_up_state++;
}
}
else if(start_up_state == 2)
{
if((cdc_trf_state == 0))
{
putrsUSBUSART("\rMicrochip Technology Inc., 2004\r\n");
start_up_state++;
}
}
else if(start_up_state == 3)
{
if((cdc_trf_state == 0))
{
putrsUSBUSART(welcome);
start_up_state++;
}
}

}

void Exercise_01(void)
{

# 216
}

const char ex02_string[]={"Type in a string here.\r\n"};
void Exercise_02(void)
{

# 243
}

void Exercise_03(void)
{

# 262
}

void Exercise_04(void)
{

# 290
}

void Exercise_05(void)
{

# 326
static word ex05_count;

if(ex05_count == 0)
{
AcquireTemperature();
UpdateCelsiusASCII();




while (*tempString) { while (TXIF == 0) continue; TXREG =*tempString++; };
ex05_count = 10000;


}
else
ex05_count--;

}

# 364
void BlinkUSBStatus(void)
{
static word led_count=0;

if(led_count == 0)led_count = 10000U;
led_count--;

# 376
if(SUSPND == 1)
{
if(led_count==0)
{
LATD0 = !LATD0;;
LATD1 = LATD0;
}
}
else
{
if(usb_device_state == 0)
{
{LATD0 = 0;;LATD1 = 0;;};
}
else if(usb_device_state == 1)
{
{LATD0 = 1;;LATD1 = 1;;};
}
else if(usb_device_state == 2)
{
{LATD0 = 1;;LATD1 = 0;;};
}
else if(usb_device_state == 3)
{
{LATD0 = 0;;LATD1 = 1;;};
}
else if(usb_device_state == 5)
{
if(led_count == 0)
{
LATD0 = !LATD0;;
LATD1 = 0;;
}
}
else if(usb_device_state == 6)
{
if(led_count==0)
{
LATD0 = !LATD0;;
LATD1 = !LATD0;
}
}
}

}

BOOL Switch2IsPressed(void)
{
if(RB4 != old_sw2)
{
old_sw2 = RB4;
if(RB4 == 0)
return TRUE;
}
return FALSE;
}

BOOL Switch3IsPressed(void)
{
if(RB5 != old_sw3)
{
old_sw3 = RB5;
if(RB5 == 0)
return TRUE;
}
return FALSE;
}

⌨️ 快捷键说明

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