如題:在測(cè)試ch372是否正常工作時(shí),讀出來的數(shù)據(jù)和寫進(jìn)去的數(shù)值是一樣的,比如寫0x55,讀出來的也是0x55;寫進(jìn)去0xaa,讀出來的也是0xaa;計(jì)算機(jī)也可以識(shí)別ch372,單片機(jī)端口和ch372經(jīng)測(cè)試連接也是好的,真的不知道是什么原因?有人可以幫忙嗎?謝謝了,將程序附上: #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設(shè)置為輸出方向 DDRG|=(1<<0)|(1<<1);//WR,RD設(shè)置為輸出方向 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; /*--------------------測(cè)試CH375是否正常工作,可選操作,通常不需要----------- */
writech372cmd(CMD_CHECK_EXIST); //測(cè)試CH372/CH375是否正常工作 writech372data(0x55); //寫入測(cè)試數(shù)據(jù) i = ~ 0xaa; //返回?cái)?shù)據(jù)應(yīng)該是測(cè)試數(shù)據(jù)取反,即0xaa if (readch372data()!=0x55) // CH372/CH375不正常 { led_on; for ( i=80; i!=0; i-- ) { writech372cmd(CMD_RESET_ALL);//多次重復(fù)發(fā)命令,執(zhí)行硬件復(fù)位 readch372data(); } writech372cmd(0); delay_nms(50); }
/*------------------------設(shè)置USB工作模式, 必要操作----------------------*/
writech372cmd(CMD_SET_USB_MODE);// 設(shè)置USB工作模式 writech372data(2); // 設(shè)置為使用內(nèi)置固件的USB設(shè)備方式 for ( i=100; i!=0; i-- ) // 等待操作成功,通常需要等待10uS-20uS { if(readch372data()==CMD_RET_SUCCESS) break; } while(1); }