PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và PIC

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Tìm Kiếm Bài Trong Ngày Ðánh Dấu Ðã Ðọc Vi điều khiển

Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 26-04-2010, 07:53 PM   #1
somali123
Đệ tử 1 túi
 
Tham gia ngày: Mar 2010
Bài gửi: 13
:
18F4550 giao tiếp USB thất bại

mình đang cố gắng giao tiếp USB qua 18f4550,chạy mô phỏng proteus thành công rùi,trong manage của mycomputer thông báo đã nhận thiết bị,bây giờ mình cắm trên testboard,nhưng kết quả là thất bại liên tục,cũng có khi nhận dc thông báo USB not recognized,nhưng đa số không có tín hiệu ji,mình cắm theo mạch proteus,dùng thạch anh 12Mhz và 2 tụ 22pF như trong khai báo chuơng trình,nhưng chan 18 Vusb trong mạch là 470nF,mình chỉ dùng 1uF không biết có sao không,nghe nói chân 18 điện áp là 3.3V nhưng mình đo thì không có V nào,các chân nguồn mass đã nối cẩn thận,chân D+, D- cũng đã coi kĩ,mình post code lên mọi người xem giúp có bị sai ji không nhé,mình sợ nhất là phần cấu hình #fuses sai,thanks all!!!

#include "usb_demo_bulk.h"
#include <pic18_usb.h>
#include <usb_desc_scope1.h>
#include <usb.c>
#include <lcd4bit.c>
void usb_debug_task(void)
{
static int8 last_connected;
static int8 last_enumerated;
int8 new_connected;
int8 new_enumerated;
new_connected=usb_attached();
new_enumerated=usb_enumerated();
if (new_connected && !last_connected)
printf("\r\n\nUSB connected, waiting for enumaration...");
if (!new_connected && last_connected)
printf("\r\n\nUSB disconnected, waiting for connection...");
if (new_enumerated && !last_enumerated)
printf("\r\n\nUSB enumerated by PC/HOST");
if (!new_enumerated && last_enumerated)
printf("\r\n\nUSB unenumerated by PC/HOST, waiting for enumeration...");
last_connected=new_connected;
last_enumerated=new_enumerated;
}

void main()
{
int8 out_data[3];
int8 in_data[64];
int8 i=0;
char c;
int8 send_timer=0;
int8 count=0;


setup();


usb_init_cs();
lcd_init();

while (TRUE)
{
usb_task();
usb_debug_task();
if(usb_enumerated())
{
if (!send_timer)
{
count++;
send_timer=250;
out_data[0]=100;
out_data[1]=111;
out_data[2]=233;
if (usb_put_packet(1, out_data, 3, USB_DTS_TOGGLE))
printf("\r\n<-- Sending 2 bytes: 0x%X", out_data[0]);
}

if (usb_kbhit(1))
{

usb_get_packet(1, in_data, 64);

lcd_putc("\f");i=0;
for(;i<32;i++)
{
if(i==15) lcd_putc("\n");
c=in_data[i];
lcd_putc(c);
}
//printf("\r\n--> Received data: %s",in_data);
}
send_timer--;
delay_ms(1);
}
}
}
////////////////////////////////////////////////////////////////////////
#include <18F4550.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES EC_IO //External clock
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOMCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL3 // PLL PreScaler 3
#FUSES USBDIV
#FUSES VREGEN
#FUSES CPUDIV1
#FUSES HS



#DEFINE USB_HID_DEVICE FALSE
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 64 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 64 //size to allocate for the rx endpoint 1 buffer
#use delay(clock=12000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
void setup()
{
setup_adc_ports(AN0|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_low_volt_detect(FALSE);
setup_oscillator(False);
}
somali123 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ðiều Chỉnh
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 05:18 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam