51卡在忙信号检测

2020-02-01 16:17发布

void enc28j60PhyWrite(unsigned char address, unsigned short mydat)
{
    enc28j60Write(MIREGADR, address);
    enc28j60Write(MIWRL, mydat & 0x00ff);
    enc28j60Write(MIWRH, mydat >> 8);
        Delay_ms(40);
        Delay_ms(40);
        Delay_ms(40);
        Delay_ms(40);
       
    while(enc28j60Read(MISTAT) & MISTAT_BUSY){
                        Delay_ms(40);
                        SBUF = enc28j60Read(MISTAT); //卡在这里,返回0xF5
                }
       
}

我的其他函数

unsigned char enc28j60Read(unsigned char address)
{
       
    enc28j60SetBank(address);
    return enc28j60ReadOp(ENC28J60_READ_CTRL_REG, address);
       
}

unsigned char enc28j60ReadOp(unsigned char op, unsigned char address)
{
    unsigned char v_data;
    CS = 0;
    WriteByte(op | (address & ADDR_MASK));
    v_data = ReadByte();
    if(address & 0x80)         v_data = ReadByte();
    CS = 1;
    return(v_data);
}

void enc28j60SetBank(unsigned char address)
{
    if((address & BANK_MASK) != Enc28j60Bank)
    {
        enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, (ECON1_BSEL1 | ECON1_BSEL0));
        enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, (address & BANK_MASK) >> 5);
        Enc28j60Bank = (address & BANK_MASK);
    }
}

大写的常量一定对照手册了,奇怪.
0条回答

一周热门 更多>