Skip to content

Instantly share code, notes, and snippets.

View Jartza's full-sized avatar

Jari Tulilahti Jartza

View GitHub Profile
/*
* Common bit handling macros for AVR (avr-gcc)
*
* Examples:
*
* #define LED_DIR BITP(DDRB, PB4) // LED_DIR is "variable" pointing to single bit (PB4) in DDRB
* #define LED_STATE BITP(PORTB, PB4) // LED_STATE points to single bit (PB4) in PORTB
* LED_DIR = DIR_OUT; // Set pin as output
* LED_STATE = LEVEL_HIGH; // Switch LED on
*
/*
* Struct to handle bits in registers
*/
typedef struct {
uint8_t b0:1;
uint8_t b1:1;
uint8_t b2:1;
uint8_t b3:1;
uint8_t b4:1;
uint8_t b5:1;
@Jartza
Jartza / Makefile
Last active December 11, 2015 18:25
OBJECTS = main.o task.o
DEVICE = attiny85
CLOCK = 8000000
PROGRAMMER = -c usbasp
FUSES = -U lfuse:w:0xe2:m -U hfuse:w:0xDF:m -U efuse:w:0xFF:m -B 12
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)
all: main.hex
@Jartza
Jartza / euler67.js
Created March 15, 2015 20:40
Euler Problem 67 solver in node :)
t=require('fs').readFileSync("triangle.txt","utf8").trim().split("\n");for(f in t)i=t[f]=t[f--].split(" ");for(;1+f;)for(s in w=t[f--])i[s]=+w[s]+Math.max(i[s],i[++s]);console.log(i[0])
@Jartza
Jartza / uart.c
Last active August 29, 2015 14:13
interrupt-driven send-only uart for attiny84
/* Name: uart.c
* Author: Jari Tulilahti
*
* UART TEST
*/
#include <avr/io.h>
#include <avr/interrupt.h>
/* Helpers */
#include <avr/io.h>
start:
sbi _SFR_IO_ADDR(DDRB), 4
blink:
sbi _SFR_IO_ADDR(PINB), 4
ldi ZH, 20
loop:
t=require('fs').readFileSync("tree.txt","utf8").split("\n");for(f in t)i=t[f]=t[f--].split(" ");for(;f;)for(s in w=t[f--])i[s]=+w[s]+Math.max(i[s],i[++s]);console.log(i[0])