使用CH375但始終無法通過測試命令,不知道怎么回事,麻煩大家給看一下,使用串口方式,電路按照手冊連接,單片機(jī)使用STC89C52,謝謝
main() { INT8U i; //手動復(fù)位 P0_2=0;mDelaymS(1); P0_2=1;mDelaymS(10000); P0_2=0;mDelaymS(1); CH375_PORT_INIT(); CH375_WR_CMD_PORT(CMD_CHECK_EXIST); CH375_WR_DAT_PORT(0x3F); i = CH375_RD_DAT_PORT(); if(i==0xc0){P0_0=0;}//指示燈 //else P0_1=0; while (1) {
}
}
void CH375_WR_CMD_PORT( unsigned char mCmd ) // 向CH375的命令端口寫入命令,周期不小于4uS,如果單片機(jī)較快則延時 { TI = 0; TB8 = 1; SBUF = mCmd; while ( TI == 0 );
}
void CH375_WR_DAT_PORT( unsigned char mData ) // 向CH375的數(shù)據(jù)端口寫入數(shù)據(jù),周期不小于1.5uS,如果單片機(jī)較快則延時 { TI = 0; TB8 = 0; SBUF = mData;
while ( TI == 0 ); }
unsigned char CH375_RD_DAT_PORT() // 從CH375的數(shù)據(jù)端口讀出數(shù)據(jù),周期不小于1.5uS,如果單片機(jī)較快則延時 { while ( RI == 0 ); RI = 0; return( SBUF ); }
void mDelaymS( unsigned char delay ) { unsigned char i, j, c; for ( i = delay; i != 0; i -- ) { for ( j = 200; j != 0; j -- ) c += 3; // 在24MHz時鐘下延時500uS for ( j = 200; j != 0; j -- ) c += 3; // 在24MHz時鐘下延時500uS } } // 如果單片機(jī)與CH375是串口連接,那么參考下面的子程序 void CH375_PORT_INIT() { mDelaymS(1); CH375_WR_CMD_PORT(CMD_SET_BAUDRATE); CH375_WR_DAT_PORT(0x02); CH375_WR_DAT_PORT(0xb2); mDelaymS(1); //while(xReadCH375Data()!=CMD_RET_SUCCESS); //printf("%02x\n",xReadCH375Data()); SCON = 0xD0; //設(shè)置串口為9位數(shù)據(jù) PCON = 0x80;// TMOD = 0x20; TH1 = 0xf3; //24MHz晶振, 9600bps TR1 = 1; TI = 1;//設(shè)置波特率和其它串口參數(shù) //CommSendString( UART0, "init finished\n" );
}