ATTINY85 和 ATTINY84 与arduino的对应引脚

时间:2024-04-09 14:12:55

        我们在编译ATTINY85和ATTINY84的时候,特别是用arduino IDE的时候,一定要特别注意,他这个引脚都不是一一对应的。下面我们来看一下他是如何对应的呢?

        这是attiny84对应arduino引脚的表格。

        ATTINY85 和 ATTINY84 与arduino的对应引脚

所以我们在对引脚进行编程控制的时候要看清楚对应的引脚。

        下面是attiny85的表格:

ATTINY85 和 ATTINY84 与arduino的对应引脚

好,现在我们来试一下串口:

#include "SoftwareSerial.h"

const int Rx = 3; 

const int Tx = 4;

SoftwareSerial mySerial(Rx, Tx);

void setup()

{ pinMode(Rx, INPUT);

pinMode(Tx, OUTPUT);

mySerial.begin(9600); 

void loop()

{ mySerial.println(val); }

注意,由于这个单片机没有串口,所以我们只能使用软串口实现串口的功能,但是注意,波特率不要设的太高,9600就可以了。设置的太高,软串口可能会读写出错。

下面是85的软串口测试程序:

#include "SoftwareSerial.h"

const int LED = 1; // this is physical pin 6 for the LED

const int ANTENNA = 2; // this is physical pin 7, connect wire as antenna

const int Rx = 3; // this is physical pin 2

const int Tx = 4; // this is physical pin 3

SoftwareSerial mySerial(Rx, Tx);

int val = 0; // variable to store antenna readings

void setup()

{

pinMode(LED, OUTPUT); // tell Arduino LED is an output

pinMode(Rx, INPUT);

pinMode(Tx, OUTPUT);

mySerial.begin(9600); // send serial data at 9600 bits/sec

}

void loop()

{

digitalWrite(LED, HIGH); // turn LED ON

delay(500);

digitalWrite(LED, LOW); // turn off

delay(500);

val = analogRead(ANTENNA); // read the ANTENNA

mySerial.println(val); // send the value to Serial Monitor, ^Cmd-M

digitalWrite(LED, HIGH); // turn LED ON

delay(10); digitalWrite(LED, LOW); // turn off

delay(500);

}

下面是attiny84的串口程序,来对比一下:

#include "SoftwareSerial.h"

const int LED = 5; // this is physical pin 8 for the LED

const int ANTENNA = 1; // this is physical pin 12, connect wire as antenna

const int Rx = 7; // this is physical pin 6

const int Tx = 6; // this is physical pin 7

SoftwareSerial mySerial(Rx, Tx);

int val = 0; // variable to store antenna readings

void setup()

{

pinMode(LED, OUTPUT); // tell Arduino LED is an output

pinMode(Rx, INPUT);

pinMode(Tx, OUTPUT);

mySerial.begin(9600); // send serial data at 9600 bits/sec

}

void loop()

{

digitalWrite(LED, HIGH); // turn LED ON

delay(500);

digitalWrite(LED, LOW); // turn off

delay(500);

val = analogRead(ANTENNA); // read the ANTENNA

mySerial.println(val); // send the value to Serial Monitor, ^Cmd-M

digitalWrite(LED, HIGH); // turn LED ON

delay(10);

digitalWrite(LED, LOW); // turn off

delay(500);

}

以上程序来自于:http://www.instructables.com/id/ATtiny85-ATtiny84-Analog-Pins-Serial-Communication/