Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- void init(void);
- void init(void) {
- /* Setup comparator */
- ACSR = (1 << ACIE);
- /* Initialize PORTD for PIND5 */
- DDRD = 0x00;
- PORTD = 0x00;
- /* Enable global interrupts */
- sei();
- }
- int main(void) {
- init();
- while (1) {}
- }
- ISR(ANALOG_COMP_vect) {
- PORTC ^= (1 << PINC1);
- if (!(ACSR & (1<<ACIS0))) { //comparator falling edge
- /* Set PIND5 to 0V */
- PORTD &= ~(1 << PIND5);
- ACSR |= (1<<ACIS0); //set next comparator detection on rising edge
- }
- else {
- ACSR &= ~(1<<ACIS0); //set next comparator detection on falling edge
- /* Set PIND5 to 5V */
- PORTD |= (1 << PIND5);
- }
- }
Add Comment
Please, Sign In to add comment