374 通用I/O模拟并口时续

发表于:2008-1-31 20:15:00,来源于:222.69.62.162 发贴心情: ----------------------------------------------------------------------------------------------------- 偶用374模拟并口方式和计算机通信,芯片用DSPIC的现在程序遇到点麻烦,读写时序冲突,当WR为低时,RD也有低电平,打电话后按你们的方式做还是有读写冲突,而且和网上帖子给我的关于时序的处理方法的 建议(hcn给的)有出入,特把程序贴出来,望帮忙看看:: D端口有12个引脚,低8位数据连374并口,高4位连信号线! #define CH374_DATA_DAT_OUT(d) (LATD=(LATD&&0XFF00)+d)//数据输出 #define CH374_DATA_DAT_IN() (LATD&&0X00FF)//数据输出 #define CH374_DATA_DIR_OUT() (TRISD&=0X0000)//设置口为输出 #define CH374_DATA_DIR_IN() (TRISD|=0X00FF)//设置口为输入 [ 1] WRITE374indeX( UINT8mindex) { //DSP复位后引脚能输出高电平 CH374_RD=1; CH374_DATA_DIR_OUT(); CH374_DATA_DAT_OUT(d); ch374_A0=1; CH374_CS=0; CH374_WR=0; mDelayus(1);//125ns CH374_WR=1; CH374_CS=0; CH374_DATA_DIR_IN(); ch374_A0=0; } //=========================================================================== [2] WRITE374DATA( UINT8 mdata) { CH374_RD=1; CH374_DATA_DIR_OUT();//设置为输出 CH374_DATA_DAT_OUT(d);//输出数据 ch374_A0=0; CH374_CS=0; CH374_WR=0; mDelayus(1);//125ns CH374_WR=1; CH374_CS=0; CH374_DATA_DIR_IN(); //ch374_A0=1; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ [3] READ374DATA(VOID) { UINT8 mDATA; //CH374_WR=1; CH374_DATA_DIR_IN(); CH374_A0=0; CH374_CS=0; CH374_RD=0; mDelayus(1);//125ns mDATA=CH374_DATA_DAT_IN(); CH374_RD=1; CH374_CS=1; } 这是按照你们的提示做的,示波器上WR/RD信号有冲突,374的指示灯亮,PC没有发现未知硬件提示!没有用4通道测CS/A0????? 谢谢---------------------! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 你的程序应该这样写: [ 1] WRITE374indeX( UINT8mindex) { //DSP复位后引脚能输出高电平 CH374_RD=1; CH374_DATA_DIR_OUT(); CH374_DATA_DAT_OUT(d); ch374_A0=1; CH374_CS=0; CH374_WR=0; mDelayus(1);//125ns CH374_WR=1; CH374_CS=1; // CH374_DATA_DIR_IN(); ch374_A0=0; } //=========================================================================== [2] WRITE374DATA( UINT8 mdata) { CH374_RD=1; CH374_DATA_DIR_OUT();//设置为输出 CH374_DATA_DAT_OUT(d);//输出数据 ch374_A0=0; CH374_CS=0; CH374_WR=0; mDelayus(1);//125ns CH374_WR=1; CH374_CS=1; // CH374_DATA_DIR_IN(); //ch374_A0=1; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ [3] READ374DATA(VOID) { UINT8 mDATA; //CH374_WR=1; CH374_DATA_DIR_IN(); CH374_A0=0; CH374_CS=0; CH374_RD=0; mDelayus(1);//125ns mDATA=CH374_DATA_DAT_IN(); CH374_RD=1; CH374_CS=1; } ------------------------------------------- __________________________________________ 按你们说的方法还是出现读写冲突,还有别的原因吗? 比如软件复位,以及其他?

按照你上面说的,你的D口的高4位为控制位,这样的话,你这样看下,在你将RD或者WR拉低之后,你看下别的信号线是否有冲突,因为这个不是我们时序的问题,可能是你I/O端口会不会出现冲突之类的。


关于8位数据口这几个宏定义有问题 #define CH374_DATA_DAT_OUT(d) (LATD=(LATD&&0XFF00)+d)//数据输出 应改为 #define CH374_DATA_DAT_OUT(d) (LATD = (LATD & 0XFF00) + d)//数据输出

#define CH374_DATA_DAT_IN() (LATD&&0X00FF)//数据输出 应改为 #define CH374_DATA_DAT_IN() (LATD & 0X00FF)//数据输出

你的CS A0 WR RD不知道是怎么配置的?


&&: 逻辑与 &: 位运算与 我搞错了~~~~~~~~~ 读写冲突问题解决! CS A0 WR RD分别通过D端口引脚 发送高低电平! 但是现在计算机还是只能提示"无法识别的USB设备",并且和374 ACK,引脚相连的指示灯不亮,能产生中断,想在程序中读取寄存器的值,读不到! 该怎么办,有什么方法!


只有登录才能回复,可以选择微信账号登录