This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* pwm_1khz_02.c ATmega88 @ 1MHz */ | |
#include <avr/io.h> | |
int main(void) | |
{ | |
DDRB |= (1<<PB1); // OC1A = output | |
ICR1 = 1000; // Top Value = 1000 | |
OCR1A = 700; // Compare Match bei 700 | |
// Clear OC1A on Compare Match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* pwm_1khz_01.c ATmega88 @ 1MHz */ | |
#include <avr/io.h> | |
int main(void) | |
{ | |
DDRB |= (1<<PB2); // OC1B = output | |
OCR1A = 999; // Top value = 999 | |
OCR1B = 300; // Compare Match bei 300 | |
// Clear OC1B on Compare Match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* fast_pwm_02.c ATmega88 @ 1MHz */ | |
#include <avr/io.h> | |
int main(void) | |
{ | |
DDRB |= (1<<PB1); // OC1A = output | |
DDRB |= (1<<PB2); // OC1B = output | |
OCR1A = 307; // Compare match bei 307 = 30% Duty Cycle | |
OCR1B = 716; // Compare match bei 716 = 70% Duty Cycle | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* fast_pwm_01.c ATmega88 @ 8MHz */ | |
#include <avr/io.h> | |
int main(void) | |
{ | |
DDRB |= (1<<PB1); // OC1A = output | |
OCR1A = 307; // Compare match bei 307 = 30% Duty Cycle | |
TCCR1A = (1 << COM1A1) + (1 << WGM11) + (1 << WGM10); // Lösche OC1A @ Compare Match | |
TCCR1B = (1 << WGM12) + (1 << CS11); // Mode 7, Fast PWM 10-bit, Prescaler = 8 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* rectangle_01.c | |
* Ein 100Hz Rechtecksignal am OC1A (Pin 15) erzeugen | |
* Controller: ATmega88 @ 1MHz */ | |
#include <avr/io.h> | |
int main(void) | |
{ | |
DDRB |= (1<<PB1); // OC1A = output | |
OCR1A = 39999; // Compare match auf 39999 setzen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* timer_ctc_mode_01.c ATmega88 @ 8MHz */ | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#define LED (1<<PB3) // LED auf Portpin B3 | |
int main(void) | |
{ | |
DDRB |= (1<<PB3); // Portpin B3 = output | |
TCCR1B |= (1 << CS12); // Vorteiler auf 256 und Timer start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* timer_normal_mode_01.c ATmega88 @ 8MHz */ | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#define preload_value 64536 // Timer1 Vorladewert | |
void init_timer_1 (void) | |
{ | |
TCCR1A = 0x00; // Timer1 Normal Mode (Mode 0) | |
TCCR1B = (1<<CS11); // Prescaler = 8 -> 8Mhz/8 = 1MHz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* lauflicht_sr_02.c ATmega88 @ 8MHz */ | |
int main(void) | |
{ | |
DDRD = 0xFF; // Richtungsregister PORTD = Ausgang | |
PORTD = 0x04; // PD2 (RCK) = High, 0x04 = 0000 0100 | |
uint8_t k, data = 0x01; // data = 0000 0001 | |
while(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* lauflicht_sr_01.c ATmega88 @ 8MHz */ | |
#include <avr/io.h> | |
#include <util/delay.h> | |
void soft_serial (uint8_t data) // Funktion soft_serial | |
{ | |
for (uint8_t i=0; i<=7; i++) | |
{ | |
if (data & 1) // Wenn data an Stelle 0 = 1 | |
PORTD |= (1<<PD0); // Data serial = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* soft_serial_01.c ATmega88 @ 8MHz */ | |
#include <avr/io.h> | |
void soft_serial (uint8_t data) // Funktion soft_serial | |
{ | |
for (uint8_t i=0; i<=7; i++) // for-Schleife 8 mal ausführen | |
{ | |
if (data & 1) // Wenn data an Stelle 0 = 1 | |
PORTD |= (1<<PD0); // Data serial = 1 | |
else |