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

📄 main.c

📁 example lis302 lpc2142
💻 C
字号:
//
// Copyright (c) 2009  http://www.embeddedboards.com 
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#include <LPC214x.h>
#include <vcom.h>
#include <LIS302.h>
#include <string.h>
#include <micro214x.h>
#include <stdio.h>
#include <stdlib.h>

#define OK	1
#define ERROR	0
#define ACTIVE	1
#define INACTIVE	0

#define SCLK_PINSEL		0x00000100	//Select SPI Function for P0.4
#define MISO_PINSEL		0x00000400	//Select SPI Function for P0.5
#define MOSI_PINSEL		0x00001000	//Select SPI Function for P0.6
 
static unsigned int   incoming;       // pointer to SPI data buffer 
static unsigned int   count;      // nr of bytes send/received 
static unsigned int	i;
static unsigned int	k;

void print_banner(void)
{
	printf("\n\r");
	printf("http://www.embeddedboards.com micro214x LIS302DL\n\r");
	printf("----------------------------------------------------\n\r");
	printf("\n\r");
}

void initializeAccelerometer( char range ) {
	//Initialize the accelerometer
	initAccel(range);

	//Set Accel. to Interrupt.
	//WriteLis302Register(FF_WU_CFG_1, XHIE | ZHIE | YHIE);	//Enable LIS302 Accel. Interrupts
	//WriteLis302Register(FF_WU_THS_1, 55);					//Set Accelerometer Threshold to ~1G


	WriteLis302Register(CLICK_CFG, LIR | Double_X | Double_Y | Double_Z);	//Enable LIS302 Click. Interrupts
	WriteLis302Register(CLICK_THSY_X, 0xff );
	WriteLis302Register(CLICK_THSZ, 0xff );
	WriteLis302Register(CLICK_timelimit, 0x5 );
	WriteLis302Register(CLICK_latency, 0xf5 );
	WriteLis302Register(CLICK_window, 0xb5 );

	WriteLis302Register(Ctrl_Reg3, I1CFG0|I1CFG1|I1CFG2 );

	//Make sure Accelerometer is not selected
	UnselectAccel();
	
}

void iniciar_SPI(void)
{
	IODIR0  |= 0x00000080;         // P0.7 SS_LIS302DL
	UnselectAccel();
	printf("INICIO SPI:\n\r");
	SPI0_Init();			//Select pin functions for SPI signals.
	S0SPCCR = 64;           // SCK = 1 MHz (60MHz / 64 ~= 1Mhz)
	S0SPCR  = 0x20;			//antes 0x20
	  
	
	UnselectAccel();
		
}

void esperando(void)
{
	for (i=0 ; i< 100000; i++);	
	printf("\n\rFIN\n\r");
}

int main(void)
{
	LEDS_init();	/* init the LEDs for this board  */
	VCOM_init();	/* init the USB Virtual COM port */
	   	
	printf_output(&VCOM_putchar);	/* define the output for the printf/puts */

	
	LEDS_on(LED3);
	count = 0;
	
	
	while (1) 
	{
		
		k = VCOM_getchar();
		
		LEDS_on(LED1);
		
		print_banner();
		
	
		printf("inicia spi\n\r");
		iniciar_SPI();
		esperando();
		
		printf("Iniciando acelerometro \n\r");
		initializeAccelerometer(1);
		esperando();
		WriteLis302Register(Ctrl_Reg1,0x6f);
		
		printf("Leer quien soy: %x\n\r",ReadLis302Register(WHO_AM_I));
		
		LEDS_off(LED1);
		accelX();
	}

}




⌨️ 快捷键说明

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