刚开始调CH375B,测试时测了好几个数都是低位是取反的,高位是0,如0x77,读取后为0x08,麻烦解答下
程序如下:
#define USB_A0 LATG1
#define USB_CS LATG2
#define USB_RD LATG3
#define USB_WR LATG4
#define CMD_TEST_CONNECT 0x16
#define CMD_DISK_INIT 0x51
#define CMD_DISK_RESET 0x52
#define CMD_DISK_SIZE 0x53
#define CMD_DISK_READ 0x54
#define CMD_RESET_ALL 0x05
#define CMD_CHECK_EXIST 0x06
#define CMD_SET_USB_MODE 0x15
#define CMD_GET_STATUS 0x22
#define USB_INT_SUCCESS 0x14
#define USB_INT_CONNECT 0x15
void CH375_WR_CMD_PORT( unsigned char Index ) /* 写索引地址 */
{
delay_1us();
delay_2us();
LATH=Index;
USB_A0=1;
USB_CS=0;
//USB_RD =1;
USB_WR=0;
USB_CS=0; //无意义
USB_WR=1;
USB_CS=1;
USB_A0=0;
delay_2us();
delay_2us();
}
void CH375HM_DATA_WR( unsigned char Data ) /* 写数据 */
{
delay_2us();
delay_1us();
LATH=Data;
USB_A0=0;
USB_CS=0;
USB_WR=0;
USB_CS=0; //无意义
USB_WR=1;
USB_CS=1;
delay_1_2us();
delay_2us();
}
unsigned char CH375_RD_DAT_PORT( ) /* 读数据 */
{
unsigned char mData;
delay_2us();
delay_1_2us();
TRISH=0xff; //设置为输入读取数据
USB_A0=0;
USB_CS=0;
USB_RD=0;
USB_CS=0; //无意义
mData=PORTH;
USB_RD=1;
USB_CS=1;
TRISH=0x00; //设为输出
delay_2us();
delay_2us();
return mData;
}
void main() {
init_ccp3();
init_IO();
mDelay100mS( ); /* 延时100毫秒,CH375模块上电后需要100毫秒左右的复位时间 */
mDelay100mS( );
mDelay100mS( );
mDelay100mS( );
mDelay100mS( );
mDelay100mS( );
CH375HM_INT_EN=1; //开中断
//CH375_WR_CMD_PORT(0x51);
//CH375_WR_CMD_PORT(0x53);
temp=0xaa;
CH375_WR_CMD_PORT(CMD_CHECK_EXIST);
CH375HM_DATA_WR( 0x77 ) ;
tmp1=CH375_RD_DAT_PORT( );
delay_2us();
while(1)
{}
}