我用51單片機與ch374通過并口通訊時,借用其它口線模擬讀寫時序,可讀寫的數(shù)據(jù)很不穩(wěn)定,時對時錯,代碼如下: /* 向索引端口寫入索引地址 ,a為8位地址 */ void Write374Index(UINT8 addr) { WR = 1; RD = 1; CH374A0 = CH374Addr; P0 = addr; for(addr=0;addr<3;addr++); WR = 0; for(addr=0;addr<3;addr++); WR = 1; _nop_(); } /* 向數(shù)據(jù)端口寫入數(shù)據(jù),索引地址自動加1 */ void Write374Data(UINT8 d) { WR = 1; RD = 1; CH374A0 = CH374Data; P0 = d; for(d=0;d<3;d++); WR = 0; for(d=0;d<3;d++); WR = 1; _nop_(); }
/* 從數(shù)據(jù)端口讀出數(shù)據(jù),索引地址自動加1 */ UINT8 Read374Data(void) /* 從CH374讀數(shù)據(jù) */ { UINT8 Value ; WR = 1; RD = 1; CH374A0 = CH374Data; P0 = 0xFF; RD = 0; for(Value = 0;Value<3;Value++); Value = P0; RD = 1; return Value; } 其中數(shù)據(jù)建立時間都用了for(Value = 0;Value<3;Value++);這么長還是有問題,請高手指點;