pinMode(), digitalWrite() などは使えず、マイクロコントローラのレジスタなど設定せねばなりません。pinMode() は DDRB レジスタ、digitalWrite() は PORTB などのレジスタを設定することで実装できます。
割り込みなどは MCUCR, GIMSK レジスタを設定し、割り込みを許可せねばなりません。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Interrupt.cpp | |
* | |
* Created: 6/2/2016 5:05:28 PM | |
* Author : easai | |
*/ | |
#define F_CPU 1000000UL | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
ISR(INT0_vect) | |
{ | |
PORTB |= (1<< DDB0); | |
_delay_ms(10000); | |
PORTB &= ~(1<< DDB0); | |
} | |
int main(void) | |
{ | |
DDRB |= (1<<DDB0); | |
MCUCR |= (1<<ISC01); | |
GIMSK |= (1<<INT0); | |
sei(); | |
while (1){} | |
return 0; | |
} | |
ATtiny13A では PWM 出力が可能ですが、これも TCCR0A, TCCR0B レジスタを設定し、デューティ比を OCR0A, OCR0B などで設定します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* PWM.cpp | |
* | |
* Created: 6/3/2016 8:59:58 AM | |
* Author : easai | |
*/ | |
#define F_CPU 1000000UL | |
#include <avr/io.h> | |
#include <util/delay.h> | |
int main(void) | |
{ | |
DDRB |= 0b00011; | |
TCCR0A = (1<<COM0A1) | (1<< COM0B0) | (1<< COM0B1) | (1 << WGM01) | (1 << WGM00); | |
OCR0A = 0; | |
OCR0B=0; | |
TCCR0B = (1<<CS00); | |
while (1) | |
{ | |
OCR0A+=10; | |
if(255<=OCR0A) | |
{ | |
OCR0A=0; | |
} | |
OCR0B=OCR0A; | |
_delay_ms(500); | |
} | |
return 0; | |
} | |
ATtiny13A の良さといえば、省電力で省スペース、低価格であること。活用しましょう。