CH375 HOST串口在19200波特率時就不穩(wěn)定呀,通信時數(shù)據(jù)丟失或錯誤。 ch375 晶振12M,8051晶振11.0592M。 設(shè)置為9600時沒有問題,但為了速度要求,設(shè)置為19200時就不對了。初始化都完成不了,什么意思?
程序如下:
MAIN: NOP MOV TCON,#00H MOV SP,#0CFH MOV IE,#098H INIT_COM: MOV SCON,#0D0H ;串口方式1工作,8位數(shù)據(jù)位,1位停止位,有奇偶校驗 ORL PCON,#080H ;SMOD=1,波特率增倍 ORL TMOD,#020H ;波特率設(shè)置,fOSC=11.0592MHz,波特率=9600,N=0FDH MOV TH1,#0FAH ;先用CH375的默認(rèn)波特率進(jìn)行工作 MOV TL1,#0FAH SETB TR1 ;啟動定時器T1
MOV DATAIN_OUT,#CMD_SET_BAUDRATE CALL WRITEADDRESS NOP MOV DATAIN_OUT,#002H ;寫入分頻系數(shù) CALL WRITEDATA MOV DATAIN_OUT,#0D9H ;寫入分頻常數(shù) CALL WRITEDATA NOP CLR TR1 MOV TH1,#0FDH ;更改CH375的波特率 MOV TL1,#0FDH SETB TR1 CALL DELAY2 CH375_BAUD_WT: CALL READDATA ;返回操作狀態(tài) MOV A,DATAIN_OUT XRL A,#CMD_RET_SUCCESS JNZ CH375_BAUD_WT ;等待操作成功,通常需要等待10uS-20uS
CALL CH375_INIT
。。。。。。。
;********初始化子程序**********
CH375_INIT: MOV DATAIN_OUT,#CMD_RESET_ALL CALL WRITEADDRESS CALL DELAY3 ;測試CH375是否正常工作,可選操作 MOV DATAIN_OUT,#CMD_CHECK_EXIST CALL WRITEADDRESS MOV DATAIN_OUT,#055H ;寫入測試數(shù)據(jù) CALL WRITEDATA MOV A,DATAIN_OUT CPL A MOV R0,A ;取反數(shù)據(jù) CALL READDATA MOV A,DATAIN_OUT ;返回數(shù)據(jù)應(yīng)該是測試數(shù)據(jù)取反 XRL A,R0 JZ CH375_INIT_OK ;測試通過 MOV DATAIN_OUT,#CMD_RESET_ALL MOV R1,#050H ;多次重復(fù)發(fā)命令 CH375_INIT_HR: CALL WRITEADDRESS DJNZ R1,CH375_INIT_HR MOV R1,#0A0H ;160*256uS=40mS CH375_INIT_D2: CLR A CH375_INIT_D1: DJNZ ACC,CH375_INIT_D1 ;延時1uS DJNZ R1,CH375_INIT_D2 ;延時256uS SJMP CH375_INIT ;再次測試 CH375_INIT_OK: ;設(shè)置外部自定義的USB設(shè)備VID和PID,可選操作,不執(zhí)行該命令則使用默認(rèn)的VID和PID MOV DATAIN_OUT,#CMD_SET_USB_ID CALL WRITEADDRESS MOV DATAIN_OUT,#USB_VENDOR_ID_L CALL WRITEDATA MOV DATAIN_OUT,#USB_VENDOR_ID_H CALL WRITEDATA MOV DATAIN_OUT,#USB_PRODUCT_ID_L CALL WRITEDATA MOV DATAIN_OUT,#USB_PRODUCT_ID_H CALL WRITEDATA MOV DATAIN_OUT,#CMD_SET_USB_MODE CALL WRITEADDRESS MOV DATAIN_OUT,#06H ;設(shè)置為使用外部固件的USB設(shè)備方式 CALL WRITEDATA NOP NOP CH375_INIT_WT: CALL READDATA ;返回操作狀態(tài) MOV A,DATAIN_OUT XRL A,#CMD_RET_SUCCESS JNZ CH375_INIT_WT ;等待操作成功,通常需要等待10uS-20uS RET RET
;*********寫指令子程序*********
WRITEADDRESS: SETB TB8 MOV SBUF,DATAIN_OUT JNB TI,$ CLR TI RET
;*********寫數(shù)據(jù)子程序*********
WRITEDATA: CLR TB8 MOV SBUF,DATAIN_OUT JNB TI,$ CLR TI RET
;*********讀數(shù)據(jù)子程序*********
READDATA: JNB RI,$ MOV DATAIN_OUT,SBUF CLR RI RET
[Emot]27[/Emot][Emot]27[/Emot][Emot]27[/Emot][Emot]27[/Emot][Emot]27[/Emot]