Skip to content
Snippets Groups Projects
Commit 2498a368 authored by yuichitamiya's avatar yuichitamiya
Browse files

fix tips resistor bit

parent 3374906b
No related branches found
No related tags found
No related merge requests found
Pipeline #290755 passed
docs/Instruction/images/register/PORT_Function _Multiplexing .png

386 KiB

docs/Instruction/images/register/Register_Summary-PORTx.png

226 KiB

...@@ -6,32 +6,20 @@ ...@@ -6,32 +6,20 @@
## n-ary numbers ## n-ary numbers
- 1 byte = 8 bits = [7:0] - 1 byte = 8 bits = 2^8 = 256 = [7:0]
- binary - 1 B = 8 b
- 2進数(0,1)
- 0b00001111
- B00001111
- hexadecimal
- 16進数(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
- 0xFF
- $FF
- decimal
- 10進数(0,1,2,3,4,5,6,7,8,9)
- 0d255
- 255
- ref. [2進数、8進数、10進数、16進数相互変換ツール](https://hogehoge.tk/tool/number.html)
!!! Note JP | EN | usable |15 |255|255
JP | EN |10 |255 -- |--- |-- |-- |-- |--
-- |--- |-- |-- 2進数 |Binary |0,1|0b1111 |0b11111111|B11111111
2進数 |Binary |0b1010 |0b11111111 10進数|Decimal |0,1,2,3,4,5,6,7,8,9|0d15 |0d255|255
10進数|Decimal |0d10 |0d255 16進数|Hexadecimal|0,1,2,3,4,5,6,7,8,9,</br>A,B,C,D,E,F|0xf|0xff|$f
16進数|Hexadecimal|0xA |0xff
- Ref. [2進数、8進数、10進数、16進数相互変換ツール](https://hogehoge.tk/tool/number.html)
1 byte = 8 bits = 2^8 = 256
1B = 8b
!!! Note
1**k**B = 1 [kilo] byte = 1000 B 1**k**B = 1 [kilo] byte = 1000 B
1**K**B = 1 [ke̞ː] byte = 1024 B = 2^10 B = 1KiB = 1 [kibi] byte 1**K**B = 1 [ke̞ː] byte = 1024 B = 2^10 B = 1KiB = 1 [kibi] byte
...@@ -41,20 +29,69 @@ ...@@ -41,20 +29,69 @@
## pinout ## pinout
![](../images/register/ATtiny_x14.gif) ![](../images/register/ATtiny_x14.gif)
- Pin name ## Datasheet
- 5.1 Multiplexed Signals(page18)
- Pin names are of type Pxn, with x being the PORT instance (A, B) and n the pin number. The notation for [ATtiny1614](http://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf)
signals is PORTx_PINn. All pins can be used as event input.
- PA0
- PORT A 5. I/O Multiplexing and Considerations
- pin number 0 5.1 Multiplexed Signals
- Data Direction Register ![](../images/register/PORT_Function _Multiplexing .png)
- 16.5.1 Data Direction
- DDRA > Pin names are of type Pxn, with x being the PORT instance (A, B) and n the pin number. T``
- PORT A
- 0: input
- 1: output 16 . PORT - I/O Pin Configuration
16.1 Features
General Purpose Input and Output Pins with Individual Configuration:
– Pull-up
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.**
>
> **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.**
16.4 Register Summary - PORTx
![](../images/register/Register_Summary-PORTx.png)
16.5.1 Data Direction
> Name: DIR
> This bit field controls the output driver for each PORTx pin.
Value |Description
:--:|:--
0 |Pxn is configured as an input-only pin, and the output driver is disabled
1 |Pxn is configured as an output pin, and the output driver is enabled
16.5.5 Output Value
> Name: OUT
> This bit field controls the output driver level for each PORTx pin.
Value |Description
:--:|:--
0 |The pin n (Pxn) output is driven low
1 |The Pxn output is driven high
16.5.9 Input Value
> Name: IN
> This bit field shows the state of the PORTx pins when the digital input buffer is enabled
Value |Description
:--:|:--
0 |The voltage level on Pxn is low
1 |The voltage level on Pxn is high
## Program ## Program
...@@ -71,29 +108,28 @@ void loop() { ...@@ -71,29 +108,28 @@ void loop() {
delay(500); delay(500);
} }
``` ```
AVR 1-series
AVR
``` ```
void setup() { void setup() {
DDRB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT PORTB.DIR |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
} }
void loop() { void loop() {
PORTB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH PORTB.OUT |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
delay(500); delay(500);
PORTB &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW PORTB.OUT &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
delay(500); delay(500);
} }
``` ```
AVR 1-series AVR
``` ```
void setup() { void setup() {
PORTB.DIR |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT DDRB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
} }
void loop() { void loop() {
PORTB.OUT |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH PORTB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
delay(500); delay(500);
PORTB.OUT &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW PORTB &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
delay(500); delay(500);
} }
``` ```
...@@ -101,18 +137,40 @@ void loop() { ...@@ -101,18 +137,40 @@ void loop() {
Ref. [Arduinoで入出力を高速化する方法](https://haizairenmei.com/2019/11/29/avr/) Ref. [Arduinoで入出力を高速化する方法](https://haizairenmei.com/2019/11/29/avr/)
!!! HINT !!! HINT
// コメント
**代入**
a = 0; //初期値 代入 a = 0; //初期値 代入
b = a + 1; //代入 b = a + 1; //代入
a = a + 1; //加算代入 a = a + 1; //加算代入
a += a; //加算代入 a += a; //加算代入
PORTB.DIR = 0b00000001; //初期値
PORTB.DIR = PORTB.DIR | 0b00000001 //OR
PORTB.DIR |= 0b00000001 //OR
<!-
DDRB = 0b000000; //初期値 DDRB = 0b000000; //初期値
DDRB = DDRB | 0b00000001; //OR DDRB = DDRB | 0b00000001; //OR
DDRB |= 0b00000001; //OR DDRB |= 0b00000001; //OR
->
## Bitwise Operators (bit演算子)
機能|演算子|使用例
-- |-- |--
OR |``|`` |指定bitのセット
AND |& |指定bitの取り出し, NOTと併用した指定bitのクリア
XOR | ^ |bit反転
NOT | ~ |bit反転, bitクリア
ビットシフト(右)| >> |ビットシフト
ビットシフト(左)| << |ビットシフト
!!! Note
operand: 被演算子
OR ### OR
``` ```
0 0 1 1 operand1 0 0 1 1 operand1
0 1 0 1 operand2 0 1 0 1 operand2
...@@ -121,7 +179,7 @@ OR ...@@ -121,7 +179,7 @@ OR
``` ```
1に指定したbitは、元が0でも1でも、1になる -> 指定bitのセット 1に指定したbitは、元が0でも1でも、1になる -> 指定bitのセット
NOT ### NOT
``` ```
0 1 operand1 0 1 operand1
----- -----
...@@ -129,7 +187,7 @@ NOT ...@@ -129,7 +187,7 @@ NOT
``` ```
1に指定したbitは、0に反転する (0は1に反転する) 1に指定したbitは、0に反転する (0は1に反転する)
AND ### AND
``` ```
0 0 1 1 operand1 0 0 1 1 operand1
0 1 0 1 operand2 0 1 0 1 operand2
...@@ -140,14 +198,25 @@ NOTで反転した0に指定したbitは、元が0でも1でも、0になる -> ...@@ -140,14 +198,25 @@ NOTで反転した0に指定したbitは、元が0でも1でも、0になる ->
ref. [Arduino Language Reference](https://www.arduino.cc/reference/en/) ref. [Arduino Language Reference](https://www.arduino.cc/reference/en/)
## Example
Bitwise Operators (bit演算子) ````
void setup() {
PORTB.DIR |= 0b00000011; //PB0とPB1をOUTPUTに設定
}
void loop() {
PORTB.OUT |= 0b00000001; //PB0をHIGH...(1)
delay(500);
PORTB.OUT |= 0b00000010; //PB1をHIGH (PB0もHIGHのまま)...(2)
delay(500);
PORTB.OUT |= 0b00000011; //PB0,PB1をLOW
}
````
|機能|演算子|使用例| ##### (1) (2)について
|-- |-- |-- | ```
|OR |``|`` |指定bitのセット| 0000 0001 operand1 (ORTB.OUT)
|AND|& |指定bitの取り出し, NOTと併用した指定bitのクリア| 0000 0010 operand2
|XOR| ^ |bit反転| ----------
|NOT| ~ |bit反転, bitクリア| 0000 0011 ORTB.OUT = ORTB.OUT | operand2 = ORTB.OUT |= operand2
|ビットシフト(右)| >> |ビットシフト| ```
|ビットシフト(左)| << |ビットシフト|
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
- [ATtiny1614 hello buzzer board](http://tatsuro.homma.fabcloud.io/fabacademy/tips/electronics_design/ATtiny1614_hello_buzzer/) - [ATtiny1614 hello buzzer board](http://tatsuro.homma.fabcloud.io/fabacademy/tips/electronics_design/ATtiny1614_hello_buzzer/)
- [Step Response / CapacitiveSensor](http://academany.fabcloud.io/fabacademy/2021/labs/kannai/site/instruction/tips/step_response/) - [Step Response / CapacitiveSensor](http://academany.fabcloud.io/fabacademy/2021/labs/kannai/site/instruction/tips/step_response/)
- [Write C language program to AVR-1 series](http://tatsuro.homma.fabcloud.io/fabacademy/tips/embedded_programming/write_c_program_to_avr1/) - [Write C language program to AVR-1 series](http://tatsuro.homma.fabcloud.io/fabacademy/tips/embedded_programming/write_c_program_to_avr1/)
- [Register_bit](./tips/register_bit.md) - [Register bit](./tips/register_bit.md)
## Other Tips list ## Other Tips list
- [Tips List 2021](http://academany.fabcloud.io/fabacademy/2021/labs/kannai/site/instruction/tips_list/) - [Tips List 2021](http://academany.fabcloud.io/fabacademy/2021/labs/kannai/site/instruction/tips_list/)
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