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

📄 spi1c1.c

📁 NEC78f0892 SPI single
💻 C
字号:

/**************************** .FILE_HEADER_BEGIN *****************************
  .TITLE  		[ SPI display data communication control					]
*-----------------------------------------------------------------------------
  .FILE   		[ SPI1c1.c                                               	]
  .AUTHOR 	[ Leon                                                  	]
*-----------------------------------------------------------------------------
  .CONTENTS  (Will be filled by MAS-SoftDoc)
   *** Functions / Macros ***      *** Title ***

   *** Functions / Macros ***      *** Title ***

*-----------------------------------------------------------------------------
  .INCLUDE_REFERENCES  (Will be filled by MAS-SoftDoc)
   *** Program Includefiles ***

   *** External Includefiles ***

*-----------------------------------------------------------------------------
  .REVISION_LIST  (Will be filled by Leon)
   Archive: $Log:     $
//
//    Rev 1.10   Jun 21 2007 17:09    Building  
// 
//
//    

****************************** .FILE_HEADER_END *****************************/

#define SPI1C1                          /* Name of the Module                */


/*****************************************************************************
* Template name		: SPI1C1.C
* Template revision	: 
*-----------------------------------------------------------------------------
* CASE-Tool:         EasyCASE(C++), Version 6.01
	Last change: EB 18.02.04 13:48:08
******************************************************************************/

/*****************************************************************************
* HEADER-FILES (Only those that are needed in this file)
*****************************************************************************/
/* System-headerfiles */
#include "target.h"
#include "CDEF.H"			/* General type definitions */
#include "mmi1c1.h"
#include "io78082x.h"
#include "sysbits.h"

/* Own headerfiles */
#include "SPI1C1.H" 		/* Export interface (Own interface) */
#include "SPI1CI.H"

static tunBitByte SPI_DisplayBuffer[6];
static uint8   SPI_Send_Count;
/**************************** .BLOCK_COMMENT_BEGIN ***************************
* GLOBAL DEFINITIONS
*
* In this section define
* - all global ROM-constants of your module
* - all global variables of your module
***************************** .BLOCK_COMMENT_END ****************************/


/**************************** .BLOCK_COMMENT_BEGIN ***************************
* FILE LOCAL DEFINITIONS
*
* In this section define
* - all file local macros
* - all file local define-constants
* - all file local type definitions
* - all file local ROM-constants
* - all file local variables
***************************** .BLOCK_COMMENT_END ****************************/

/* ===========================================================================
* Function   	: void SPI_vReset (void)
* Description	: Reset container function of SPI
* Takes      	: Nothing
* Returns    	: Nothing
*/
void SPI_vReset (void)
{
   SPI_vInit();
}

/* ===========================================================================
* Function   	: void SPI_vInit (void)
* Description	: Init function of SPI
*              	Called in Active->On container and through other local functions
* Takes      	: Nothing
* Returns    	: Nothing
*/
void SPI_vInit (void)
{
	SPI_SOMR	&= 0x01;//	(CSIM11)		//Serial operation mode register 11
	SPI_SOMR	|= 0xC0;//0x40;		//=1100000x
	
	SPI_SCSR	= 0x17;//	(CSIC11)=00010111		//Serial clock selection register 11
	SPI_PMR_SO	= 0;//	(PM7._no4)		//Port mode register 7 (PM7)
	SPI_PMR_SI	= 0;//	(PM7._no5)		//
	SPI_PMR_SCK	= 1;//	(PM7._no6)		//

	SPI_PR_SO	= 0;//	(P7._no4)		//Port register 7 (P7)
	SPI_PR_SI	= SPI_Bus_Busy;//	(P7._no5)		//spi bus is busy
	SPI_PR_SCK	= 1;//	(P7._no6)		//
       
	//SPI_EI;			//allow spi bus is started.
	SPI_3ms_Count=4;
	SPI_DisplayBuffer[0].b = Key_DisplayBuffer[0].b;  //~Fog
	SPI_DisplayBuffer[1].b = Key_DisplayBuffer[1].b;
	SPI_DisplayBuffer[2].b = Key_DisplayBuffer[2].b;
	SPI_DisplayBuffer[3].b = Key_DisplayBuffer[3].b;
	SPI_DisplayBuffer[4].b = Key_DisplayBuffer[4].b;
	SPI_DisplayBuffer[5].b = Key_DisplayBuffer[5].b;
	SPI_DataSend=(unsigned char)SPI_DisplayBuffer[0].b;
	SPI_Send_Count=1;
	
	SPI_Busy	= SPI_Bus_Free;
}

/* ===========================================================================
* Function   	: void SPI_vMain (void)
* Description	: Main container function of SPI
* Takes      	: Nothing
* Returns    	: Nothing
*/
void SPI_vMain_Isr(void)
{
	//SPI_DI;
	SPI_3ms_Count=0;
	SPI_PMR_SCK = 0;
	SPI_PR_SCK = 0;
	//CSIMK11 = 1;
	//SPI_SOMR	&= 0x01;//	(CSIM11)		//Serial operation mode register 11
	//SPI_SOMR	|= 0xC0;
	SPI_Busy			=SPI_Bus_Busy;
	SPI_DataSend 		=(unsigned char)SPI_DisplayBuffer[SPI_Send_Count].b;
	SPI_Send_Count++;
	if((SPI_Send_Count >= SPI_Array_Max) )
	{
		if(SPI_UpdataEnable == 0)// add it for mistake data when spi updata.
		{
			SPI_DisplayBuffer[0].b = Key_DisplayBuffer[0].b;  
			SPI_DisplayBuffer[1].b = Key_DisplayBuffer[1].b;
			SPI_DisplayBuffer[2].b = Key_DisplayBuffer[2].b;
			SPI_DisplayBuffer[3].b = Key_DisplayBuffer[3].b;
			SPI_DisplayBuffer[4].b = Key_DisplayBuffer[4].b;
			SPI_DisplayBuffer[5].b = Key_DisplayBuffer[5].b;
		}
		SPI_Send_Count	= 0;
	}
	//SPI_EI;
	//SPI_SOMR	|= 0x40;
}

/* ===========================================================================
* Function   	: void SPI_vDeinit (void)
* Description	: De-init function of SPI
*              	Called in On->Active container
* Takes      	: Nothing
* Returns    	: Nothing
*/
void SPI_vDeinit (void)
{
   //SPI_vInit();
   SPI_Busy			= SPI_Bus_Busy;
   SPI_DI;
}


/* ===========================================================================
* Function   	:void SPI_3msSysTick(void)
* Description	: 
* Takes      	: 
* Returns    	: 
*/
void SPI_3msSysTick(void)
{
	if(SPI_3ms_Count<3)
	{
		SPI_3ms_Count++;
		SPI_50ms_Count=0;
	}
	else if(SPI_3ms_Count==3)
	{
		SPI_3ms_Count++;
		SPI_50ms_Count=0;
		SPI_PMR_SCK =1;
		SPI_PR_SCK = 1;		
		SPI_Busy = SPI_Bus_Free;
	}
	else
	{
		SPI_50ms_Count++;
		if(SPI_50ms_Count>=47)
			SPI_EMI_PROTECT;
			// add it via EMI stop SPI, by leon at 2007.11.27
			// if SPI is stop after 50 ms, SPI genorator an interrupt request.
	}
		
}
/* [MRxx]-E */


/*****************************************************************************
* EOF:
*****************************************************************************/

⌨️ 快捷键说明

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