深圳免费网站制作哪个好,网站空间虚拟主机续费,工程行业证书,好的网页制作公司有哪些该楼层疑似违规已被系统折叠 隐藏此楼查看此楼89C51系列单片机都不带SPI口#xff0c;所在在这种情况下#xff0c;我们可以模拟SPI口来现实我们要的功能#xff0c;程序如下#xff1a;//-----------------------函数声明#xff0c;变量定义#xff0d;#xff0d;所在在这种情况下我们可以模拟SPI口来现实我们要的功能程序如下//-----------------------函数声明变量定义#include #include sbit SCKP1^0; // 将p1.0口模拟时钟输出sbit MOSIP1^1; // 将p1.1口模拟主机输出sbit MISOP1^2; // 将p1.1口模拟主机输入sbit SS1P1^3; // 将p1.1口模拟片选#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};//-------------------------------------------------------------------------------// 函数名称 SPISendByte// 入口参数 ch// 函数功能 发送一个字节//-------------------------------------------------------------------------------void SPISendByte(unsigned char ch){unsigned char idata n8; // 向SDA上发送一位数据字节共八位SCK 1 ; //时钟置高SS1 0 ; //选择从机 while(n--){delayNOP();SCK 0 ; //时钟置低if((ch0x80) 0x80) // 若要发送的数据最高位为1则发送位1{MOSI 1; // 传送位1}else{MOSI 0; // 否则传送位0}delayNOP();ch ch1; // 数据左移一位SCK 1 ; //时钟置高}}//-------------------------------------------------------------------------------// 函数名称 SPIreceiveByte// 返回接收的数据// 函数功能 接收一字节子程序//-------------------------------------------------------------------------------unsigned char SPIreceiveByte(){unsigned char idata n8; // 从MISO线上读取一上数据字节共八位unsigned char tdata;SCK 1; //时钟为高SS1 0; //选择从机while(n--){delayNOP();SCK 0; //时钟为低delayNOP();tdata tdata1; // 左移一位或_crol_(temp,1)if(MISO 1)tdata tdata|0x01; // 若接收到的位为1则数据的最后一位置1elsetdata tdata0xfe; // 否则数据的最后一位置0SCK1;}return(tdata);}//-------------------------------------------------------------------------------// 函数名称 SPIsend_receiveByte// 入口参数 ch// 返回接收的数据// 函数功能串行输入/输出子程序//-------------------------------------------------------------------------------unsigned char SPIsend_receiveByte(unsigned char ch){unsigned char idata n8; // 从MISO线上读取一上数据字节共八位unsigned char tdata;SCK 1; //时钟为高SS1 0; //选择从机while(n--){delayNOP();SCK 0; //时钟为低delayNOP();{tdata tdata1; // 左移一位或_crol_(temp,1)if(MISO 1)tdata tdata|0x01; // 若接收到的位为1则数据的最后一位置1elsetdata tdata0xfe; // 否则数据的最后一位置0}{if((ch0x80) 0x80) // 若要发送的数据最高位为1则发送位1{MOSI 1; // 传送位1}else{MOSI 0; // 否则传送位0}ch ch1; // 数据左移一位}SCK1;}return(tdata);}