C51 COMPILER V9.59.0.0 STC8A_SPI 06/10/2021 17:30:09 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE STC8A_SPI OBJECT MODULE PLACED IN .\list\STC8A_SPI.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE STC8A_SPI.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE DEBUG PRINT(.\list\STC8A -_SPI.lst) TABS(2) OBJECT(.\list\STC8A_SPI.obj) line level source 1 /*---------------------------------------------------------------------*/ 2 /* --- STC MCU Limited ------------------------------------------------*/ 3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/ 4 /* --- Mobile: (86)13922805190 ----------------------------------------*/ 5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/ 6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/ 7 /* --- Web: www.STCMCU.com --------------------------------------------*/ 8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/ 9 /* --- QQ: 800003751 -------------------------------------------------*/ 10 /* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */ 11 /*---------------------------------------------------------------------*/ 12 13 #include "STC8A_SPI.h" 14 15 u8 SPI_RxTimerOut; 16 u8 SPI_BUF_type SPI_RxBuffer[SPI_BUF_LENTH]; 17 bit B_SPI_Busy; //发送忙标志 18 19 20 //======================================================================== 21 // 函数: void SPI_Init(SPI_InitTypeDef *SPIx) 22 // 描述: SPI初始化程序. 23 // 参数: SPIx: 结构参数,请参考spi.h里的定义. 24 // 返回: none. 25 // 版本: V1.0, 2012-11-22 26 //======================================================================== 27 void SPI_Init(SPI_InitTypeDef *SPIx) 28 { 29 1 if(SPIx->SPI_SSIG == ENABLE) SPCTL &= ~(1<<7); //enable SS, conform Master or Slave by SS pin. 30 1 else SPCTL |= (1<<7); //disable SS, conform Master or Slave by SPI_Mode 31 1 SPI_Start(SPIx->SPI_Enable); 32 1 SPI_FirstBit_Set(SPIx->SPI_FirstBit); 33 1 SPI_Mode_Set(SPIx->SPI_Mode); 34 1 SPI_CPOL_Set(SPIx->SPI_CPOL); 35 1 SPI_CPHA_Set(SPIx->SPI_CPHA); 36 1 SPI_Clock_Select(SPIx->SPI_Speed); 37 1 38 1 SPI_RxTimerOut = 0; 39 1 B_SPI_Busy = 0; 40 1 } 41 42 //======================================================================== 43 // 函数: void SPI_SetMode(u8 mode) 44 // 描述: SPI设置主从模式函数. 45 // 参数: mode: 指定模式, 取值 SPI_Mode_Master 或 SPI_Mode_Slave. 46 // 返回: none. 47 // 版本: V1.0, 2012-11-22 48 //======================================================================== 49 void SPI_SetMode(u8 mode) 50 { 51 1 if(mode == SPI_Mode_Slave) 52 1 { 53 2 SPCTL &= ~(1<<4); //重新设置为从机待机 54 2 SPCTL &= ~(1<<7); //SS引脚确定主从 C51 COMPILER V9.59.0.0 STC8A_SPI 06/10/2021 17:30:09 PAGE 2 55 2 } 56 1 else 57 1 { 58 2 SPCTL |= (1<<4); //使能 SPI 主机模式 59 2 SPCTL |= (1<<7); //忽略SS引脚功能 60 2 } 61 1 } 62 63 //======================================================================== 64 // 函数: void SPI_WriteByte(u8 dat) 65 // 描述: SPI发送一个字节数据. 66 // 参数: dat: 要发送的数据. 67 // 返回: none. 68 // 版本: V1.0, 2020-09-14 69 //======================================================================== 70 void SPI_WriteByte(u8 dat) //SPI发送一个字节数据 71 { 72 1 SPDAT = dat; 73 1 B_SPI_Busy = 1; 74 1 while(B_SPI_Busy) ; 75 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 153 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = 129 ---- PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = 1 ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)