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 @@
## n-ary numbers
- 1 byte = 8 bits = [7:0]
- binary
- 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)
- 1 byte = 8 bits = 2^8 = 256 = [7:0]
- 1 B = 8 b
!!! Note
JP | EN |10 |255
-- |--- |-- |--
2進数 |Binary |0b1010 |0b11111111
10進数|Decimal |0d10 |0d255
16進数|Hexadecimal|0xA |0xff
JP | EN | usable |15 |255|255
-- |--- |-- |-- |-- |--
2進数 |Binary |0,1|0b1111 |0b11111111|B11111111
10進数|Decimal |0,1,2,3,4,5,6,7,8,9|0d15 |0d255|255
16進数|Hexadecimal|0,1,2,3,4,5,6,7,8,9,</br>A,B,C,D,E,F|0xf|0xff|$f
- 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 [ke̞ː] byte = 1024 B = 2^10 B = 1KiB = 1 [kibi] byte
......@@ -41,20 +29,69 @@
## pinout
![](../images/register/ATtiny_x14.gif)
- Pin name
- 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
signals is PORTx_PINn. All pins can be used as event input.
- PA0
- PORT A
- pin number 0
- Data Direction Register
- 16.5.1 Data Direction
- DDRA
- PORT A
- 0: input
- 1: output
## Datasheet
[ATtiny1614](http://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf)
5. I/O Multiplexing and Considerations
5.1 Multiplexed Signals
![](../images/register/PORT_Function _Multiplexing .png)
> Pin names are of type Pxn, with x being the PORT instance (A, B) and n the pin number. T``
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
......@@ -71,29 +108,28 @@ void loop() {
delay(500);
}
```
AVR
AVR 1-series
```
void setup() {
DDRB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
PORTB.DIR |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
}
void loop() {
PORTB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
PORTB.OUT |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
delay(500);
PORTB &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
PORTB.OUT &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
delay(500);
}
```
AVR 1-series
AVR
```
void setup() {
PORTB.DIR |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
DDRB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
}
void loop() {
PORTB.OUT |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
PORTB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
delay(500);
PORTB.OUT &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
PORTB &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
delay(500);
}
```
......@@ -101,18 +137,40 @@ void loop() {
Ref. [Arduinoで入出力を高速化する方法](https://haizairenmei.com/2019/11/29/avr/)
!!! HINT
// コメント
**代入**
a = 0; //初期値 代入
b = a + 1; //代入
a = a + 1; //加算代入
a += a; //加算代入
PORTB.DIR = 0b00000001; //初期値
PORTB.DIR = PORTB.DIR | 0b00000001 //OR
PORTB.DIR |= 0b00000001 //OR
<!-
DDRB = 0b000000; //初期値
DDRB = 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 1 0 1 operand2
......@@ -121,7 +179,7 @@ OR
```
1に指定したbitは、元が0でも1でも、1になる -> 指定bitのセット
NOT
### NOT
```
0 1 operand1
-----
......@@ -129,7 +187,7 @@ NOT
```
1に指定したbitは、0に反転する (0は1に反転する)
AND
### AND
```
0 0 1 1 operand1
0 1 0 1 operand2
......@@ -140,14 +198,25 @@ NOTで反転した0に指定したbitは、元が0でも1でも、0になる ->
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
}
````
|機能|演算子|使用例|
|-- |-- |-- |
|OR |``|`` |指定bitのセット|
|AND|& |指定bitの取り出し, NOTと併用した指定bitのクリア|
|XOR| ^ |bit反転|
|NOT| ~ |bit反転, bitクリア|
|ビットシフト(右)| >> |ビットシフト|
|ビットシフト(左)| << |ビットシフト|
##### (1) (2)について
```
0000 0001 operand1 (ORTB.OUT)
0000 0010 operand2
----------
0000 0011 ORTB.OUT = ORTB.OUT | operand2 = ORTB.OUT |= operand2
```
......@@ -41,7 +41,7 @@
- [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/)
- [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
- [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