最近打算用PIC18F4550做个USB的东西,打算先在protues上仿真一下,但是usb模块一直没有工作,有没有熟悉这块的朋友帮忙看一下,是不是我初始化上面有问题呢?或者是protues的电路图有问题?
我的代码:
#include <htc.h>
#include <p18f4550.h>
#pragma config MCLRE = 0
#pragma config WDT = OFF
#pragma config VREGEN = 1
#pragma config FOSC = HSPLL_HS
#pragma config USBDIV = 2
#pragma config CPUDIV = OSC1_PLL2
#pragma config PLLDIV = 1
static unsigned char BD0STAT_OUT @ 0x400;
static unsigned char BD0CNT_OUT @ 0x401;
static unsigned char BD0ADRL_OUT @ 0x402;
static unsigned char BD0ADRH_OUT @ 0x403;
static unsigned char BD0STAT_IN @ 0x404;
static unsigned char BD0CNT_IN @ 0x405;
static unsigned char BD0ADRL_IN @ 0x406;
static unsigned char BD0ADRH_IN @ 0x407;
void init(void);
void main(void)
{
TRISB=0;
PORTB=0x0f;
init();
while(1);
}
void init(void)
{
GIE = 1;
PEIE = 1;
USBIE = 1;
UPUEN = 1;
PKTDIS = 0;
UTRDIS = 0;
FSEN = 1;
BD0STAT_OUT = 0x00001100;
//调试的时候发现对这个寄存器的设置没有生效,寄存器仍然是0,所以推测是usb模块没有工作。
BD0CNT_OUT = 0x40;
BD0ADRL_OUT = 0x00;
BD0ADRH_OUT = 0x05;
UEP0 = 0b00010110;
UIE = 0b01111111;
USBEN = 1;
}
void interrupt intfunc(void)
{
int i;
if(UIR!=0)
PORTB = 0xf0;
//仿真时,此处UIR一直都是0
USBIF = 0;
}
这是protues里的电路:
此帖出自
小平头技术问答
一周热门 更多>