我用的pic16f876直接接的ch372。插上后沒反應(yīng)。我是第一次用pic單片機編程。麻煩幫我看看我的程序。這是程序的一部分。謝謝了。 W_TEMP EQU 20H ST_TEMP EQU 21H TX_IN EQU 22H tx_len EQU 23H TX_CNT EQU 24H INT_TEMP EQU 25H COUNT EQU 220 COUNT_1 EQU 1 COUNT1 EQU 27H COUNT2 EQU 28H W_BUF EQU 29H COUNT_2 EQU 80 count_3 equ 6

CMD_RESET_ALL EQU 05H ;執(zhí)行硬件復(fù)位 CMD_CHECK_EXIST EQU 06H ;測試工作狀態(tài) CMD_SET_USB_ADDR EQU 13H ;設(shè)置USB地址 CMD_SET_USB_MODE EQU 15H ;設(shè)置USB工作模式 CMD_SET_ENDP2 EQU 18H ;設(shè)備方式: 設(shè)置USB端點0的接收器 CMD_SET_ENDP3 EQU 19H ;設(shè)備方式: 設(shè)置USB端點0的發(fā)送器 CMD_SET_ENDP4 EQU 1AH ;設(shè)備方式: 設(shè)置USB端點1的接收器

CMD_GET_STATUS EQU 22H ;獲取中斷狀態(tài)并取消中斷請求 CMD_UNLOCK_USB EQU 23H ;設(shè)備方式: 釋放當(dāng)前USB緩沖區(qū) CMD_RD_USB_DAT EQU 28H ;從當(dāng)前USB中斷的端點緩沖區(qū)讀取數(shù)據(jù)塊, 并釋放緩沖區(qū) CMD_WR_USB_DATA3 EQU 29H ;設(shè)備方式: 向USB端點0的發(fā)送緩沖區(qū)寫入數(shù)據(jù)塊 CMD_WR_USB_DATA5 EQU 2AH ;設(shè)備方式: 向USB端點1的發(fā)送緩沖區(qū)寫入數(shù)據(jù)塊 CMD_WR_USB_DATA7 EQU 2BH ;向USB端點2的發(fā)送緩沖區(qū)寫入數(shù)據(jù)塊

usb_int_ep1_in equ 09h usb_int_ep1_out equ 01h usb_int_ep2_out equ 02h usb_int_ep2_in equ 0ah

SEND_LEN EQU 8H ;準(zhǔn)備下次發(fā)送的數(shù)據(jù)長度

TX_FIFO EQU 0A0H TX_1 EQU 0A1H TX_2 EQU 0A2H TX_3 EQU 0A3H TX_4 EQU 0A4H TX_5 EQU 0A5H TX_6 EQU 0A6H TX_7 EQU 0A7H TX_8 EQU 0A8H TX_9 EQU 0A9H TX_10 EQU 0AAH TX_11 EQU 0ABH TX_12 EQU 0ACH TX_13 EQU 0ADH TX_14 EQU 0AEH TX_15 EQU 0AFH

org 00h call start ;org 04h ;call usb_int

start: call initial mainloop: bcf status,5 btfsc portc,4 goto mainloop call usb_int initial: call delay_40ms call delay_40ms call delay_40ms call delay_40ms call delay_40ms call delay_40ms call delay_40ms bcf intcon,7 bsf status,5 ; movlw 02h ; movwf pcon movlw 11010011b movwf trisc movlw tx_2 movwf tx_fifo bcf status,5 movwf st_temp call ch372_wr_cmd movlw cmd_check_exist movwf portb call delay_2us call ch372_wr_dat movlw 55h movwf portb call delay_2us call ch372_re_dat movf portb,0 andlw 55h btfss status,z goto initial call usb_reset call usb_mode

return usb_reset: call ch372_wr_cmd movlw cmd_reset_all movwf portb call delay_40ms call delay_40ms call delay_40ms return

ch372_wr_cmd: bsf status,5 movlw 00h movwf trisb bcf status,5 call delay_2us bcf portc,2 bsf portc,5 bsf portc,3 nop nop return ch372_wr_dat: bsf status,5 movlw 00h movwf trisb bcf status,5 bcf portc,5 bsf portc,3 bcf portc,2 nop nop return ch372_re_dat: bsf status,5 movlw 0ffh movwf trisb bcf status,5 bsf portc,2 bcf portc,3 bcf portc,5 nop nop return ch372_re_int: bsf status,5 movlw 0ffh movwf trisb bcf status,5 bsf portc,2 bcf portc,3 bsf portc,5 nop nop return delay_2us: MOVLW COUNT_1 MOVWF COUNT1 MOVLW COUNT_3 MOVWF COUNT2

LOOP: DECFSZ COUNT2,1 GOTO LOOP DECFSZ COUNT1,1 GOTO LOOP RETURN

delay_40ms: MOVLW COUNT MOVWF COUNT1 CLRF COUNT2

LOOP2: DECFSZ COUNT2,1 GOTO LOOP2 DECFSZ COUNT1,1 GOTO LOOP2 RETURN DELAY_20us: MOVLW COUNT_1 MOVWF COUNT1 MOVLW COUNT_2 MOVWF COUNT2

LOOP1: DECFSZ COUNT2,1 GOTO LOOP1 DECFSZ COUNT1,1 GOTO LOOP1

RETURN usb_mode: call ch372_wr_cmd movlw cmd_set_usb_mode movwf portb call delay_2us call ch372_wr_dat movlw 02h movwf portb call delay_20us call ch372_re_dat bcf status,5 movlw 51h subwf portb,0

btfss status,z goto usb_mode return


熱門產(chǎn)品 : USB3.0 HUB控制器:CH634