Created
May 14, 2019 10:53
-
-
Save avr-programmierung/5d9c2823f69d8f9824c2e5a260c00f9f to your computer and use it in GitHub Desktop.
ATmega88 @ 1MHz Analog Comparator
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
/* analog_comp_01.c ATmega88 @ 1MHz */ | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
#define LED PC5 | |
int main(void) | |
{ | |
DDRC = 0xFF; //Richtungsregister PORTC auf Ausgang | |
PORTC &= ~(1<<LED); //LED OFF | |
ACSR |= (1<<ACBG); //Referenzspannung an AIN0 aktivieren | |
ACSR |= (1<<ACIE); //AC-Interrupt enable | |
sei(); //Global Interrupt enable | |
while(1) | |
{ | |
//Nichts tun… | |
} | |
} | |
ISR (ANALOG_COMP_vect) //Analog Comparator Interrupt Service Routine | |
{ | |
if ((ACSR & 0b00100000) == 0) //Wenn Bit ACO gelöscht ist | |
PORTC |= (1<<LED); //LED ON | |
else | |
PORTC &= ~(1<<LED); //LED OFF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment