Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 14, 2019 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avr-programmierung/5d9c2823f69d8f9824c2e5a260c00f9f to your computer and use it in GitHub Desktop.
Save avr-programmierung/5d9c2823f69d8f9824c2e5a260c00f9f to your computer and use it in GitHub Desktop.
ATmega88 @ 1MHz Analog Comparator
/* 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