From 3b654a5240ebf6e282ba67986287e8234472e015 Mon Sep 17 00:00:00 2001 From: yuichitamiya <y2miyacatsfab@gmail.com> Date: Tue, 22 Mar 2022 12:49:45 +0900 Subject: [PATCH] fix tips register bit --- docs/Instruction/tips/register_bit.md | 65 ++++++++++++++++++--------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/docs/Instruction/tips/register_bit.md b/docs/Instruction/tips/register_bit.md index d89eba1..f80ed45 100644 --- a/docs/Instruction/tips/register_bit.md +++ b/docs/Instruction/tips/register_bit.md @@ -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 + ``` -- GitLab