天天看點

ATTINY85 和 ATTINY84 與arduino的對應引腳

        我們在編譯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/