新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > SPI总线驱动(C语言源程序)

SPI总线驱动(C语言源程序)

作者: 时间:2013-01-07 来源:网络 收藏

/*-----------------------------------------------------
93c76与93c86系列函数调用(举例)
调用方式:bit write93c76_word(unsigned int address,unsigned int dat) ﹫2001/05/12
函数说明:私有函数,专用
-----------------------------------------------------
void ewen76(void)
{
_nop_();
cs_93=1;
dip7=1;
high46();
low46();
low46();
high46();
high46();
wd46(0xff);
cs_93=0;
}
unsigned int read93c76_word(unsigned int address)
{
unsigned char dat0,dat1;
gnd_93=0;
cs_93=sk_93=0;
org_93=1;
cs_93=1;
address>>=1;
high46();
high46();
low46();
if((address0x200)==0x200) high46();
else low46();
if ((address0x100)==0x100) high46();
else low46();
wd46(address);
dat1=rd46();
dat0=rd46();
cs_93=0;
return(dat1*256|dat0);
}
bit write93c76_word(unsigned int address,unsigned int dat)
{
unsigned char e;
unsigned int temp=address;
e=0;
address>>=1;
while (e3)
{
gnd_93=0;
cs_93=sk_93=0;
org_93=1;
cs_93=1;
ewen76();
_nop_();
cs_93=1;
high46();
low46();
high46();
if((address0x200)==0x200) high46();
else low46();
if ((address0x100)==0x100) high46();
else low46();
wd46(address);
wd46(dat/256);
wd46(dat%256);
cs_93=0;_nop_();cs_93=1;
time=0;do_93=1;
while (1)
{
if (do_93==1) break;
if (time>10) break;
}
cs_93=0;
e++;
}
return(1);
}
/*-----------------------------------------------------
主函数调用(举例)
调用方式:main() ﹫2001/05/12
函数说明:私有函数,SPI专用
-----------------------------------------------------*/
main()
{
bit b;
unsigned int i;
unsigned int j[32];
eral_46();
for(i=0;i32;i++)
j[i]=read93c46_word(i);
for(i=0;i32;i++)
write93c46_word(i,0x0910);
i=0;
b=write93c46_word(i,0x1213);
j[i]=read93c46_word(i);
i=1;
b=write93c46_word(i,0x1122);
j[i]=read93c46_word(i);
i=2;
b=write93c46_word(i,0x1344);
j[i]=read93c46_word(i);
i=3;
b=write93c46_word(i,0x1526);
j[i]=read93c46_word(i);
i=4;
b=write93c46_word(i,0xccde);
j[i]=read93c46_word(i);
P2_7=0;
}

c语言相关文章:c语言教程


晶振相关文章:晶振原理

上一页 1 2 3 下一页

关键词: SPI 总线驱动 C语言源

评论


相关推荐

技术专区

关闭