Skip to content

Instantly share code, notes, and snippets.

@dagon666
dagon666 / Makefile
Created September 21, 2013 21:09
Pure C Arduino generic Makefile
TARGET=blink
SOURCES=blink.c
DEPS=
COBJ=$(SOURCES:.c=.o)
CC=avr-gcc
OBJC=avr-objcopy
MCU=atmega328p
CFLAGS=-I. -Wall -Os -DF_CPU=16000000UL
LDFLAGS=
@dagon666
dagon666 / blink.c
Created September 21, 2013 21:15
Blink Demo
@dagon666
dagon666 / dummy.h
Created September 25, 2013 18:43
dummy library interface
#ifndef _DUMMY_H_
#define _DUMMY_H_
// prototype
void portb_high();
#endif
@dagon666
dagon666 / dummy.c
Created September 25, 2013 18:44
dummy library implementation
#include "dummy.h"
#include "avr/io.h"
void portb_high() {
portb = 0xff;
}
@dagon666
dagon666 / main.c
Created September 25, 2013 18:49
dummy library example program
#include "dummy.h"
int main(void) {
portb_high();
return 0;
}
@dagon666
dagon666 / tdelay_ms.c
Created September 26, 2013 20:59
Arduino Timer Delay example
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/power.h>
#define F_CPU 16000000UL
static volatile uint32_t duration = 0x00;
ISR(TIMER0_COMPA_vect) {
@dagon666
dagon666 / Makefile
Created September 26, 2013 21:18
tdelay with libpca
TARGET=delay_tests
SOURCES=main.c
DEPS=
COBJ=$(SOURCES:.c=.o)
PCA_PREFIX=../pca
CC=avr-gcc
OBJC=avr-objcopy
@dagon666
dagon666 / Makefile
Last active November 27, 2022 00:07
generating tones with Atmega328p's timer
TARGET=beeper
SOURCES=beeper.c
DEPS=
COBJ=$(SOURCES:.c=.o)
CC=avr-gcc
OBJC=avr-objcopy
MCU=atmega328p
CFLAGS=-I. -Wall -Os -DF_CPU=16000000UL -std=c99
@dagon666
dagon666 / prescaler.c
Created September 30, 2013 20:19
prescaler calculation atmega328p
// system clock frequency
#define F_CPU 16000000UL
void timer_freq_prescale(uint32_t a_freq, uint8_t *a_ocr, uint8_t *a_prescaler) {
// prescaler table for timer 0
uint8_t prescalers[] = { 0x00, 0x03, 0x06, 0x08, 0x0a, 0x00 };
uint16_t ocr = 0x00;
@dagon666
dagon666 / pocr_test.c
Created September 30, 2013 20:23
calculating prescaler and ocr values offline
#include <stdio.h>
#include <stdint.h>
// system clock frequency
#define F_CPU 16000000UL