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

📄 lib_lpc_spi.h

📁 使用embest IDE开发工具开发的基于LPC2294 的触摸屏开发
💻 H
字号:

/*
***********************************************************************

       Embest Info&Tech Co., Ltd.  All rights reserved.
                     www.embedinfo.com

***********************************************************************

---------------- file information -------------------------------------

file name: lpc_lib_spi.h
version  : v0
author   : peter pan / panqan@hotmail.com
	                   panqian@embedinfo.com
begin    : 2006-02-10
finish   : 2006-02-10
define   : lpc spi controll functions head file

notes    :

---------------- modify information -----------------------------------
version  :
modify   :
begin    :
finish   :
define   :
-----------------------------------------------------------------------
*/


// (--------------------- compiler condition --------------------------
#ifndef  lpc_lib_spi_h
         #define  lpc_lib_spi_h



// --------------------- compiler condition --------------------------)



/*-------------------------------------------------------------------*/
/*                       include files                               */
/*---------------------------------------------------------------- --*/
#include	"..\..\..\com\type_redefine.h"
#include	"..\..\..\com\register_lpc22xx.h"


/*-------------------------------------------------------------------*/
/*                       variable define                             */
/*-------------------------------------------------------------------*/


// SPI driver



// SPI Port define
// P0 to spi0 controll value in PINSEL0
#define		P0_4__SPI_SCK0_PINSEL0_VALUE       (0x01 <<8)  //01
#define		P0_5__SPI_MISO0_PINSEL0_VALUE      (0x01 <<10) //01
#define		P0_6__SPI_MOSI0_PINSEL0_VALUE      (0x01 <<12) //01
#define		P0_7__SPI_SSEL0_PINSEL0_VALUE      (0x01 <<14) //01
#define     SPI0_EN_PINSEL0_VALUE              (P0_4__SPI_SCK0_PINSEL0_VALUE + P0_5__SPI_MISO0_PINSEL0_VALUE\
                                              + P0_6__SPI_MOSI0_PINSEL0_VALUE + P0_7__SPI_SSEL0_PINSEL0_VALUE)
// P0 to spi0 controll MASK in PINSEL0
// use to clear the control bit
#define		P0_4__SPI_SCK0_PINSEL0_MASK        (0x03 <<8)  //11
#define		P0_5__SPI_MISO0_PINSEL0_MASK       (0x03 <<10) //11
#define		P0_6__SPI_MOSI0_PINSEL0_MASK       (0x03 <<12) //11
#define		P0_7__SPI_SSEL0_PINSEL0_MASK       (0x03 <<14) //11
#define     SPI0_EN_PINSEL0_MASK               (P0_4__SPI_SCK0_PINSEL0_MASK + P0_5__SPI_MISO0_PINSEL0_MASK\
                                              + P0_6__SPI_MOSI0_PINSEL0_MASK + P0_7__SPI_SSEL0_PINSEL0_MASK)
// spio master control in PINSEL1
#define     P0_24__GPIO_024_PINSEL1_VALUE      (0x00<<16)
#define     P0_24__GPIO_024_PINSEL1_MASK       (0x03<<16)  //11


//define the spi0 control
#define     SPCR_CPHA_B1_595_VALUE             (0x0<<3)
#define     SPCR_CPHA_B2_595_VALUE             (0x1<<3)
#define     SPCR_CPOL_CH_595_VALUE             (0x0<<4)
#define     SPCR_CPOL_CL_595_VALUE             (0x1<<4)
#define     SPCR_MSTR_MASTER_595_VALUE         (0x1<<5)
#define     SPCR_MSTR_SLAVE_595_VALUE          (0x0<<5)
#define     SPCR_LSBR_B0F_595_VALUE            (0x1<<6)
#define     SPCR_LSBR_B7F_595_VALUE            (0x0<<6)
#define     SPCR_SPIE_EE_595_VALUE             (0x1<<7)
#define     SPCR_SPIE_ED_595_VALUE             (0x0<<7)

