Skip to content

Instantly share code, notes, and snippets.

View ricardas's full-sized avatar

ricardas ricardas

  • Lithuania
View GitHub Profile
@ricardas
ricardas / usart.c
Created December 24, 2012 01:21
Atmega328: USART
#ifndef F_CPU
#define F_CPU 16000000
#endif
#include <avr/io.h>
#include <util/delay.h>
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
@ricardas
ricardas / eeprom.c
Created December 24, 2012 01:20
Atmega328: EEPROM
#include <avr/io.h>
void EEPROM_write(unsigned int uiAddress, unsigned char ucData) {
while(EECR & (1 << EEPE));
EEAR = uiAddress;
EEDR = ucData;
EECR |= 1 << EEMPE;
EECR |= 1 << EEPE;
}
@ricardas
ricardas / adc.c
Created December 24, 2012 01:19
Atmega16: ADC
// chip: atmega16
#include <avr/io.h>
void ADC_init() {
ADMUX = 1 << REFS0;
ADCSRA = 1 << ADEN | 1 << ADSC | 1 << ADATE | 7 << ADPS0;
}
@ricardas
ricardas / usart.c
Created December 24, 2012 01:15
Atmega16: USART
// chip: atmega16
#ifndef F_CPU
#define F_CPU 16000000
#endif
#include <avr/io.h>
#include <util/delay.h>
#define BAUD 9600