Guest User

Untitled

a guest
Jan 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <mega8535.h>
  2.  
  3. unsigned int timecount = 0; // global counter variable
  4.  
  5. interrupt [TIM0_OVF] void timer0_ovf_isr(void)
  6. {
  7. TCNT0 = 131; // reload value for 0.004s ticks
  8. if (++timecount == 250)
  9. {
  10. PORTA ^= 0x01; // toggle PORTA.0
  11. timecount = 0; // clear for next 500ms interval
  12. }
  13. }
  14.  
  15. void main(void)
  16. {
  17. PORTA=0x00; // PORTA LOW
  18. DDRA=0x01; // PORTA.0 AS OUTPUT
  19.  
  20. TCCR0=0x05; // set system clock/1024 for Timer 0 input
  21. TCNT0=0x00; // start timer with 0 in timer
  22.  
  23. TIMSK=0x01; // unmask Timer 0 overflow interrupt
  24.  
  25. #asm("sei") // global enable interrupts
  26.  
  27. while (1)
  28. ; // Do nothing (yet)
  29.  
  30. }
Add Comment
Please, Sign In to add comment