SPI總線驅(qū)動(C語言源程序)
/*--------------------
〖說明〗SPI總線驅(qū)動源程序 默認11.0592Mhz的晶振。
〖文件〗93CXX.C ﹫2003/5/12
---------------------*/
/*通用93c06-93c86系列使用說明
93c06=93c4693c56=93c6693c76=93c86*/
//dipx 可以自行定義
#i nclude AT89X52.H>
#i nclude "intrins.h"
/*-----------------------------------------------------
SPI93cXX系列時序函數(shù)調(diào)用(普通封裝)
調(diào)用方式:自行定義﹫2001/05/12
函數(shù)說明:私有函數(shù),封裝各接口定義
-----------------------------------------------------*/
/*#define di_93 dip3
#define sk_93 dip2
#define cs_93 dip1
#define do_93 dip4
#define gnd_93 dip5
#define org_93 dip6*/
sbit cs_93=0xA3;
sbit sk_93=0xA4;
sbit di_93=0xA5;
sbit do_93=0xA6;
sbit org_93=0xA7;
/*
sbit spi_cs = 0xA3;
sbit spi_sk = 0xA4;
sbit spi_di = 0xA5;
sbit spi_do = 0xA6;
sbit spi_org = 0xA7;*/
/*-----------------------------------------------------
SPI93cXX系列時序函數(shù)調(diào)用(普通封裝)
調(diào)用方式:void high46(void) ---高8位函數(shù)調(diào)用
void low46(void) ---低8位函數(shù)調(diào)用﹫2001/05/12
函數(shù)說明:私有函數(shù),SPI專用93c46普通封裝驅(qū)動程序
-----------------------------------------------------*/
void high46(void)
{
di_93=1;
sk_93=1;
_nop_();
sk_93=0;
_nop_();
}
void low46(void)
{
di_93=0;
sk_93=1;
_nop_();
sk_93=0;
_nop_();
}
void wd46(unsigned char dd)
{
unsigned char i;
for (i=0;i8;i++)
{
if (dd>=0x80)
high46();
else
low46();
dd=dd1;
}
}
unsigned char rd46(void)
{
unsigned char i,dd;
do_93=1;
for (i=0;i8;i++)
{
dd=1;
sk_93=1;
_nop_();
sk_93=0;
_nop_();
if (do_93)
dd|=1;
}
return(dd);
}
/*-----------------------------------------------------
SPI93cXX系列時序函數(shù)調(diào)用(特殊封裝)
調(diào)用方式:自行定義﹫2001/05/12
函數(shù)說明:私有函數(shù),特殊封裝各接口定義
-----------------------------------------------------
#define di_93a dip5
#define sk_93a dip4
#define cs_93a dip3
#define do_93a dip6
#define gnd_93a dip7
#define vcc_93a out_vcc(2)
sbit cs_93a=P1^0;
sbit sk_93a=P1^1;
sbit di_93a=P1^2;
sbit do_93a=P1^3;
/*-----------------------------------------------------
SPI93cXX系列時序函數(shù)調(diào)用(特殊封裝)
調(diào)用方式:void high46a(void) ---高8位函數(shù)調(diào)用
void low46a(void) ---低8位函數(shù)調(diào)用﹫2001/05/12
函數(shù)說明:私有函數(shù),SPI專用93c46特殊封裝驅(qū)動程序
-----------------------------------------------------
void high46a(void)
{
di_93a=1;
sk_93a=1;_nop_();
sk_93a=0;_nop_();
}
void low46a(void)
{
di_93a=0;
sk_93a=1;_nop_();
sk_93a=0;
_nop_();
}
void wd46a(unsigned char dd)
{
unsigned char i;
for (i=0;i8;i++)
{
if (dd>=0x80) high46a();
else low46a();
dd=dd1;
}
}
unsigned char rd46a(void)
{
unsigned char i,dd;
do_93a=1;
for (i=0;i8;i++)
{
dd=1;
sk_93a=1;_nop_();
sk_93a=0;_nop_();
if (do_93a) dd|=1;
}
return(dd);
}
/*-----------------------------------------------------
SPI93c46系列函數(shù)調(diào)用(舉例)
調(diào)用方式:bit write93c56_word(unsigned int address,unsigned int dat) ﹫2001/05/12
函數(shù)說明:私有函數(shù),SPI專用
-----------------------------------------------------*/
void ewen46(void)
{
_nop_();
cs_93=1;
high46();
wd46(0x30);
cs_93=0;
}
c語言相關(guān)文章:c語言教程
晶振相關(guān)文章:晶振原理
評論