Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <avr/interrupt.h>
  2. #include <avr/io.h>
  3.  
  4. uint8_t stanje=0xff;
  5.  
  6. int main(void)
  7. {
  8. DDRA=0xff;
  9. PORTA=0xff;
  10.  
  11. MCUCR=1<<ISC01 | 1<<ISC00;
  12. GICR=1<<INT0;
  13.  
  14. // ~2ms interval
  15. TCCR0= 1<<WGM01 | 1<<CS02 | 1<<CS00;
  16. OCR0=15;
  17.  
  18. sei();
  19.  
  20.  
  21. while(1)
  22. {
  23. //TODO:: Please write your application code
  24. }
  25. }
  26.  
  27. ISR(INT0_vect) {
  28. GICR=0;
  29. TIMSK=1<<OCIE0;
  30. stanje=~stanje;
  31. PORTA=stanje;
  32. }
  33.  
  34. ISR(TIMER0_COMP_vect) {
  35. static uint8_t y_old=0, flag=0;
  36. uint8_t temp;
  37.  
  38. temp=y_old>>2;
  39. y_old=y_old-temp;
  40.  
  41. if(bit_is_clear(PIND, PD2)) {
  42. y_old=y_old+0x3f;
  43. }
  44.  
  45. if(y_old>0xF0 && flag==0) {
  46. flag=1;
  47. GIFR|=0b10000000;
  48. TIMSK=0;
  49. GICR=1<<INT0;
  50. }
  51. if(y_old>0xF0 && flag==1) {
  52. flag=0;
  53. TIMSK=0;
  54. GIFR|=0b10000000;
  55. GICR=1<<INT0;
  56. }
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement