导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→C51编程:急切求助93C46的读写!!!!

* 12131: C51编程:急切求助93C46的读写!!!!

   tiger420 
tiger420发表的帖子 

 C51编程:急切求助93C46的读写!!!!
有谁用过AT93C46啊,我的程序为什么总不能正确读写。请各位大虾指点小弟。万分感激。
我的邮件tiger420@163.com
(我的读写函数如下)
// Write enable must precede all programming modes.
void Ewen(void) {
    unsigned char temp,InData;
    CS=0;    
    SK=0;
    CS=1;
    InData=0x98;    // 10011XXXX
    for(temp=9;temp!=0;temp--) {    // 9
        DI=InData&0x80;
        SK=1;    SK=0;
        InData<<=1;
    }
    CS=0;
}

// Disables all programming instructions.
void Ewds(void) {
    unsigned char temp,InData;
    CS=0;
    SK=0;
    CS=1;
    InData=0x80;    // 10000XXXX
    for(temp=9;temp!=0;temp--) {    // 9
        DI=InData&0x80;
        SK=1;    SK=0;
        InData<<=1;
    }
    CS=0;
}

// Reads data stored in memory, at specified address.
unsigned int Read_data(unsigned char address) {
    unsigned char temp;
    unsigned int result;
    Ewen();
    SK=0;    DI=1;    // 110 A5-A0
    CS=0;    CS=1;
    SK=1;    SK=0;            // 
    address=address&0x3f|0x80;
    for(temp=8;temp!=0;temp--) {    // 8
        DI=address&0x80;
        SK=1;    SK=0;
        address<<=1;
    }
    DO=1;
    for(temp=16;temp!=0;temp--) {    // 16
        SK=1;
        result=(result<<1)|DO;
        SK=0;
    }
    CS=0;
    Ewds();
    return(result);
}

// Write_datas memory location An - A0.
void Write_data(unsigned char address,unsigned int InData) {
    unsigned char temp;
    Ewen();
    SK=0;    DI=1;    // 101 A5-A0
    CS=0;    CS=1;
    SK=1;    SK=0;            // 1
    address=address&0x3f|0x40;
    for(temp=8;temp!=0;temp--) {    // 8
        DI=address&0x80;
        SK=1;    SK=0;
        address<<=1;
    }
    for(temp=16;temp!=0;temp--) {    // 16
        DI=InData&0x8000;
        SK=1;    SK=0;
        InData<<=1;
    }
    CS=0;    DO=1;
    CS=1;    SK=1;
    while(DO==0) {            // busy test
        SK=0;    SK=1;
    }
    SK=0;    CS=0;
    Ewds();
}

unsigned char ReadChar(unsigned char address) {
    unsigned char temp=address>>1;
    if(address&0x01) return((unsigned char)(Read_data(temp)>>8));
    else return((unsigned char)(Read_data(temp)));
}

void WriteChar(unsigned char address,unsigned char InData) {
    unsigned char temp=address>>1;
    if(address&0x01) Write_data(temp,(unsigned int)(Read_data(temp)
&0x00ff|(InData<<8)));
    else Write_data(temp,(unsigned int)(Read_data(temp)&0xff00|InData));
}

发表时间:2002年10月10日17:40:00

  
回复该帖

本主题共有 7 帖,分页:>>>>>该主题的所有内容[7]条

 *树形目录 只列出部分跟帖的标题以及简单的摘要信息 该主题的部分跟帖如下:

  12146.[详细]建议
摘要:DI=address&0x80; result=(result<<1)|DO; 是否定义有问题?DI、DO是位变量,表达式为unsigned char,改为: if(address......(199字)
- [pan-x][1098次] 2002年10月10日

  12181.[详细]你的程序没问题,我已试过,查查你的硬件 
摘要:......(无内容)
- [lingl2][1030次] 2002年10月11日

  12268.[详细]我的操作
摘要:我原本的程序:         XBYTE[0x304c]=0x25;     //port&nbs......(2594字)
- [tiger420][782次] 2002年10月13日

[上一篇帖子]:C51编程:ht1621我写的ht1621程序信号不能锁从。点亮后随即熄灭。谁帮帮我!! 
[下一篇帖子]:用一个1:1变压器