请问hcn: 不知能否给个参考程序? 尤其是关于测试CH375部分的。 希望百忙中给予帮助。 谢谢! 急!
你所说的测试375是CHECK—EXIST命令吗??
我把我的测试CH375部分的程序贴出来,望大家帮忙看一下,希望能提出问题。 谢谢! 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; /* 数据 */ 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; /* 数据 */ 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 ); /* 写入测试数据 */ i = ~ 0x55; /* 返回数据应该是测试数据取反 */ RD_Data=CH375_RD_DAT_PORT(); if ( RD_Data!= i ) { /* CH375不正常 */ for ( i=80; i!=0; i-- ) { CH375_WR_CMD_PORT( CMD_RESET_ALL ); /* 多次重复发命令,执行硬件复位 */ CH375_RD_DAT_PORT( ); } CH375_WR_CMD_PORT( 0 ); delay50ms( ); /* 延时50ms */ } } if( k==0 ) { while(1) { flash_led(); /* CH375出错;发光二极管以100ms的间隔闪烁10次 */ return; } } }
是CMD_CHECK_EXIST命令啊
是CMD_CHECK_EXIST命令啊
你你定义的A0是不是CH375_CMD_PORT?,你的读和写函数好象有点问题,你是采用的模拟口方式还是总线方式?
#define CH375_DATA_PORT P0 /* CH375端口的I/O地址 */ sbit CH375_CMD_DAT = P2^2; /* CH375地址线输入A0,A0=1时写命令,A0=0时读写数据 */ 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#引脚,用于查询中断状态 */
我定义的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; /* 数据 */ 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; /* 数据 */ 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呢??
好遗憾啊 仍然通不过 :(
我的片选在主程序里头给了 永远置0了
给了命令CMD_CHECK_EXIST,输入一个数后,输出并没有反向,还是原来那个数。 有的情况下,输出变成了0xFF。 很费解啊! ?? :(
你看下你测试时候返回的数据是多少,如果测试数据不是你写进去数据去反的话,那就是你硬件有问题,通过你的描述,那就是你硬件有问题
hcn大哥还在么?