請問hcn: 不知能否給個(gè)參考程序? 尤其是關(guān)于測試CH375部分的。 希望百忙中給予幫助。 謝謝! 急!
你所說的測試375是CHECK—EXIST命令嗎??
我把我的測試CH375部分的程序貼出來,望大家?guī)兔匆幌?,希望能提出問題。 謝謝! unsigned char CH375_WR_CMD_PORT(unsigned char cmd) { CH375_WR = 0; CH375_RD = 1; CH375_CMD_DAT = 1; _nop_(); _nop_(); CH375_DATA_PORT=cmd; _nop_(); _nop_(); CH375_WR = 0; }
void CH375_WR_DAT_PORT( unsigned char dat ) { _nop_(); CH375_WR=0; CH375_RD=1; CH375_CMD_DAT = 0; /* 數(shù)據(jù) */ CH375_DATA_PORT = dat; _nop_(); CH375_WR = 1; }
unsigned char CH375_RD_DAT_PORT(void) { unsigned char rev_data; CH375_DATA_PORT = 0xFF; CH375_WR = 0; CH375_RD = 1; CH375_CMD_DAT = 0; /* 數(shù)據(jù) */ CH375_WR = 1; CH375_RD = 0; rev_data = CH375_DATA_PORT; _nop_(); CH375_RD = 1; return( rev_data ); }
void CH375_Init( void ) { unsigned char i, k; unsigned char RD_Data; CH375_INT_WIRE = 1; CH375_WR = 1; CH375_RD = 1; CH375_CMD_DAT = 0;
/* 測試CH375是否正常工作 */ for( k=20; k!=0; k-- ) { CH375_WR_CMD_PORT( CMD_CHECK_EXIST ); /* 測試CH375是否正常工作 */ CH375_WR_DAT_PORT( 0x55 ); /* 寫入測試數(shù)據(jù) */ i = ~ 0x55; /* 返回?cái)?shù)據(jù)應(yīng)該是測試數(shù)據(jù)取反 */ RD_Data=CH375_RD_DAT_PORT(); if ( RD_Data!= i ) { /* CH375不正常 */ for ( i=80; i!=0; i-- ) { CH375_WR_CMD_PORT( CMD_RESET_ALL ); /* 多次重復(fù)發(fā)命令,執(zhí)行硬件復(fù)位 */ CH375_RD_DAT_PORT( ); } CH375_WR_CMD_PORT( 0 ); delay50ms( ); /* 延時(shí)50ms */ } } if( k==0 ) { while(1) { flash_led(); /* CH375出錯(cuò);發(fā)光二極管以100ms的間隔閃爍10次 */ return; } } }
是CMD_CHECK_EXIST命令啊
是CMD_CHECK_EXIST命令啊
你你定義的A0是不是CH375_CMD_PORT?,你的讀和寫函數(shù)好象有點(diǎn)問題,你是采用的模擬口方式還是總線方式?
#define CH375_DATA_PORT P0 /* CH375端口的I/O地址 */ sbit CH375_CMD_DAT = P2^2; /* CH375地址線輸入A0,A0=1時(shí)寫命令,A0=0時(shí)讀寫數(shù)據(jù) */ sbit CH375_RD = P3^7; /* CH375讀選通輸入,低電平有效 */ sbit CH375_WR = P3^6; /* CH375寫選通輸入,低電平有效 */ sbit CH375_CS = P2^3; /* CH375片選,低電平有效 */ sbit led = P2^5; /* 指示燈 */ sbit CH375_INT_WIRE = P3^2; /* CH375中斷請求輸出,低電平有效;P3.2, INT0, 連接CH375的INT#引腳,用于查詢中斷狀態(tài) */
我定義的AO是CH375_CMD_DAT 和51芯片的P2^2相連
unsigned char CH375_WR_CMD_PORT(unsigned char cmd) { CH375_DATA_PORT=cmd; CH375_CMD_DAT = 1; CH375_WR = 0; CH375_CS =0 CH375_RD = 1; _nop_(); _nop_(); CH375_CS =1 CH375_WR = 0; }
void CH375_WR_DAT_PORT( unsigned char dat ) { _nop_(); CH375_DATA_PORT = dat; CH375_CMD_DAT = 0; /* 數(shù)據(jù) */ CH375_WR=0; CH375_CS=0; CH375_RD=1; _nop_(); CH375_CS=1; CH375_WR = 1; }
unsigned char CH375_RD_DAT_PORT(void) { unsigned char rev_data; CH375_DATA_PORT = 0xFF; CH375_CMD_DAT = 0; /* 數(shù)據(jù) */ CH375_WR = 1; CH375_RD = 0; CH375_CS =0 rev_data = CH375_DATA_PORT; _nop_(); CH375_RD =1; CH375_CS =1 CH375_RD = 1; return( rev_data ); }
謝謝hcn 您真是熱心人 :)
你上面的程序都沒有片選你怎么操作375呢??
好遺憾啊 仍然通不過 :(
我的片選在主程序里頭給了 永遠(yuǎn)置0了
給了命令CMD_CHECK_EXIST,輸入一個(gè)數(shù)后,輸出并沒有反向,還是原來那個(gè)數(shù)。 有的情況下,輸出變成了0xFF。 很費(fèi)解??! ?? :(
你看下你測試時(shí)候返回的數(shù)據(jù)是多少,如果測試數(shù)據(jù)不是你寫進(jìn)去數(shù)據(jù)去反的話,那就是你硬件有問題,通過你的描述,那就是你硬件有問題
hcn大哥還在么?