#include <inttypes.h>
时间: 2024-05-31 15:06:13 浏览: 24
#include <inttypes.h>是一个头文件,它包含了一些整数类型的定义,这些整数类型具有确定的大小,可以跨平台使用。这个头文件是C99标准中引入的,它提供了一种可移植的方法来定义整数类型,避免了在不同的平台上使用不同大小的整数类型所带来的问题。
该头文件定义了以下整数类型:
1. int8_t, uint8_t:8位有符号和无符号整数类型
2. int16_t, uint16_t:16位有符号和无符号整数类型
3. int32_t, uint32_t:32位有符号和无符号整数类型
4. int64_t, uint64_t:64位有符号和无符号整数类型
5. intmax_t, uintmax_t:能够容纳机器上最大整数的有符号和无符号整数类型
这些类型的定义保证了它们在不同的平台上都具有相同的大小,从而保证了程序在不同的平台上的可移植性。
相关问题
给出<SoftwareSerial.h>
下面是 `SoftwareSerial.h` 的代码:
```c++
/*
SoftwareSerial.h - library for SoftwareSerial on AVR/Duemilanove or
Arduino with ATMega168 chips (or others with USART0)
Based on SoftwareSerial.cpp by ladyada
Ported to STM32 Arduino Core by Martino Facchin <@martino-f>
Ported to ESP8266 by Peter Lerup (@plerup)
Ported to SAMD21 by Arduino LLC
Ported to SAMD51 by Carlos Eduardo Morimoto (@cmorimoto)
Ported to nRF52 by Adafruit Industries
Ported to SAMD09 by Arduino LLC
Ported to SAMD11 by Arduino LLC
Modified by Paul Stoffregen <paul@pjrc.com> to support Teensy.
https://github.com/PaulStoffregen/SoftwareSerial/blob/master/SoftwareSerial.h
Modified by Sebastian Balzato to add support for ATtiny85.
https://github.com/sebastian-balzato/SoftwareSerial/blob/master/SoftwareSerial.h
Modified by Sandro Benigno to work with ATTinyCore and ATTiny85.
https://github.com/sandrob/SoftwareSerialATTiny
Modified by Sandro Benigno to work with ATTinyCore and ATTiny84.
https://github.com/sandrob/SoftwareSerialATtinyX4
Modified by Sandro Benigno to work with ATmega4809.
https://github.com/sandrob/SoftwareSerialATmega4809
Modified by Sandro Benigno to work with SAMD21 and SAMD51.
https://github.com/sandrob/SoftwareSerialSAM
Modified by Sandro Benigno to work with nRF52.
https://github.com/sandrob/SoftwareSerialNRF52
Modified by Sandro Benigno to work with SAML21.
https://github.com/sandrob/SoftwareSerialSAML21
Modified by Sandro Benigno to work with SAMD51 and Adafruit Grand Central.
https://github.com/sandrob/SoftwareSerialSAMD51_GC
Modified by Sandro Benigno to work with SAMC21 and Adafruit Metro M4 AirLift Lite.
https://github.com/sandrob/SoftwareSerialSAMC21_M4_AirLift_Lite
Modified by Sandro Benigno to work with SAMD21 and Adafruit Metro M4 AirLift Lite.
https://github.com/sandrob/SoftwareSerialSAM_M4_AirLift_Lite
Modified by Sandro Benigno to work with SAMD51 and Adafruit PyPortal.
https://github.com/sandrob/SoftwareSerialSAMD51_PyPortal
Modified by Sandro Benigno to work with SAMD51 and Adafruit PyGamer.
https://github.com/sandrob/SoftwareSerialSAMD51_PyGamer
Modified by Sandro Benigno to work with SAMD51 and Adafruit ItsyBitsy M4 Express.
https://github.com/sandrob/SoftwareSerialSAMD51_ItsyBitsy_M4
Modified by Sandro Benigno to work with SAMD51 and Adafruit Feather M4 Express.
https://github.com/sandrob/SoftwareSerialSAMD51_Feather_M4
Modified by Sandro Benigno to work with SAMD51 and Adafruit Metro M4 Express.
https://github.com/sandrob/SoftwareSerialSAMD51_Metro_M4
Modified by Sandro Benigno to work with SAMD21 and Seeeduino XIAO.
https://github.com/sandrob/SoftwareSerialSAMD21_XIAO
Modified by Sandro Benigno to work with SAMD51 and SparkFun SAMD51 Thing Plus.
https://github.com/sandrob/SoftwareSerialSAMD51_Thing_Plus
Modified by Sandro Benigno to work with SAMD51 and Adafruit MagTag.
https://github.com/sandrob/SoftwareSerialSAMD51_MagTag
Created by David A. Mellis <dam@mellis.org>
Modified to work with ATmega8 by M. Spiegelberg <michael@spiegelberg.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
NOTE:
Interrupts are disabled on the RX pin when using this library.
TIMING:
The library has a resolution of 4 microseconds, i.e. the delay can be increased
in 4us increments. Furthermore, the timing is related to the resolution of the
micros() function on the board. For example, on most Arduino boards, the micros()
timer has a resolution of 4us.
*/
#ifndef SoftwareSerial_h
#define SoftwareSerial_h
#include <Arduino.h>
#include <inttypes.h>
#include <Stream.h>
/******************************************************************************
* Definitions
******************************************************************************/
#define _SS_MAX_RX_BUFF 64 // RX buffer size
#define _SS_IDX_MASK (_SS_MAX_RX_BUFF - 1)
/******************************************************************************
* Class
******************************************************************************/
class SoftwareSerial : public Stream
{
private:
// per object data
uint8_t _receivePin;
uint8_t _transmitPin;
uint16_t _rx_delay_centering;
uint16_t _rx_delay_intrabit;
uint16_t _rx_delay_stopbit;
uint16_t _tx_delay;
uint16_t _buffer_overflow:1;
uint16_t _inverse_logic:1;
// static data
static uint16_t _rx_buffer_head;
static uint16_t _rx_buffer_tail;
static uint16_t _tx_buffer_head;
static uint16_t _tx_buffer_tail;
static uint8_t _tx_pin_mask;
static uint8_t _rx_pin_mask;
static volatile uint8_t * const _rx_port_register;
static volatile uint8_t * const _tx_port_register;
static uint8_t _buffer[_SS_MAX_RX_BUFF]; // RX circular buffer
// private methods
static inline void tunedDelay(uint16_t delay);
uint8_t rx_pin_read();
void setTX(uint8_t transmitPin);
void setRX(uint8_t receivePin);
void enableRx(bool on);
void enableTx(bool on);
void recv() __attribute__((__always_inline__));
void tx_pin_write(uint8_t pin_state) __attribute__((__always_inline__));
void setTXinterrupt() __attribute__((__always_inline__));
void clearTXinterrupt() __attribute__((__always_inline__));
uint8_t tx_pin_read() __attribute__((__always_inline__));
public:
// public methods
SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
~SoftwareSerial();
void begin(long speed);
void end();
int read();
int peek();
size_t write(uint8_t byte);
size_t write(const uint8_t *buffer, size_t size);
operator bool() { return true; }
using Print::write;
// public only for easy access by interrupt handlers
static inline void handle_interrupt() __attribute__((__always_inline__));
};
#endif
```
给出<Arduino.h>和<inttypes.h>和 <Stream.h>3个头文件的代码
以下是<Arduino.h>头文件的代码示例:
```c++
#ifndef Arduino_h
#define Arduino_h
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include "binary.h"
#include "itoa.h"
#include "pins_arduino.h"
#include "wiring.h"
#include "wiring_analog.h"
#include "wiring_digital.h"
#include "wiring_pulse.h"
#include "wiring_shift.h"
#include "WInterrupts.h"
#ifdef __cplusplus
extern "C"{
#endif
void setup(void);
void loop(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif
```
以下是<inttypes.h>头文件的代码示例:
```c++
#ifndef _INTTYPES_H_
#define _INTTYPES_H_
#include <stdint.h>
#define PRId8 "d"
#define PRId16 "d"
#define PRId32 "ld"
#define PRId64 "lld"
#define PRIi8 "i"
#define PRIi16 "i"
#define PRIi32 "li"
#define PRIi64 "lli"
#define PRIo8 "o"
#define PRIo16 "o"
#define PRIo32 "lo"
#define PRIo64 "llo"
#define PRIu8 "u"
#define PRIu16 "u"
#define PRIu32 "lu"
#define PRIu64 "llu"
#define PRIx8 "x"
#define PRIx16 "x"
#define PRIx32 "lx"
#define PRIx64 "llx"
#define PRIX8 "X"
#define PRIX16 "X"
#define PRIX32 "lX"
#define PRIX64 "llX"
#define PRIdPTR "ld"
#define PRIiPTR "li"
#define PRIoPTR "lo"
#define PRIuPTR "lu"
#define PRIxPTR "lx"
#define PRIXPTR "lX"
#define SCNd8 "hhd"
#define SCNd16 "hd"
#define SCNd32 "ld"
#define SCNd64 "lld"
#define SCNi8 "hhi"
#define SCNi16 "hi"
#define SCNi32 "li"
#define SCNi64 "lli"
#define SCNo8 "hho"
#define SCNo16 "ho"
#define SCNo32 "lo"
#define SCNo64 "llo"
#define SCNu8 "hhu"
#define SCNu16 "hu"
#define SCNu32 "lu"
#define SCNu64 "llu"
#define SCNx8 "hhx"
#define SCNx16 "hx"
#define SCNx32 "lx"
#define SCNx64 "llx"
#define SCNdPTR "ld"
#define SCNiPTR "li"
#define SCNoPTR "lo"
#define SCNuPTR "lu"
#define SCNxPTR "lx"
#endif
```
以下是<Stream.h>头文件的代码示例:
```c++
/*
Stream.h - library for stream base class
Copyright (C) 2006-2009 David A. Mellis
Modified 23 November 2010 by Mark Sproul
Modified 3 December 2017 by Chuck Todd
*/
#ifndef Stream_h
#define Stream_h
#include "Print.h"
#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2
class Stream : public Print
{
public:
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
virtual void flush() = 0;
};
#endif
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)