//spi0 value for 595
#define     SPCR_SPI_595_VALUE                 (SPCR_CPHA_B1_595_VALUE+SPCR_CPOL_CL_595_VALUE+SPCR_MSTR_MASTER_595_VALUE\
                                               +SPCR_LSBR_B7F_595_VALUE+SPCR_SPIE_ED_595_VALUE)


/*
	#define		SPCR_MSTR_SLAVE			(0 << 5)
	#define		SPCR_MSTR_MASTER		(1 << 5)
	#define		SPCR_CPOL_SET			(1 << 4)

    SPI0_SPCCR = SPCCR_SET(S0SPCCR_DATA);						// Set the SPI Frequence
    SPI0_SPCR  = (SPCR_MSTR_MASTER | SPCR_CPOL_SET);	
	SPI0_SPCR  = 0x30;
*/


// P0 to spi1 controll value
#define		P0_17__SPI_SCK1_PINSEL1_VALUE      (0x10<<2)
#define		P0_18__SPI_MISO1_PINSEL1_VALUE     (0x10<<4)
#define		P0_19__SPI_MOSI1_PINSEL1_VALUE     (0x10<<6)
#define		P0_20__SPI_SSEL1_PINSEL1_VALUE     (0x10<<8)
#define     SPI1_EN_PINSEL1_VALUE              (P0_4__SPI_SCK1_PINSEL1_VALUE + P0_5__SPI_MISO1_PINSEL1_VALUE\
                                              + P0_6__SPI_MOSI1_PINSEL1_VALUE + P0_7__SPI_SSEL1_PINSEL1_VALUE)

// P0 to spi1 controll value MASK
// use to clear the control bit
#define		P0_17__SPI_SCK1_PINSEL1_MASK       (0x03<<2)
#define		P0_18__SPI_MISO1_PINSEL1_MASK      (0x03<<4)
#define		P0_19__SPI_MOSI1_PINSEL1_MASK      (0x03<<6)
#define		P0_20__SPI_SSEL1_PINSEL1_MASK      (0x03<<8)
#define     SPI1_EN__PINSEL1_MASK              (P0_4__SPI_SCK1_PINSEL1_MASK + P0_5__SPI_MISO1_PINSEL1_MASK\
                                              + P0_6__SPI_MOSI1_PINSEL1_MASK + P0_7__SPI_SSEL1_PINSEL1_MASK)


// define the spix_spccr value
#define     SPI_SPCCR_value_max   10



typedef enum {
	          spi_c0=0,
	          spi_c1,
	         } spi_channel;

typedef enum {
	          spi_slave=0,
	          spi_master,
	         } spi_mode;

typedef enum {
	          spi_off=0,
	          spi_on,
	         } spi_onoff;



/*-------------------------------------------------------------------*/
/*                       local function declare                      */
/*-------------------------------------------------------------------*/

// spi_extend controll LIB
void spi_init(spi_channel channel, spi_mode mode, spi_onoff onoff);
void spi_send(spi_channel channel, INT8U data_send);
void spi_data_send(spi_channel channel, INT8U data_send);



/*-------------------------------------------------------------------*/
/*                       extern function declare                     */
/*-------------------------------------------------------------------*/

/*--- define in XXX.c ---
extern  void    XXX();
*/


/*-------------------------------------------------------------------*/
/*                       extern variable declare                     */
/*-------------------------------------------------------------------*/

/*--- USED in XXX() ---
XXX SSS; // used inXXX()
*/


/*-------------------------------------------------------------------*/
/*                       function code                               */
/*-------------------------------------------------------------------*/


/**********************************************************************
* name  :    xxxxx
* func  :    xxxxx
* para  :    xxxx
* ret   :    xxxx

* glob  :    xxxx
* inc   :

* author:
* date  :

* modify:
* comment:
**********************************************************************/
/*void  xxx(xxx xxx)
      {
      }
*/


#endif  //lpc_lib_spi_h

⌨️ 快捷键说明

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