下面是改寫的匯編,前面的測試可以通過.但是程序不能進入MA02: SETB RED,而且CH372的INT#引腳一直為高電平,
;用CH372操作HID設(shè)備,比如鍵盤,鼠標 ;89C51,11.0592MHz晶振,CH372 CMD1 EQU 0BDF1H ;寫命令口 CMD2 EQU 0BDF0H ;寫數(shù)據(jù)口 RED EQU P1.7 ;紅色指示燈 GED EQU P1.6 ;綠色指示燈 ENDP6 EQU 30H ENDP7 EQU 31H ORG 00H MAIN0: MOV P1,#0FFH MOV P2,#0FFH MOV R7,#05H ;執(zhí)行硬件復位 ACALL CH372_WR_CMD_PORT ACALL DELAY40ms CPL GED ;執(zhí)行硬件復位完綠燈指示 MOV R7,#06H ;測試工作狀態(tài) ACALL CH372_WR_CMD_PORT MOV R7,#55H ACALL CH372_WR_DATA_PORT ACALL CH372_RD_DATA_PORT CJNE A,#0AAH,MAIN0 CLR RED ;測試成功紅綠指示 MOV R7,#06H ACALL set_usb_mode ;設(shè)置USB主機模式, 如果設(shè)備端是CH37X, 那么5和6均可 CJNE R7,#01H,MAIN0 ;操作不成功返回MAIN0 ACALL set_freq_void ;使375B進入低速模式
MA01: JNB P3.2,MA02 ; ACALL CH372_RD_DATA_PORT ; MOV A,R7 AJMP MA01 MA02: SETB RED ; AJMP $ set_usb_mode: MOV R6,07H MOV R7,#15H ;模式代碼 ACALL CH372_WR_CMD_PORT_mod MOV R7,06H MOV ENDP7,#80H MOV ENDP6,#80H CLR A MOV R6,A set_usb_mode1: ACALL CH372_RD_DATA_PORT CJNE R7,#51H,set_usb_mode2 ;判斷操作成功沒有 MOV R7,#01H RET set_usb_mode2: INC R6 CJNE R6,#64H,set_usb_mode1 ;讀100次 MOV R7,#00H RET CH372_WR_CMD_PORT_mod: ; ACALL CH372_WR_CMD_PORT MOV R7,06H CH372_WR_DATA_PORT: ;向CH372寫入數(shù)據(jù) MOV DPTR,#CMD2 MOV A,R7 MOVX @DPTR,A RET CH372_WR_CMD_PORT: ;向CH372寫命令 MOV DPTR,#CMD1 MOV A,R7 MOVX @DPTR,A RET CH372_RD_DATA_PORT: ;讀CH372的數(shù)據(jù) MOV DPTR,#CMD2 MOVX A,@DPTR MOV R7,A RET set_freq_void: ;切換使372進入低速模式 MOV R7,#0BH ACALL CH372_WR_CMD_PORT MOV R7,#17H ACALL CH372_WR_DATA_PORT MOV R7,#0D8H ACALL CH372_WR_DATA_PORT RET DELAY40ms: MOV R7,#28H DELAY40ms1: ACALL DELAY_MS DJNZ R7,DELAY40MS1 RET DELAY_MS: MOV A,#0E6H DELAY_1MS: NOP NOP DJNZ ACC,DELAY_1MS ;每周期延時1毫秒 RET END