Skip to content
Snippets Groups Projects
Commit 3b654a52 authored by yuichitamiya's avatar yuichitamiya
Browse files

fix tips register bit

parent 2498a368
No related branches found
No related tags found
No related merge requests found
Pipeline #290770 passed
......@@ -50,7 +50,7 @@
16.2 Overview
> The I/O pins of the device are controlled by instances of the PORT peripheral registers. **Each PORT instance has up to eight I/O pins. The PORTs are named PORTA, PORTB, PORTC, etc.**
> The I/O pins of the device are controlled by instances of the PORT peripheral registers. **Each PORT instance has up to eight I/O pins. The PORTs are named PORTA, PORTB, PORTC, etc.**
>
> **Each PORT pin has a corresponding bit in the Data Direction (PORTx.DIR) and Data Output Value (PORTx.OUT)** registers to enable that pin as an output and to define the output state. For example, **pin PA3 is controlled by DIR[3]
and OUT[3] of the PORTA instance.**
......@@ -108,15 +108,15 @@ void loop() {
delay(500);
}
```
AVR 1-series
AVR 1-series (1614)
```
void setup() {
PORTB.DIR |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
PORTA.DIR |= 0b00000001;//ポートAの0番ピン(Arduinoの11番ピン)をOUTPUT
}
void loop() {
PORTB.OUT |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
PORTA.OUT |= 0b00000001;//ポートAの0番ピン(Arduinoの11番ピン)をHIGH
delay(500);
PORTB.OUT &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
PORTA.OUT &= ~0b00000001;//ポートAの0番ピン(Arduinoの11番ピン)をLOW
delay(500);
}
```
......@@ -124,12 +124,12 @@ void loop() {
AVR
```
void setup() {
DDRB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
DDRB |= 0b00000001;//ポートBの0番ピン(Arduinoのn番ピン)をOUTPUT
}
void loop() {
PORTB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
PORTB |= 0b00000001;//ポートBの0番ピン(Arduinoのn番ピン)をHIGH
delay(500);
PORTB &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
PORTB &= ~0b00000001;//ポートBの0番ピン(Arduinoのn番ピン)をLOW
delay(500);
}
```
......@@ -144,10 +144,10 @@ Ref. [Arduinoで入出力を高速化する方法](https://haizairenmei.com/2019
a = a + 1; //加算代入
a += a; //加算代入
**OR**
PORTB.DIR = 0b00000001; //初期値
PORTB.DIR = PORTB.DIR | 0b00000001 //OR
PORTB.DIR |= 0b00000001 //OR
PORTB.DIR = PORTB.DIR | 0b00010000 //OR
PORTB.DIR **|=** 0b00010000 //OR
<!-
DDRB = 0b000000; //初期値
......@@ -200,23 +200,44 @@ ref. [Arduino Language Reference](https://www.arduino.cc/reference/en/)
## Example
````
```
void setup() {
PORTB.DIR |= 0b00000011; //PB0とPB1をOUTPUTに設定
PORTA.DIR |= 0b00010001; //Set PA4 and PA0 to OUTPUT
}
void loop() {
PORTB.OUT |= 0b00000001; //PB0をHIGH...(1)
PORTA.OUT |= 0b00000001; //Set PA0 to HIGH...(1)
delay(500);
PORTB.OUT |= 0b00000010; //PB1をHIGH (PB0もHIGHのまま)...(2)
PORTA.OUT |= 0b00010000; //Set PA4 to HIGH...(2)
delay(500);
PORTB.OUT |= 0b00000011; //PB0,PB1をLOW
PORTA.OUT &= ~0b00000001; //Set PA0 to LOW....(3)
}
````
```
### What to work in (1)(2)(3)
##### (1) (2)について
```
0000 0001 operand1 (ORTB.OUT)
0000 0010 operand2
----------
0000 0011 ORTB.OUT = ORTB.OUT | operand2 = ORTB.OUT |= operand2
(1) OR
0000 0000 operand1_1
0000 0001 operand1_2
---------
0000 0001 (operand1_1 | operand1_2) - returned result1
(2) OR
0000 0001 operand2_1 (returned result1)
0001 0000 operand2_2
---------
0001 0001 (operand2_1 | operand2_2) - returned result2
(3)
(3-1) NOT
0000 0001 operand3_1
---------
1111 1110 ~operand3_1
(3-2) AND
0001 0001 ~operand3_2 (returned result2)
1111 1110 operand3_1
---------
0001 0000 (~operand3_1 & operand3_2) - returned result3
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment