- UID
- 872235
|
/*********************************************************************************************************
*
* File : main.c
* Hardware Environment:
* Build Environment : RealView MDK-ARM Version: 4.20
* Version : V1.0
* By :
*
* (c) Copyright 2005-2011, WaveShare
* http://www.waveshare.net
* All Rights Reserved
*
*********************************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "I2C.h"
#include "LSM303.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* Private function prototypes -----------------------------------------------*/
void GPIO_Configuration(void);
void USART_Configuration(void);
/* 函数申明 -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void WWDG_Configuration(void);
void Delay(u32 nTime);
void Delayms(vu32 m);
#define uchar unsigned char
#define uint unsigned int
unsigned char TX_DATA[4];
unsigned char BUF_A[6],BUF_M[6]; //接收数据缓存区
char test=0;
short X_A,Y_A,Z_A, X_M,Y_M,Z_M;
float buf_A[3],buf_M[3];
float north;
/*******************************************************************************
* Function Name : Delay
* Description : Delay Time
* Input : - nCount: Delay Time
* Output : None
* Return : None
* Attention
: None
*******************************************************************************/
void Delay (uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
* Attention
: None
*******************************************************************************/
void usart_send(uchar *s)
{
uchar i;
printf("x=%c", *s );
for(i=0;i<3;i++)
printf("%c", *++s );
Delay (0xfffff);
}
int main(void)
{
// uint16_t Addr;
//
uint8_t WriteBuffer[256],ReadBuffer[256];
GPIO_Configuration();
USART_Configuration();
I2C_Configuration();
printf("\r\n**********************\r\n");
LSM303A_Init();
LSM303M_Init();
printf("\r\n****************************************************************\r\n");
while (1)
{
LAM303M_Raed(buf_M);
LAM303A_Raed(buf_A);
north=Data_conversion(buf_A,buf_M);//
printf("\r\n******** LSM303DLHC *********************\r\n");
printf("X_A=%f m/s^2\r\n",buf_A[0]);
printf("Y_A=%f m/s^2\r\n",buf_A[1]);
printf("Z_A=%f m/s^2\r\n",buf_A[2]);
printf("X_M=%f T\r\n",buf_M[0] );
printf("Y_M=%f T\r\n",buf_M[1]);
printf("Z_M=%f T\r\n",buf_M[2]);
printf("north=%f degree \r\n",north);
printf("\r\n");
Delay(8000000);
}
}
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configure GPIO Pin
* Input : None
* Output : None
* Return : None
* Attention
: None
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOF , ENABLE);
/**
* LED1 -> PF6 , LED2 -> PF7 , LED3 -> PF8 , LED4 -> PF9
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/*********************************************************************************************************
END FILE
*********************************************************************************************************/ |
|