Guest User

Untitled

a guest
Feb 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <avr/io.h>
  2.  
  3. void init(void);
  4.  
  5. void init(void) {
  6. /* Setup comparator */
  7. ACSR = (1 << ACIE);
  8. /* Initialize PORTD for PIND5 */
  9. DDRD = 0x00;
  10. PORTD = 0x00;
  11. /* Enable global interrupts */
  12. sei();
  13. }
  14.  
  15. int main(void) {
  16.  
  17. init();
  18.  
  19. while (1) {}
  20. }
  21.  
  22. ISR(ANALOG_COMP_vect) {
  23. PORTC ^= (1 << PINC1);
  24.  
  25. if (!(ACSR & (1<<ACIS0))) { //comparator falling edge
  26. /* Set PIND5 to 0V */
  27. PORTD &= ~(1 << PIND5);
  28.  
  29. ACSR |= (1<<ACIS0); //set next comparator detection on rising edge
  30. }
  31. else {
  32. ACSR &= ~(1<<ACIS0); //set next comparator detection on falling edge
  33. /* Set PIND5 to 5V */
  34. PORTD |= (1 << PIND5);
  35. }
  36. }
Add Comment
Please, Sign In to add comment