hdf5 目录没有serial_Arduino安装目录探秘.1

dea9be6d07f9371d32308f1ece1d6e8e.png

最近一直用Arduino写各种东西,但是也用到了许多非标准板的硬件

对于这个具体的实现过程很有兴趣,也找到了一些资料,故此做记录

这篇文章都是自我探索和经验论,并没有很多引用的资料

91f234dce069b06b442b8b9cd2cb0cba.png

首先一切的根源就是这个安装目录,所以来看看

f21d7c76c2a153b3c9e5212399931765.png

驱动嘛,都是变成了CP210了

922cca6f8fa314accbd084bcd415822c.png

用vscode也看了一眼,都是一些dll文件,我现在不想分析它

08830258eeceeb2a8e076245b2960dcc.png

这个地方是自带的示例,比较写的好,可以参考

348c536a47208667682baf6f4ee38103.png

打开一个?电压读取串口

4d0ef894f6b632d8bd74505d0e35a5dc.png

其实有大量注释,就是你别看见英文就头秃

配置段初始化了一个串口,指定了baud

然后用函数读取A0这个引脚,赋值给senorValue

接着打印出来,用了一个延时.为了稳定读取

void setup() {  // initialize serial communication at 9600 bits per second:  Serial.begin(9600);}// the loop routine runs over and over again forever:void loop() {  // read the input on analog pin 0:  int sensorValue = analogRead(A0);  // print out the value you read:  Serial.println(sensorValue);  delay(1);        // delay in between reads for stability}

24e857886d4809901e1ae4412debd4a9.png

然后一个简短的项目介绍,ReadMe吧~

97f31ae010d630e1a8c7fd567cfccc1b.png

一个是实物连接图

ed531a0a3fbe64251e9c53faa68854b5.png

一个是电路图

1293f3574a903bb8f958425da4284ebd.png

这个是程序框架

9c1a5911e7d840fa0a75fb84c5767f60.png

小灯闪烁,这个LED在13jio~,就是浪费掉了其实,完全可以引出来再用

2620f765ec3ad0277d91e57957c22894.png

这个也简单

在code的最上面指定了按下的按钮的引脚号,设置它的模式

然后代码和上面的一样

884a3ccb60ec313671237de54063c277.png

我们也可以看看这个ISP就是烧写AVR芯片进Bootloader,出现了这个Arduino.h的头文件.我们来研究一下(之后重点研究)

#ifndef Arduino_h#define Arduino_h#include #include #include #include #include #include #include #include "binary.h"#ifdef __cplusplusextern "C"{#endifvoid yield(void);#define HIGH 0x1#define LOW  0x0#define INPUT 0x0#define OUTPUT 0x1#define INPUT_PULLUP 0x2#define PI 3.1415926535897932384626433832795#define HALF_PI 1.5707963267948966192313216916398#define TWO_PI 6.283185307179586476925286766559#define DEG_TO_RAD 0.017453292519943295769236907684886#define RAD_TO_DEG 57.295779513082320876798154814105#define EULER 2.718281828459045235360287471352#define SERIAL  0x0#define DISPLAY 0x1#define LSBFIRST 0#define MSBFIRST 1#define CHANGE 1#define FALLING 2#define RISING 3#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)  #define DEFAULT 0  #define EXTERNAL 1  #define INTERNAL1V1 2  #define INTERNAL INTERNAL1V1#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)  #define DEFAULT 0  #define EXTERNAL 4  #define INTERNAL1V1 8  #define INTERNAL INTERNAL1V1  #define INTERNAL2V56 9  #define INTERNAL2V56_EXTCAP 13#else  #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)#define INTERNAL1V1 2#define INTERNAL2V56 3#else#define INTERNAL 3#endif#define DEFAULT 1#define EXTERNAL 0#endif// undefine stdlib's abs if encountered#ifdef abs#undef abs#endif#define min(a,b) ((a)#define max(a,b) ((a)>(b)?(a):(b))#define abs(x) ((x)>0?(x):-(x))#define constrain(amt,low,high) ((amt)(high)?(high):(amt)))#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))#define radians(deg) ((deg)*DEG_TO_RAD)#define degrees(rad) ((rad)*RAD_TO_DEG)#define sq(x) ((x)*(x))#define interrupts() sei()#define noInterrupts() cli()#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )#define lowByte(w) ((uint8_t) ((w) & 0xff))#define highByte(w) ((uint8_t) ((w) >> 8))#deine bitRead(value, bit) (((value) >> (bit)) & 0x01)#define bitSet(value, bit) ((value) |= (1UL << (bit)))#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))#define bitToggle(value, bit) ((value) ^= (1UL << (bit)))#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))// avr-libc defines _NOP() since 1.6.2#ifndef _NOP#define _NOP() do { __asm__ volatile ("nop"); } while (0)#endiftypedef unsigned int word;#define bit(b) (1UL << (b))typedef bool boolean;typedef uint8_t byte;void init(void);void initVariant(void);int atexit(void (*func)()) __attribute__((weak));void pinMode(uint8_t pin, uint8_t mode);void digitalWrite(uint8_t pin, uint8_t val);int digitalRead(uint8_t pin);int analogRead(uint8_t pin);void analogReference(uint8_t mode);void analogWrite(uint8_t pin, int val);unsigned long millis(void);unsigned long micros(void);void delay(unsigned long ms);void delayMicroseconds(unsigned int us);unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode);void detachInterrupt(uint8_t interruptNum);void setup(void);void loop(void);// Get the bit location within the hardware port of the given virtual pin.// This comes from the pins_*.c file for the active board configuration.#define analogInPinToBit(P) (P)// On the ATmega1280, the addresses of some of the port registers are// greater than 255, so we can't store them in uint8_t's.extern const uint16_t PROGMEM port_to_mode_PGM[];extern const uint16_t PROGMEM port_to_input_PGM[];extern const uint16_t PROGMEM port_to_output_PGM[];extern const uint8_t PROGMEM digital_pin_to_port_PGM[];// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];// Get the bit location within the hardware port of the given virtual pin.// This comes from the pins_*.c file for the active board configuration.// // These perform slightly better as macros compared to inline functions//#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )#define analogInPinToBit(P) (P)#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )#define NOT_A_PIN 0#define NOT_A_PORT 0#define NOT_AN_INTERRUPT -1#ifdef ARDUINO_MAIN#define PA 1#define PB 2#define PC 3#define PD 4#define PE 5#define PF 6#define PG 7#define PH 8#define PJ 10#define PK 11#define PL 12#endif#define NOT_ON_TIMER 0#define TIMER0A 1#define TIMER0B 2#define TIMER1A 3#define TIMER1B 4#define TIMER1C 5#define TIMER2  6#define TIMER2A 7#define TIMER2B 8#define TIMER3A 9#define TIMER3B 10#define TIMER3C 11#define TIMER4A 12#define TIMER4B 13#define TIMER4C 14#define TIMER4D 15#define TIMER5A 16#define TIMER5B 17#define TIMER5C 18#ifdef __cplusplus} // extern "C"#endif#ifdef __cplusplus#include "WCharacter.h"#include "WString.h"#include "HardwareSerial.h"#include "USBAPI.h"#if defined(HAVE_HWSERIAL0) && defined(HAVE_CDCSERIAL)#error "Targets with both UART0 and CDC serial not supported"#endifuint16_t makeWord(uint16_t w);uint16_t makeWord(byte h, byte l);#define word(...) makeWord(__VA_ARGS__)unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);void noTone(uint8_t _pin);// WMath prototypeslong random(long);long random(long, long);void randomSeed(unsigned long);long map(long, long, long, long, long);#endif#include "pins_arduino.h"#endif

53274ada999a2434d6bbb82a50b4581f.png

可以看到是定位在了这里,也有标准的C库.通过溯源

找到了最终的位置在哪里~

15301d01cc9a053c14f9a9d898b08ce8.png

3d6793f559c2c8a907a09ab65e481f85.png

对于这个Arduino的安装目录探秘还有很多要说的,但是限于篇幅

就下次再说吧.arduino大家不要小看.对于它的库,CPP味道十足

你学会了Arduino以后学传统的嵌入式开发,就会发现其实就是一个不断深入的过程.思想上面没有什么不同.只是Arduino抽象的更多,封装的更好.

但是也失去了完全可控的一些东西,总归是有得有失.不要太较真

b3185d43be171b0f9ba405ecf7594794.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值