spi.c

来自「基于摩托罗拉(现在飞思卡尔)系列MC68HC908单片机开发车辆ECU系统!」· C语言 代码 · 共 73 行

C
73
字号
#include "SPI.h"



  
 

void SPIinit(void) {
 SPCR_SPMSTR=1;
 CS_33972=1;
 DDRD_DDRD0=1;
 CS_33689=1;
 DDRA_DDRA3=1;
 SPSCR_SPR=0x01;
 SPIenable;
 }
 

void SPI33972(UINT8 SPIbyte1, UINT8 SPIbyte2, UINT8 SPIbyte3, UINT8 SPIbyte4, UINT8 SPIbyte5, UINT8 SPIbyte6) {
UINT8 i=0xf;
DisableInt();
CS_33972=0;
while(i--); 
while (!SPSCR_SPTE);
SPDR=SPIbyte1;
while(!SPSCR_SPRF);
switchstatus[0]=SPDR;
while (!SPSCR_SPTE);
SPDR=SPIbyte2;
while(!SPSCR_SPRF);
switchstatus[1]=SPDR;
while (!SPSCR_SPTE);
SPDR=SPIbyte3;
while(!SPSCR_SPRF);
switchstatus[2]=SPDR;
while (!SPSCR_SPTE);
SPDR=SPIbyte4; 
while(!SPSCR_SPRF);
switchstatus[3]=SPDR;
while (!SPSCR_SPTE);
SPDR=SPIbyte5;
while(!SPSCR_SPRF);
switchstatus[4]=SPDR;
while (!SPSCR_SPTE);
SPDR=SPIbyte6;
while(!SPSCR_SPRF);
switchstatus[5]=SPDR;
i=0xf;
while(i--);
CS_33972=1;
EnableInt();
}

void SPI33689(UINT8 SPIbyte){
UINT16 i;
UINT8 temp;
DisableInt();
CS_33689=0;
i=0xf;
while(i--);
SPDR=SPIbyte;
while(!SPSCR_SPRF);
temp=SPDR;
i=0xf;
while(i--);
CS_33689=1;
EnableInt();
}


  

  

⌨️ 快捷键说明

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