如题:在测试ch372是否正常工作时,读出来的数据和写进去的数值是一样的,比如写0x55,读出来的也是0x55;写进去0xaa,读出来的也是0xaa;计算机也可以识别ch372,单片机端口和ch372经测试连接也是好的,真的不知道是什么原因?有人可以帮忙吗?谢谢了,将程序附上: #define CH372_A0_H PORTC|=(1<<1) #define CH372_A0_L PORTC&=~(1<<1) #define CH372_CS_H PORTC|=(1<<3) #define CH372_CS_L PORTC&=~(1<<3) #define CH372_INT_H PORTC|=(1<<0) #define CH372_INT_L PORTC&=~(1<<0) #define CH372_WR_H PORTG|=(1<<0) #define CH372_WR_L PORTG&=~(1<<0) #define CH372_RD_H PORTG|=(1<<1) #define CH372_RD_L PORTG&=~(1<<1) void CH372_PORT_INT() { DDRC|=(1<<1)|(1<<3);//A0,CS设置为输出方向 DDRG|=(1<<0)|(1<<1);//WR,RD设置为输出方向 CH372_CS_L; CH372_WR_H; CH372_RD_H ; CH372_A0_L; DDRA=0x00; PORTA=0xff; } void writech372cmd(unsigned char cmd) { ch372_delay_us();ch372_delay_us(); DDRA = 0xFF; PORTA=cmd; CH372_A0_H; CH372_CS_L;CH372_WR_L; CH372_CS_L;CH372_WR_H; CH372_CS_H; CH372_A0_L; DDRA=0x00; ch372_delay_us();ch372_delay_us(); } void writech372data(unsigned char data) { ch372_delay_us();ch372_delay_us(); DDRA = 0xFF; PORTA=data; CH372_A0_L;CH372_CS_L;CH372_WR_L; CH372_CS_L; CH372_WR_H ; CH372_CS_H; CH372_A0_H; DDRA=0x00; ch372_delay_us();ch372_delay_us(); } unsigned char readch372data(void) { unsigned char data; ch372_delay_us();ch372_delay_us(); DDRA=0x00; CH372_A0_L; CH372_CS_L; CH372_RD_L; CH372_WR_H ; CH372_CS_L; data=PORTA; CH372_RD_H;CH372_CS_H;CH372_A0_H; ch372_delay_us();ch372_delay_us(); return (data); }
void main() { unsigned char i; CH372_PORT_INT(); led_DDR; led_off; /*--------------------测试CH375是否正常工作,可选操作,通常不需要----------- */
writech372cmd(CMD_CHECK_EXIST); //测试CH372/CH375是否正常工作 writech372data(0x55); //写入测试数据 i = ~ 0xaa; //返回数据应该是测试数据取反,即0xaa if (readch372data()!=0x55) // CH372/CH375不正常 { led_on; for ( i=80; i!=0; i-- ) { writech372cmd(CMD_RESET_ALL);//多次重复发命令,执行硬件复位 readch372data(); } writech372cmd(0); delay_nms(50); }
/*------------------------设置USB工作模式, 必要操作----------------------*/
writech372cmd(CMD_SET_USB_MODE);// 设置USB工作模式 writech372data(2); // 设置为使用内置固件的USB设备方式 for ( i=100; i!=0; i-- ) // 等待操作成功,通常需要等待10uS-20uS { if(readch372data()==CMD_RET_SUCCESS) break; } while(1); }