at93c46.c

来自「存储器93C46的存储、读取及显示程序!」· C语言 代码 · 共 106 行

C
106
字号
#include"stdio.h"
#include"reg52.h"
#include"stdlib.h"
#include"intrins.h"
#include"absacc.h"
unsigned char code tab[]={0x09,0x02,0x55,0x04,0x44};
sbit cs=P2^0;
sbit csk=P2^1;
sbit so=P2^2;
sbit si=P2^3;
void start()
{
    cs=0;
    _nop_();
    csk=0;
    _nop_();
    cs=1;
}
void setcondition(unsigned char condition)
{
    unsigned char j;
    for(j=0;j<3;j++)
    {
        cs=1;
        csk=0;
        _nop_();
        si=condition&0x80;
        csk=1;
        condition<<=1;
    }
}
void busycheck()
{
    cs=0;
    _nop_();
    cs=1;
    while(!so) ;
}
void writeaddress(unsigned char address)
{
    unsigned char i;
    for(i=0;i<7;i++)
    {
        cs=1;
        address<<=1;
        csk=0;
        si=address&0x80;
        _nop_();
        csk=1;
        
    }
}
void writedata(unsigned char dat)
{
    unsigned char i;
    for(i=0;i<8;i++)
    {
        cs=1;
        _nop_();
        csk=0;
        si=dat&0x80;
        dat<<=1;
        csk=1;
    }
}
unsigned char readdata()
{
    unsigned char i,result;
    for(i=0;i<9;i++)
    {
        cs=1;
        result<<=1;
        csk=0;
        result|=so;
        csk=1;
    }
        return(result);
}
main()
{
    
    unsigned char a,m=0x00,k;
    start();//写使能
    setcondition(0x80);
    writeaddress(0xff);
    busycheck();
    for(k=0;k<5;k++)
    {
        start();//写数据
        setcondition(0xa0);
        writeaddress(m++);
        writedata(tab[k]);
        busycheck();
    }
    m=0x00;
    for(k=0;k<5;k++)
    {
        start();//读数据
        setcondition(0xc0);
        writeaddress(m++);
        a=readdata();
        busycheck();
    }
    
    _nop_();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?