下载

1下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 ATMEL51系列单片机SPI例程

ATMEL51系列单片机SPI例程.pdf

ATMEL51系列单片机SPI例程

zaiwu2000
2013-03-03 0人阅读 举报 0 0 暂无简介

简介:本文档为《ATMEL51系列单片机SPI例程pdf》,可适用于IT/计算机领域

D:天康工作DOCDOCc*************************MasterwithSlavesSelect***************************file$RCSfile:spimasterssc,v$****Copyright(c)Atmel****Pleasereadfilelicensetxtforcopyrightnotice**briefThisfileisanexampletousespiinmastermode**ThisfilecanbeparsedbyDoxygenforautomaticdocumentation**generation**Putherethefunctionaldescriptionofthisfilewithinthesoftware**architectureofyourprogram**version$Revision:$$Name:$****************************************************************************sectionINCLUDES*#include"regch"charserialdatachardataexample=xchardatasavebittransmitcompleted=******************************************************************FUNCTIONPURPOSE:Thisfilesetupspiinmastermodewith**FclkPeriphasbaudrateandwithslaveselectpin**FUNCTIONINPUTS:P(MISO)serialinput**FUNCTIONOUTPUTS:P(MOSI)serialoutput******************************************************************voidmain(void){SPCON|=x*Mastermode*P=*enablemaster*SPCON|=x*FclkPeriph*SPCON=~x*CPOL=transmitmodeexample*SPCON|=x*CPHA=transmitmodeexample*IEN|=x*enablespiinterrupt*SPCON|=x*runspi*EA=*enableinterrupts*while()*endless*{SPDAT=dataexample*sendanexampledata*while(!transmitcompleted)*waitendoftransmition*transmitcompleted=*clearsoftwaretransfertflag*SPDAT=x*dataissendtogenerateSCKsignal*while(!transmitcompleted)*waitendoftransmition*transmitcompleted=*clearsoftwaretransfertflag*datasave=serialdata*savereceivedata*}}**********************************************************************FUNCTIONPURPOSE:interrupt**FUNCTIONINPUTS:void**FUNCTIONOUTPUTS:transmitcompleteissoftwaretransfertflag**********************************************************************voiditSPI(void)interrupt*interruptaddressisxB*{switch(SPSTA)*readandclearspistatusregister*{casex:serialdata=SPDAT*readreceivedata*transmitcompleted=*setsoftwareflag*breakPage:D:天康工作DOCDOCccasex:*puthereformodefaulttasking*breakcasex:*puthereforoverruntasking*break}}Page:D:天康工作DOCDOCc**************************SlavewithSlaveSelect****************************file$RCSfile:spislavessc,v$****Copyright(c)Atmel****Pleasereadfilelicensetxtforcopyrightnotice****briefThisfileisanexampletousespiinslavemode****ThisfilecanbeparsedbyDoxygenforautomaticdocumentation**generation**Putherethefunctionaldescriptionofthisfilewithinthesoftware**architectureofyourprogram****version$Revision:$$Name:$******************************************************************************sectionINCLUDES*#include"regch"bittransmitcompletedcharserialdata******************************************************************FUNCTIONPURPOSE:Thisfilesetupspiinslavemodewith**FclkPeriphasbaudrateandwithslaveselectpin**FUNCTIONINPUTS:P(MISO)serialinput**P(SS)=slaveselected**FUNCTIONOUTPUTS:P(MOSI)serialoutput******************************************************************voidmain(void){SPCON=~x*slavemode*SPCON=~x*CPOL=transmitmodeexample*SPCON|=x*CPHA=transmitmodeexample*IEN|=x*enablespiinterrupt*SPCON|=x*spirun*transmitcompleted=*clearsoftwaretransfertflag*EA=*enableinterrupts*while()*endless*{if(transmitcompleted){SPDAT=serialdata*echodatatomaster*transmitcompleted=*clearsoftwaretransfertflag*}}}********************************************************************FUNCTIONPURPOSE:spiinterrupt,receivedatatomaster**FUNCTIONINPUTS:void**FUNCTIONOUTPUTS:void********************************************************************voiditSPI(void)interrupt*interruptaddressisxB*{switch(SPSTA)*readandclearspistatusregister*{casex:serialdata=SPDAT*readreceivedata*transmitcompleted=*setsoftwareflag*breakcasex:*puthereformodefaulttasking*Page:D:天康工作DOCDOCcbreakcasex:*puthereforoverruntasking*break}SPDAT=serialdata*neededtocompleteclearingsequence*}Page:D:天康工作DOCDOCc****************************MasterwithoutSlaveSelect*************************file$RCSfile:spimasternossc,v$****Copyright(c)Atmel****Pleasereadfilelicensetxtforcopyrightnotice****briefThisfileisanexampletousespiinmastermode**ThisfilecanbeparsedbyDoxygenforautomaticdocumentation**generation**Putherethefunctionaldescriptionofthisfilewithinthesoftware**architectureofyourprogram**version$Revision:$$Name:$*******************************************************************************sectionINCLUDES*#include"regch"charserialdatachardataexample=xchardatasavebittransmitcompleted=******************************************************************FUNCTIONPURPOSE:Thisfilesetupspiinmastermodewith**FclkPeriphasbaudrateandwithoutslaveselectpin**FUNCTIONINPUTS:P(MISO)serialinput**FUNCTIONOUTPUTS:P(MOSI)serialoutput**P******************************************************************voidmain(void){SPCON|=x*Mastermode*SPCON|=x*FclkPeriph*SPCON|=x*PisavailableasstandardIOpin*SPCON=~x*CPOL=transmitmodeexample*SPCON|=x*CPHA=transmitmodeexample*IEN|=x*enablespiinterrupt*SPCON|=x*runspi*EA=*enableinterrupts*while()*endless*{P=~P*PisavailableasstandardIOpin*SPDAT=dataexample*sendanexampledata*while(!transmitcompleted)*waitendoftransmition*transmitcompleted=*clearsoftwaretransfertflag*SPDAT=x*dataissendtogenerateSCKsignal*while(!transmitcompleted)*waitendoftransmition*transmitcompleted=*clearsoftwaretransfertflag*datasave=serialdata*savereceivedata*}}*************************************************************************FUNCTIONPURPOSE:interrupt**FUNCTIONINPUTS:void**FUNCTIONOUTPUTS:transmitcompleteissoftwaretransfertflag*************************************************************************voiditSPI(void)interrupt*interruptaddressisxB*{switch(SPSTA)*readandclearspistatusregister*{casex:Page:D:天康工作DOCDOCcserialdata=SPDAT*readreceivedata*transmitcompleted=*setsoftwareflag*breakcasex:*puthereformodefaulttasking*breakcasex:*puthereforoverruntasking*break}}Page:D:天康工作DOCDOCc******************************SlavewithoutSlaveSelect*************************file$RCSfile:spislavenossc,v$****Copyright(c)Atmel****Pleasereadfilelicensetxtforcopyrightnotice****briefThisfileisanexampletousespiinslavemode****ThisfilecanbeparsedbyDoxygenforautomaticdocumentation**generation**Putherethefunctionaldescriptionofthisfilewithinthesoftware**architectureofyourprogram****version$Revision:$$Name:$********************************************************************************sectionINCLUDES*#include"regch"bittransmitcompletedcharserialdata*****************************************************************FUNCTIONPURPOSE:Thisfilesetupspiinslavemodewith**FclkPeriphasbaudrateandwithoutslaveselectpin**FUNCTIONINPUTS:P(MISO)serialinput**FUNCTIONOUTPUTS:P(MOSI)serialoutput**P*****************************************************************voidmain(void){SPCON|=x*PisavailableasstandardIOpin**SPCON(SSDIS)hasnoeffectifCPHA=inslavemodethenPisusedtoslaveselect*SPCON=~x*slavemode*SPCON=~x*CPOL=transmitmodeexample*SPCON|=x*CPHA=transmitmodeexample*IEN|=x*enablespiinterrupt*SPCON|=x*spirun*transmitcompleted=*clearsoftwaretransfertflag*EA=*enableinterrupts*while()*endless*{P=~P*PisavailableasstandardIOpin*if(transmitcompleted){SPDAT=serialdata*echodatatomaster*transmitcompleted=*clearsoftwaretransfertflag*}}}*****************************************************************FUNCTIONPURPOSE:spiinterrupt,receivedatatomaster**FUNCTIONINPUTS:void**FUNCTIONOUTPUTS:void*****************************************************************voiditSPI(void)interrupt*interruptaddressisxB*{switch(SPSTA)*readandclearspistatusregister*{casex:Page:D:天康工作DOCDOCcserialdata=SPDAT*readreceivedata*transmitcompleted=*setsoftwareflag*breakcasex:*puthereformodefaulttasking*breakcasex:*puthereforoverruntasking*break}SPDAT=serialdata*neededtocompleteclearingsequence*}Page:D:天康工作DOCDOCregch*****************************SFRRegisterDefinition*****************************NAME:regch****PURPOSE:SFRDescriptionfileforproducts**ONKEILcompiler*****************************************************************************#defineSfr(x,y)sfrx=y#defineSbit(x,y,z)sbitx=y^z#defineSfr(x,y)sfrx=y***IncludefileforSFRDefinitions****BYTERegister*Sfr(P,x)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sfr(P,x)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sbit(P,x,)Sfr(P,xA)Sbit(P,xA,)Sbit(P,xA,)Sbit(P,xA,)Sbit(P,xA,)Sbit(P,xA,)Sbit(P,xA,)Sbit(P,xA,)Sbit(P,xA,)Sf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sfr(EECON,xD)Page:ATMEL系列单片机SPI例程MasterwithSlavesSelectSlavewithSlaveSelectMasterwithoutSlaveSelectSlavewithoutSlaveSelectSFRRegisterDefinition

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/12

ATMEL51系列单片机SPI例程

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利