找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

51单片机模拟spi串行接口程序,在keilc51下编写

  [复制链接]
admin 发表于 2010-5-25 22:46:26 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
51单片机模拟spi串行接口程序,在keilC51下编写

  1. sbit CS=P3^5;
  2. sbit CLK= P1^5;
  3. sbit DataI=P1^7;
  4. sbit DataO=P1^6;
  5. #define SD_Disable() CS=1 //片选关
  6. #define SD_Enable() CS=0 //片选开
  7. unsigned char SPI_TransferByte(unsigned char val)
  8. {
  9. unsigned char BitCounter;
  10. for(BitCounter=8; BiCounter!=0; BitCounter--)
  11. { CLK=0;
  12. DataI=0; // write
  13. if(val&0x80) DataI=1;
  14. val<<=1;
  15. CLK=1;
  16. if(DataO)val|=1; // read
  17. }
  18. CLK=0;
  19. return val;
  20. }sbit CLK= P1^5;
  21. sbit DataI=P1^7;
  22. sbit DataO=P1^6;
  23. #define SD_Disable() CS=1 //片选关
  24. #define SD_Enable() CS=0 //片选开
  25. unsigned char SPI_TransferByte(unsigned char val)
  26. {
  27. unsigned char BitCounter;
  28. for(BitCounter=8; BiCounter!=0; BitCounter--)
  29. { CLK=0;
  30. DataI=0; // write
  31. if(val&0x80) DataI=1;
  32. val<<=1;
  33. CLK=1;
  34. if(DataO)val|=1; // read
  35. }
  36. CLK=0;
  37. return val;
  38. }
  39. sbit CLK= P1^5;
  40. sbit DataI=P1^7;
  41. sbit DataO=P1^6;
  42. #define SD_Disable() CS=1 //片选关
  43. #define SD_Enable() CS=0 //片选开
  44. unsigned char SPI_TransferByte(unsigned char val)
  45. {
  46. unsigned char BitCounter;
  47. for(BitCounter=8; BiCounter!=0; BitCounter--)
  48. { CLK=0;
  49. DataI=0; // write
  50. if(val&0x80) DataI=1;
  51. val<<=1;
  52. CLK=1;
  53. if(DataO)val|=1; // read
  54. }
  55. CLK=0;
  56. return val;
  57. }
  58. sbit CLK= P1^5;
  59. sbit DataI=P1^7;
  60. sbit DataO=P1^6;
  61. #define SD_Disable() CS=1 //片选关
  62. #define SD_Enable() CS=0 //片选开
  63. unsigned char SPI_TransferByte(unsigned char val)
  64. {
  65. unsigned char BitCounter;
  66. for(BitCounter=8; BiCounter!=0; BitCounter--)
  67. { CLK=0;
  68. DataI=0; // write
  69. if(val&0x80) DataI=1;
  70. val<<=1;
  71. CLK=1;
  72. if(DataO)val|=1; // read
  73. }
  74. CLK=0;
  75. return val;
  76. }
  77. sbit CLK= P1^5;
  78. sbit DataI=P1^7;
  79. sbit DataO=P1^6;
  80. #define SD_Disable() CS=1 //片选关
  81. #define SD_Enable() CS=0 //片选开
  82. unsigned char SPI_TransferByte(unsigned char val)
  83. {
  84. unsigned char BitCounter;
  85. for(BitCounter=8; BiCounter!=0; BitCounter--)
  86. { CLK=0;
  87. DataI=0; // write
  88. if(val&0x80) DataI=1;
  89. val<<=1;
  90. CLK=1;
  91. if(DataO)val|=1; // read
  92. }
  93. CLK=0;
  94. return val;
  95. }
  96. sbit CLK= P1^5;
  97. sbit DataI=P1^7;
  98. sbit DataO=P1^6;
  99. #define SD_Disable() CS=1 //片选关
  100. #define SD_Enable() CS=0 //片选开
  101. unsigned char SPI_TransferByte(unsigned char val)
  102. {
  103. unsigned char BitCounter;
  104. for(BitCounter=8; BiCounter!=0; BitCounter--)
  105. { CLK=0;
  106. DataI=0; // write
  107. if(val&0x80) DataI=1;
  108. val<<=1;
  109. CLK=1;
  110. if(DataO)val|=1; // read
  111. }
  112. CLK=0;
  113. return val;
  114. }
  115. sbit CLK= P1^5;
  116. sbit DataI=P1^7;
  117. sbit DataO=P1^6;
  118. #define SD_Disable() CS=1 //片选关
  119. #define SD_Enable() CS=0 //片选开
  120. unsigned char SPI_TransferByte(unsigned char val)
  121. {
  122. unsigned char BitCounter;
  123. for(BitCounter=8; BiCounter!=0; BitCounter--)
  124. { CLK=0;
  125. DataI=0; // write
  126. if(val&0x80) DataI=1;
  127. val<<=1;
  128. CLK=1;
  129. if(DataO)val|=1; // read
  130. }
  131. CLK=0;
  132. return val;
  133. }
  134. sbit CLK= P1^5;
  135. sbit DataI=P1^7;
  136. sbit DataO=P1^6;
  137. #define SD_Disable() CS=1 //片选关
  138. #define SD_Enable() CS=0 //片选开
  139. unsigned char SPI_TransferByte(unsigned char val)
  140. {
  141. unsigned char BitCounter;
  142. for(BitCounter=8; BiCounter!=0; BitCounter--)
  143. { CLK=0;
  144. DataI=0; // write
  145. if(val&0x80) DataI=1;
  146. val<<=1;
  147. CLK=1;
  148. if(DataO)val|=1; // read
  149. }
  150. CLK=0;
  151. return val;
  152. }
  153. sbit CLK= P1^5;
  154. sbit DataI=P1^7;
  155. sbit DataO=P1^6;
  156. #define SD_Disable() CS=1 //片选关
  157. #define SD_Enable() CS=0 //片选开
  158. unsigned char SPI_TransferByte(unsigned char val)
  159. {
  160. unsigned char BitCounter;
  161. for(BitCounter=8; BiCounter!=0; BitCounter--)
  162. { CLK=0;
  163. DataI=0; // write
  164. if(val&0x80) DataI=1;
  165. val<<=1;
  166. CLK=1;
  167. if(DataO)val|=1; // read
  168. }
  169. CLK=0;
  170. return val;
  171. }
复制代码
hpdell 发表于 2010-5-27 13:12:58 | 显示全部楼层
谢谢!!!!!!!!!!!!!
aniu12 发表于 2010-9-26 13:51:32 | 显示全部楼层
搞笑吧,只有数据传送子函数?楼主肯定在开我们玩笑!
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-23 11:52 , Processed in 0.050755 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表