added advanced interrupt handler

This commit is contained in:
Sven Vogel 2023-10-31 13:18:52 +01:00
parent bc915a7a3f
commit 6eaf4518fa
6 changed files with 88 additions and 10 deletions

View File

@ -17,6 +17,8 @@ build_src_filter =
-<.git/>
-<.svn/>
-<blink/>
-<button_interrupt/>
-<button_interupt/>
-<button_poll/>
-<trafficlight/>
-<summer/>
+<summer_controlled/>

View File

@ -4,8 +4,6 @@
#include "button.h"
#ifdef BUTTON_INTERRUPT
ISR(INT0_vect)
{
PORTB = 0;
@ -43,5 +41,3 @@ void init() {
void loop() {
}
#endif

View File

@ -6,7 +6,8 @@ extern void loop();
//#include "button_poll/button.h"
//#include "button_interupt/button.h"
//#include "trafficlight/trafficlight.h"
#include "summer/summer.h"
//#include "summer/summer.h"
#include "summer_controlled/summer.h"
int main() {
init();

View File

@ -15,13 +15,14 @@ void init() {
TCCR0A |= (1 << WGM01); // set timer to CTC
OCR0A = 0x70; // count up to this value
OCR0A = 0x70; // count up to this value 440Hz
// OCR0A = 0x117; // count up to this value 265Hz
TIMSK0 |= (1 << OCIE0A); // enable timer 0
sei(); // enable interrupts
TCCR0B |= (1 << CS02) | (1 << CS00); // start timer and set prescaler to 1024
TCCR0B |= (1 << CS02); // start timer and set prescaler to 256
sei(); // enable interrupts
}
void loop() {

View File

@ -0,0 +1,65 @@
//
// Created by servostar on 30.10.23.
//
#include "summer.h"
void setup_summer_it();
void setup_button_it();
ISR (TIMER0_COMPA_vect)
{
PORTB = ~PORTB;
}
ISR(INT0_vect)
{
OCR0A = 18; // count up to this value 440Hz
}
ISR(INT1_vect)
{
OCR0A = 30; // count up to this value 265Hz
}
void init() {
setup_summer_it();
setup_button_it();
sei(); // enable interrupts
}
void setup_button_it() {
// set Port D to input (bit 2/3, remember bit 0/1 are for UART)
SET_INPUT(DDRD, DDD2);
SET_INPUT(DDRD, DDD3);
// put 5V on input (make it pull up resistor)
SET_BIT(PORTD, DDD2);
SET_BIT(PORTD, DDD3);
// configure interrupt mode
SET_INTERRUPT_MODE(0, FALLING);
SET_INTERRUPT_MODE(1, FALLING);
// enable interrupt 0 and 1
ENABLE_INTERRUPT(0);
ENABLE_INTERRUPT(1);
}
void setup_summer_it() {
DDRB = 255;
PORTB = 0;
TCCR0A |= (1 << WGM01); // set timer to CTC
OCR0A = 0x70; // count up to this value 440Hz
// OCR0A = 0x117; // count up to this value 265Hz
TIMSK0 |= (1 << OCIE0A); // enable timer 0
TCCR0B |= (1 << CS02) | (1 << CS00); // start timer and set prescaler to 1024
}
void loop() {
}

View File

@ -0,0 +1,13 @@
//
// Created by servostar on 30.10.23.
//
#ifndef ARDUINO_SUMMER_H
#define ARDUINO_SUMMER_H
#include "prelude.h"
void init();
void loop();
#endif //ARDUINO_SUMMER_H