⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openspi1.c

📁 Mplab C30编译器
💻 C
字号:
#if defined(__PIC24F__)
#include <p24Fxxxx.h>
#endif
#include "spi.h"

/*********************************************************************************
Function Prototype : void OpenSPI1(unsigned int config1,unsigned int config2,
                                    unsigned int config3)

Include            : spi.h
 
Description        : This function configures the SPI module
 
Arguments          : config1 - This contains the parameters to be configured in the
                     SPIxCON1 register as defined below					 				
					 SCK Pin Control bit
					    DISABLE_SCK_PIN
					    ENABLE_SCK_PIN 
					 SDO Pin Control bit					
					    DISABLE_SDO_PIN					
					    ENABLE_SDO_PIN					
					 Word/Byte Communication mode					
					    SPI_MODE16_ON					
					    SPI_MODE8_ON					
				 	 SPI Data Input Sample phase					
					    SPI_SMP_ON					
					    SPI_SMP_OFF					
					 SPI Clock Edge Select					
					    SPI_CKE_ON					
					    SPI_CKE_OFF					
					 SPI slave select enable					
					    SLAVE_ENABLE_ON					
					    SLAVE_ENABLE_OFF					
					 SPI Clock polarity select					
					    CLK_POL_ACTIVE_LOW					
					    CLK_POL_ACTIVE_HIGH					
					 SPI Mode Select bit					
					    MASTER_ENABLE_ON					
					    MASTER_ENABLE_OFF					
					 Secondary Prescale select					
					    SEC_PRESCAL_1_1					
					    SEC_PRESCAL_2_1					
					    SEC_PRESCAL_3_1					
					    SEC_PRESCAL_4_1					
					    SEC_PRESCAL_5_1					
					    SEC_PRESCAL_6_1					
					    SEC_PRESCAL_7_1					
					    SEC_PRESCAL_8_1					
					 Primary Prescale select					
					    PRI_PRESCAL_1_1					
					    PRI_PRESCAL_4_1					
					    PRI_PRESCAL_16_1					
					    PRI_PRESCAL_64_1					
					 
					 config2 - This contains the parameters to be configured in the
                     SPIxCON2 register as defined below
					 Frame SPI support Enable/Disable					
					    FRAME_ENABLE_ON					
					    FRAME_ENABLE_OFF					
					 Frame Sync Pulse direction control					
					    FRAME_SYNC_INPUT					
					    FRAME_SYNC_OUTPUT
					 Frame Sync Polarity bit  
					    FRAME_SYNC_ACTIVE_HIGH
					    FRAME_SYNC_ACTIVE_LOW
					 Frame Delay bit  
					    SPI_FRM_PULSE_FIRST_CLK
					    SPI_FRM_PULSE_PREV_CLK
					 Enhance Buffer Enable\Disable
					    SPI_ENH_BUFF_ENABLE
					    SPI_ENH_BUFF_DISABLE    
					    						
					 config3 - This contains the parameters to be configured in the					
					 SPIxSTAT register as defined below					
					    SPI Enable/Disable					
					    SPI_ENABLE					
					    SPI_DISABLE					
					 SPI Idle mode operation					
					    SPI_IDLE_CON					
					    SPI_IDLE_STOP					
					 Clear Receive Overflow Flag bit
					    SPI_RX_OVFLOW					
					    SPI_RX_OVFLOW_CLR
 
Return Value       : None
 
Remarks            : This functions initializes the SPI module and sets the Idle mode
                     Operation. 
**************************************************************************************/
#ifdef _SPI_V2_1

void OpenSPI1(unsigned int config1,unsigned int config2,unsigned int config3)
{       
     SPI1CON1 = config1;      /* Initalizes the spi module */
     SPI1CON2 = config2;
     SPI1STAT = config3;     /* Enable/Disable the spi module */
}

#else
#warning "Does not build on this target"
#endif

⌨️ 快捷键说明

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