added blink example

This commit is contained in:
Sven Vogel 2023-10-27 17:52:40 +02:00
parent 5acf874583
commit 163e31908f
6 changed files with 101 additions and 0 deletions

16
include/bits.h Normal file
View File

@ -0,0 +1,16 @@
//
// Created by servostar on 27.10.23.
//
#ifndef ARDUINO_BITS_H
#define ARDUINO_BITS_H
#define SET_BIT(field, idx) ((field) |= (1 << (idx)))
#define CLR_BIT(field, idx) ((field) &= ~(1 << (idx)))
#define TOG_BIT(field, idx) ((field) ^= (1 << (idx)))
#define GET_BIT(field, idx) (((field) >> idx) & 0x1)
#define SET_OUTPUT(port, pin) SET_BIT(port, pin)
#define SET_INPUT(port, pin) CLR_BIT(port, pin)
#endif //ARDUINO_BITS_H

17
include/interrupt.h Normal file
View File

@ -0,0 +1,17 @@
//
// Created by servostar on 27.10.23.
//
#ifndef ARDUINO_INTERRUPT_H
#define ARDUINO_INTERRUPT_H
#define LOW 0b00
#define CHANGE 0b01
#define FALLING 0b10
#define RISING 0b11
#define SET_INTERRUPT_MODE(index, mode) EICRA = (EICRA & (252 << (index) * 2)) | (mode) << (index) * 2
#define ENABLE_INTERRUPT(index) SET_BIT(EIMSK, index)
#define DISABLE_INTERRUPT(index) CLR_BIT(EIMSK, index)
#endif //ARDUINO_INTERRUPT_H

19
include/prelude.h Normal file
View File

@ -0,0 +1,19 @@
//
// Created by servostar on 27.10.23.
//
#ifndef ARDUINO_PRELUDE_H
#define ARDUINO_PRELUDE_H
// set clock frequency to 16MHz
#define F_CPU 16000000UL
#include "avr/io.h"
#include "avr/interrupt.h"
#include "util/delay.h"
// custom header files
#include "bits.h"
#include "interrupt.h"
#endif //ARDUINO_PRELUDE_H

21
src/blink/blink.cpp Normal file
View File

@ -0,0 +1,21 @@
//
// Created by servostar on 27.10.23.
//
#include "blink.h"
#ifdef BLINK
void init() {
DDRB = 0x20;
PORTB = 0x20;
}
void loop() {
PORTB |= 0x20;
_delay_ms(500);
PORTB &= ~0x20;
_delay_ms(500);
}
#endif

13
src/blink/blink.h Normal file
View File

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

15
src/main.cpp Normal file
View File

@ -0,0 +1,15 @@
extern void init();
extern void loop();
#include "blink/blink.h"
#define BLINK
int main() {
init();
for (;;) {
loop();
}
}