中科因仑“3+1”工程特种兵精英论坛
标题:
51单片机读DM9000c的ID
[打印本页]
作者:
因为思念谁
时间:
2016-5-28 21:55
标题:
51单片机读DM9000c的ID
我在网上买了个DM9000c的网络通信模块,老板给了读ID的程序,可我用这个程序读不到ID,不知道是怎么回事?
代码如下:
#include<reg51.h>
sbit nRSET = P3^0;
sbit CS = P2^1;
sbit IOW = P2^2;
sbit IOR = P2^3;
sbit CMD = P2^4;
sbit LED = P2^0;
void mdelay (int m)
{
int i;
for (;m > 0; m--)
for (i = 0; i < 100; i++);
}
void dm9000_write (unsigned char reg, unsigned char date)
{
P1 = reg;
CS = 0;
CMD = 0;
IOR = 1;
IOW = 0;
mdelay(1);
CS = 1;
IOW = 1;
mdelay(2);
P1 = date;
CS = 0;
CMD = 0;
IOR = 1;
IOW = 0;
mdelay(1);
CS = 1;
IOW = 1;
}
static unsigned char dm9000_read (unsigned char reg)
{
unsigned char date = 0;
P1 = reg;
CS = 0;
CMD = 0;
IOR = 1;
IOW = 0;
CS = 1;
IOW = 1;
P1 = 0xFF;
CS = 0;
CMD = 1;
IOW = 1;
IOR = 0;
date = P1;
P1 = date;
CS = 1;
IOR = 1;
return date;
}
void main (void)
{
unsigned int date = 0;
LED = 0;
nRSET = 0;
mdelay(5000);
nRSET = 1;
mdelay(5000);
nRSET = 0;
mdelay(5000);
nRSET = 1;
mdelay(5000);
LED = 1;
mdelay(5000);
date = dm9000_read (0x28);
if (date == 0x46)
date = dm9000_read (0x29);
else
while(1);
if (date == 0x0A)
date = dm9000_read (0x2A);
else
while(1);
if (date == 0x00)
date = dm9000_read (0x2B);
else
while (1);
if (date == 0x90)
CMD = ~CMD;
else
while (1);
}
欢迎光临 中科因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/)
Powered by Discuz! X3.4