剛開始用CH375,單片機與CH375是串口連接,想用CMD_CHECK_EXIST 測試一下CH375是否正常工作,代碼節(jié)選如下: 當我在main函數(shù)下單步運行到RD_Data = xReadCH375Data()時,就執(zhí)行不下去了,停在那里,請問是不是意味著我的硬件連接有問題?還是有其它的可能? 謝謝~~
void CH375_PORT_INIT( ) { SCON = 0xD0; //設(shè)置串口為9位數(shù)據(jù) //設(shè)置波特率和其它串口參數(shù) }
void xWriteCH375Cmd( UINT8 mCmd ) { TI = 0; TB8 = 1; SBUF = mCmd; while ( TI == 0 ); }
void xWriteCH375Data( UINT8 mData ) { TI = 0; TB8 = 0; SBUF = mData; while ( TI == 0 ); }
UINT8 xReadCH375Data( void ) { while ( RI == 0 ); RI = 0; return( SBUF ); }
for( k=100; k!=0; k-- ) { xWriteCH375Cmd( CMD_CHECK_EXIST ); /* 測試CH375是否正常工作 */
l = 0x5A; xWriteCH375Data( l ); /* 寫入測試數(shù)據(jù) */ l = ~l; /* 返回數(shù)據(jù)應(yīng)該是測試數(shù)據(jù)取反 */ RD_Data = xReadCH375Data(); if ( RD_Data != l ) /* CH375不正常 */ { for ( l=5; l!=0; l-- ) { xWriteCH375Cmd( CMD_RESET_ALL ); /* 多次重復(fù)發(fā)命令,執(zhí)行硬件復(fù)位 */ } mDelay100mS( ); } else break; } if( k==0 ) { while(1) { aa=1; } }