c_cpp read_ports_of_microcontroller.ino

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp read_ports_of_microcontroller.ino相关的知识,希望对你有一定的参考价值。

/**
 * see http://arduino.cc/en/Reference/PortManipulation#.Uyrot9wh6IF
 *
 * You can read what state a pin has by using bitRead and PORTD or PORTB or PORTC
 *
 * PORTD are pins 0 to 7
 * PORTB are pins 8 to 13 (bits (6 & 7) map to the crystal pins and are not usable)
 * PORTC are analog pins 0 to 5 (Pins 6 & 7 are only accessible on the Arduino Mini)
 *
 * so to get the current state of e.g. pin 13 you do a bitRead(PORTB,5)
 *
 * to get the state of pin 3 do bitRead(PORTD, 3) and so on
 */

int pin  = 13;
void setup(){
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  delay(1000);
  digitalWrite(pin, HIGH);
  Serial.println(bitRead(PORTB,5)); //Reads bit 5 of register PORTD which contains the current state (high/low) of pin 13.
  delay(1000);
  digitalWrite(pin, LOW);
  Serial.println(bitRead(PORTB,5)); //Reads bit 5 of register PORTD which contains the current state (high/low) of pin 13.

}

以上是关于c_cpp read_ports_of_microcontroller.ino的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 127.单词阶梯

c_cpp MOFSET

c_cpp MOFSET

c_cpp 31.下一个排列

c_cpp string→char *

c_cpp 54.螺旋矩阵