main()関数が未定義の場合はArduinoのようにsetup()/loop()関数が呼び出され、処理待ちのときにライブラリ(ADC/RTC/TWI/USART)内から呼び出されるavr8_yield()関数をサポートするライブラリ。
avr8_yield()はmain.cppなどにavr8_yield()を定義したときにだけ呼び出される。
【サンプルコード (Microchip Studio)】
|
1 2 3 4 5 6 7 8 9 10 11 |
#include "avr8_xxxx.h" void avr8_yield(void) { /* 処理待ちのときライブラリ内から呼び出される */ } int main(void) { ... } |
【サンプルコード (Microchip Studio or Arduino)】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include "avr8_xxxx.h" void avr8_yield(void) { /* 処理待ちのときライブラリ内から呼び出される */ } void setup(void) { ... } void loop(void) { ... } |
【ライブラリ】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* avr8_main.h - main routine Copyright (c) 2025 Sasapea's Lab. All right reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ #pragma once extern void avr8_yield(void); |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/* avr8_main.cpp - main routine Copyright (c) 2025 Sasapea's Lab. All right reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include "avr8_main.h" void avr8_yield(void) __attribute__((weak)); void avr8_yield(void) { } void yield(void) { avr8_yield(); } void setup(void) __attribute__((weak)); void setup(void) { } void loop(void) __attribute__((weak)); void loop(void) { } int main(void) __attribute__((weak)); int main(void) { setup(); while (1) { loop(); avr8_yield(); } return 0; } |
【関連投稿】
Microchip AVR8 用のライブラリを自作する。(GPIO)
Microchip AVR8 用のライブラリを自作する。(FUSE)
Microchip AVR8 用のライブラリを自作する。(CLOCK)
Microchip AVR8 用のライブラリを自作する。(RESET)
Microchip AVR8 用のライブラリを自作する。(PORTMUX)
Microchip AVR8 用のライブラリを自作する。(USART)
Microchip AVR8 用のライブラリを自作する。(RTC)
Microchip AVR8 用のライブラリを自作する。(TCA)
Microchip AVR8 用のライブラリを自作する。(TCB)
Microchip AVR8 用のライブラリを自作する。(VREF)
Microchip AVR8 用のライブラリを自作する。(DAC)
Microchip AVR8 用のライブラリを自作する。(AC)
Microchip AVR8 用のライブラリを自作する。(ADC)
Microchip AVR8 用のライブラリを自作する。(ZCD)
Microchip AVR8 用のライブラリを自作する。(SPI)
Microchip AVR8 用のライブラリを自作する。(TWI)
Microchip AVR8 用のライブラリを自作する。(MAIN)
Microchip AVR8 用のライブラリを自作する。(CONFIG)
