ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/***
16 * Demo: MPU6050, 3-axis gyroscope + 3-axis accelerometer + Digital Motion Processor™ (DMP™)
17 * Board: STC8H8K64U
18 *
19 * P32 -> SCL
20 * P33 -> SDA
21 * GND -> GND
22 * 3.3V -> VCC
23 */
24#include "fw_hal.h"
25#include "mpu6050.h"
26#include <stdio.h>
27
28void I2C_Init(void)
29{
30 // Master mode
39 // Switch alternative port
41 // Start I2C
43}
44
45void GPIO_Init(void)
46{
47 // SDA
49 // SCL
51}
52
53int main(void)
54{
55 uint8_t i;
56 uint16_t buf[7];
57
59 GPIO_Init();
61 I2C_Init();
63
64 while(1)
65 {
66 for (i = 0; i < 100; i++)
67 {
68 if (i == 0)
69 {
71 }
72 else if (i == 50)
73 {
75 }
76 MPU6050_ReadAll(buf);
77 printf("ax:%6d, ay:%6d, az:%6d, tp:%6d, gx:%6d, gy:%6d, gz:%6d\r\n",
78 buf[0], buf[1], buf[2], (int16_t)buf[3] / 34 + 365, buf[4], buf[5], buf[6]);
79 SYS_Delay(100);
80 }
81 }
82}
__WEAK_ATY void printf(uint8_t *,...)
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:89
@ GPIO_Pin_2
Definition: fw_gpio.h:47
@ GPIO_Pin_3
Definition: fw_gpio.h:48
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ GPIO_Mode_InOut_QBD
Definition: fw_gpio.h:23
#define I2C_SetClockPrescaler(__DIV__)
Definition: fw_i2c.h:71
@ I2C_WorkMode_Master
Definition: fw_i2c.h:24
#define I2C_SetWorkMode(__MODE__)
Definition: fw_i2c.h:65
#define I2C_SetEnabled(__STATE__)
Definition: fw_i2c.h:64
@ I2C_AlterPort_P32_P33
Definition: fw_i2c.h:51
#define I2C_SetPort(__ALTER_PORT__)
Definition: fw_i2c.h:121
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
unsigned short uint16_t
Definition: fw_types.h:19
@ HAL_State_ON
Definition: fw_types.h:71
short int16_t
Definition: fw_types.h:24
unsigned char uint8_t
Definition: fw_types.h:18
@ UART1_BaudSource_Timer1
Definition: fw_uart.h:33
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56
int main(void)
Definition: main.c:45
void GPIO_Init(void)
Definition: main.c:39
void I2C_Init(void)
Definition: main.c:28
uint8_t __XDATA i
void MPU6050_DisableLowPowerMode(void)
Definition: mpu6050.c:78
void MPU6050_ReadAll(uint16_t *buf)
Definition: mpu6050.c:42
void MPU6050_EnableLowPowerMode(MPU6050_Wakeup_Freq_t freq)
Definition: mpu6050.c:73
void MPU6050_Init(void)
Definition: mpu6050.c:52
@ MPU6050_Wakeup_Freq_1p25Hz
Definition: mpu6050.h:110