51 单片机 max30102头文件代码
时间: 2023-08-28 11:04:57 浏览: 554
以下是51单片机的max30102头文件代码,供参考:
```c
#ifndef __MAX30102_H
#define __MAX30102_H
#include <reg52.h>
#define MAX30102_ADDRESS 0xAE >> 1
#define MAX30102_FIFO_WRITE_POINTER 0x04
#define MAX30102_FIFO_OVERFLOW_COUNTER 0x05
#define MAX30102_FIFO_READ_POINTER 0x06
#define MAX30102_FIFO_DATA 0x07
#define MAX30102_MODE_CONFIGURATION 0x09
#define MAX30102_SPO2_CONFIGURATION 0x0A
#define MAX30102_LED_CONFIGURATION 0x0C
#define MAX30102_TEMPERATURE_INTEGER 0x1F
#define MAX30102_TEMPERATURE_FRACTION 0x20
#define MAX30102_PART_ID 0xFF
#define MAX30102_REV_ID 0xFE
#define MAX30102_INTERRUPT_STATUS_1 0x00
#define MAX30102_INTERRUPT_STATUS_2 0x01
#define MAX30102_INTERRUPT_ENABLE_1 0x02
#define MAX30102_INTERRUPT_ENABLE_2 0x03
#define MAX30102_SAMPLEAVG_MASK (0x03)
#define MAX30102_SAMPLEAVG_1 (0x00)
#define MAX30102_SAMPLEAVG_2 (0x01)
#define MAX30102_SAMPLEAVG_4 (0x02)
#define MAX30102_SAMPLEAVG_8 (0x03)
#define MAX30102_ROLLOVER_MASK (0x08)
#define MAX30102_ROLLOVER_ENABLE (0x08)
#define MAX30102_ROLLOVER_DISABLE (0x00)
#define MAX30102_A_FULL_MASK (0x80)
#define MAX30102_A_FULL_ENABLE (0x80)
#define MAX30102_A_FULL_DISABLE (0x00)
#define MAX30102_SHUTDOWN_MASK (0x7F)
#define MAX30102_SHUTDOWN_ENABLE (0x80)
#define MAX30102_SHUTDOWN_DISABLE (0x00)
#define MAX30102_RESET_MASK (0xBF)
#define MAX30102_RESET_ENABLE (0x40)
#define MAX30102_RESET_DISABLE (0x00)
#define MAX30102_MODE_MASK (0xF8)
#define MAX30102_MODE_REDONLY (0x02)
#define MAX30102_MODE_REDIRONLY (0x03)
#define MAX30102_MODE_MULTILED (0x07)
#define MAX30102_ADCRANGE_MASK (0x9F)
#define MAX30102_ADCRANGE_2048 (0x00)
#define MAX30102_ADCRANGE_4096 (0x20)
#define MAX30102_ADCRANGE_8192 (0x40)
#define MAX30102_ADCRANGE_16384 (0x60)
#define MAX30102_SAMPLERATE_MASK (0xE3)
#define MAX30102_SAMPLERATE_50 (0x00)
#define MAX30102_SAMPLERATE_100 (0x04)
#define MAX30102_SAMPLERATE_200 (0x08)
#define MAX30102_SAMPLERATE_400 (0x0C)
#define MAX30102_SAMPLERATE_800 (0x10)
#define MAX30102_SAMPLERATE_1000 (0x14)
#define MAX30102_SAMPLERATE_1600 (0x18)
#define MAX30102_SAMPLERATE_3200 (0x1C)
#define MAX30102_PULSEWIDTH_MASK (0xFC)
#define MAX30102_PULSEWIDTH_69 (0x00)
#define MAX30102_PULSEWIDTH_118 (0x01)
#define MAX30102_PULSEWIDTH_215 (0x02)
#define MAX30102_PULSEWIDTH_411 (0x03)
#define MAX30102_LED_RED_PA_MASK (0xFC)
#define MAX30102_LED_RED_PA_0 (0x00)
#define MAX30102_LED_RED_PA_1 (0x01)
#define MAX30102_LED_RED_PA_2 (0x02)
#define MAX30102_LED_RED_PA_3 (0x03)
#define MAX30102_LED_RED_PA_4 (0x04)
#define MAX30102_LED_RED_PA_5 (0x05)
#define MAX30102_LED_RED_PA_6 (0x06)
#define MAX30102_LED_RED_PA_7 (0x07)
#define MAX30102_LED_RED_PA_8 (0x08)
#define MAX30102_LED_RED_PA_9 (0x09)
#define MAX30102_LED_RED_PA_10 (0x0A)
#define MAX30102_LED_RED_PA_11 (0x0B)
#define MAX30102_LED_RED_PA_12 (0x0C)
#define MAX30102_LED_RED_PA_13 (0x0D)
#define MAX30102_LED_RED_PA_14 (0x0E)
#define MAX30102_LED_RED_PA_15 (0x0F)
#define MAX30102_LED_IR_PA_MASK (0xFC)
#define MAX30102_LED_IR_PA_0 (0x00)
#define MAX30102_LED_IR_PA_1 (0x01)
#define MAX30102_LED_IR_PA_2 (0x02)
#define MAX30102_LED_IR_PA_3 (0x03)
#define MAX30102_LED_IR_PA_4 (0x04)
#define MAX30102_LED_IR_PA_5 (0x05)
#define MAX30102_LED_IR_PA_6 (0x06)
#define MAX30102_LED_IR_PA_7 (0x07)
#define MAX30102_LED_IR_PA_8 (0x08)
#define MAX30102_LED_IR_PA_9 (0x09)
#define MAX30102_LED_IR_PA_10 (0x0A)
#define MAX30102_LED_IR_PA_11 (0x0B)
#define MAX30102_LED_IR_PA_12 (0x0C)
#define MAX30102_LED_IR_PA_13 (0x0D)
#define MAX30102_LED_IR_PA_14 (0x0E)
#define MAX30102_LED_IR_PA_15 (0x0F)
#define MAX30102_EXPECTEDPARTID 0x15
#define MAX30102_EXPECTEDREVID 0x07
#define MAX30102_BUFFER_LENGTH 32
typedef struct {
uint32_t red;
uint32_t ir;
uint32_t green;
uint32_t samples;
} max30102_values;
typedef enum {
MAX30102_OK,
MAX30102_ERROR,
} max30102_status;
max30102_status max30102_init(void);
max30102_status max30102_set_mode(uint8_t mode);
max30102_status max30102_set_spo2_sample_rate(uint8_t rate);
max30102_status max30102_set_led_pulse_width(uint8_t pulse_width);
max30102_status max30102_set_led_currents(uint8_t ir_current, uint8_t red_current);
max30102_status max30102_read_fifo(max30102_values *samples);
max30102_status max30102_read_temperature(float *temperature);
#endif
```
阅读全文