SPI總線驅(qū)動(C語言源程序)
/*-----------------------------------------------------
SPI93c76與SPI93c86系列函數(shù)調(diào)用(舉例)
調(diào)用方式:bit write93c76_word(unsigned int address,unsigned int dat) ﹫2001/05/12
函數(shù)說明:私有函數(shù),SPI專用
-----------------------------------------------------
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);
}
/*-----------------------------------------------------
主函數(shù)調(diào)用(舉例)
調(diào)用方式:main() ﹫2001/05/12
函數(shù)說明:私有函數(shù),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語言相關(guān)文章:c語言教程
晶振相關(guān)文章:晶振原理
評論