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

📄 s8051.c

📁 芯科rf资料
💻 C
字号:
/*** ============================================================================**** FILE**  S8051.c**** DESCRIPTION**  Contains all the low level, 8051 dependent functions		    **** CREATED**  Silicon Laboratories Hungary Ltd**** COPYRIGHT**  Copyright 2008 Silicon Laboratories, Inc.  **	http://www.silabs.com**** ============================================================================*/#include "S8051.h"/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  +  + FUNCTION NAME:  void SetHwMasterSpi(void)  +  + DESCRIPTION:    Initialize the HW SPI port  +  +	INPUT:			data   +  + RETURN:         None  +  + NOTES:          It doesn't control the nSEL pin  +  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/void SetHwMasterSpi(void){		SPI1CFG   = 0x40;					//Master SPI, CKPHA=0, CKPOL=0	SPI1CN    = 0x00;					//3-wire Single Master, SPI enabled	SPI1CKR   = (SYSCLK/(2*SPI_CLOCK))-1;	SPI1EN 	 = 1;                     	// Enable SPI1 module	//set nSEL pins to high    RF_NSEL = 1;    }/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  +  + FUNCTION NAME:  uint8 spi_read_write_byte(uint8 spi_in)  +  + DESCRIPTION:    Send and receive 8bits on the SPI port (MSB first)  +  +	INPUT:			8bit SPI data  +  + RETURN:         8bit received data  +  + NOTES:          void init_pic(void) function has to be called before!  +  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/uint8 spi_read_write_byte(uint8 spi_in){	SPI1DAT = spi_in;					//write data into the SPI register	while( SPIF1 == 0);					//wait for sending the data	SPIF1 = 0;							//clear interrupt flag	return SPI1DAT;						//read received bytes}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  +  + FUNCTION NAME:  uint16 send_control_command(uint16 control_command)  +  + DESCRIPTION:    Send and receive 16bit EZRadio control command   +  +	INPUT:			16bit EZRadio control command  +  + RETURN:         the received answer from the EZRadio  +  + NOTES:          None  +  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/uint16 send_control_command(uint16 control_command){	xdata uint16 temp16;			RF_NSEL = 0;							temp16 = (uint16)(spi_read_write_byte( (uint8)((control_command & 0xFF00) >> 8) ));	temp16 <<= 8;	temp16 += (uint16)(spi_read_write_byte( (uint8)(control_command & 0x00FF) ));	RF_NSEL = 1;	return temp16;}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  +  + FUNCTION NAME:  void delay_ms(uint8 delay)  +  + DESCRIPTION:    wait the predefined ms  +  +	INPUT:			length of the delay in ms (1 ... 255)  +  + RETURN:         None  +  + NOTES:          None  +  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/void delay_ms(uint8 delay){		xdata uint8  j;	xdata uint16 i;	if( delay == 0 )	{		return;	}	for(j=0;j<delay;j++)	{		for(i=0;i<640;i++);	}	}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  +  + FUNCTION NAME:  void Timer2Init(void)  +  + DESCRIPTION:    initialize the Timer2    +  +	INPUT:			None  +  + RETURN:         None  +  + NOTES:          None  +  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/void Timer2Init(void)					//8051 Timer2 init					{   	CKCON &= ~0x60;                     // Timer2 uses SYSCLK/12   	TMR2CN &= ~0x01;  	TMR2CN = 0x04;                      // Enable Timer2 in auto-reload mode  	ET2 = 1;                            // Timer2 interrupt enabled		TMR2L = 0x1A;								TMR2RLL = 0x1A;	TMR2H = 0x0A;	TMR2RLH = 0x0A;}

⌨️ 快捷键说明

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