Created
December 30, 2018 15:51
-
-
Save recuraki/d528a7818d10bfd5095aff26a964504b to your computer and use it in GitHub Desktop.
This file contains 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
// ATTINY13A 4.8M前提 | |
#define F_CPU 4800000L | |
#define soundA 38 | |
#define soundB 47 | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
char sound; | |
char is_on = 0; | |
#define SOUND_PIN PB0 | |
#define LED_PIN PB1 | |
ISR(TIM0_COMPA_vect) | |
{ | |
cli(); | |
if(is_on == 0) | |
{ | |
PORTB ^= _BV(SOUND_PIN); | |
is_on = 1; | |
} else { | |
PORTB ^= _BV(SOUND_PIN); | |
is_on = 0; | |
} | |
sei(); | |
} | |
int main (void){ | |
PORTB=0xff; DDRB=0xff; | |
// 4:timerA割り込み許可 | |
TIMSK0 = 4; | |
OCR0A = 0; | |
TCCR0A |= _BV(WGM01); // CTC mode | |
TCCR0B |= _BV(CS01); | |
cli(); OCR0A = soundA; sei(); | |
sei(); | |
while(1){ | |
cli(); OCR0A = soundA; sei(); | |
PORTB ^= _BV(LED_PIN); | |
_delay_ms(65); | |
cli(); OCR0A = soundB; sei(); | |
PORTB ^= _BV(LED_PIN); | |
_delay_ms(65); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment