Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #define F_CPU 7372800UL
  2.  
  3. #include <avr/io.h>
  4. #include <avr/interrupt.h>
  5. #include <util/delay.h>
  6.  
  7. static uint8_t br[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
  8. static uint8_t sec, msec;
  9. static uint8_t seg[4] = {_BV(4), _BV(5), _BV(6), _BV(7)};
  10.  
  11. static uint8_t state = 0x00;
  12.  
  13. ISR(TIMER1_COMPA_vect)
  14. {
  15. state ^= 0x80;
  16. }
  17.  
  18. ISR(TIMER0_COMP_vect)
  19. {
  20. //za brojeve
  21. msec++;
  22. if(msec == 100)
  23. {
  24. msec = 0;
  25. sec++;
  26.  
  27. if(sec == 60)
  28. {
  29. sec = 0;
  30. }
  31. }
  32. }
  33.  
  34. int main(void)
  35. {
  36. DDRA = 0xff;
  37. PORTA = 0xff;
  38. DDRB = 0xf0;
  39.  
  40. sec = 0;
  41. msec = 0;
  42.  
  43. //timer 1
  44.  
  45. TCCR1B = _BV(WGM12) | _BV(CS12);
  46.  
  47. OCR1A = 14399; //za tockicu,imamo formulu s ctcom s 2 zato sto je pola sekunde upaljena,pola ugasena
  48.  
  49. //timer 0
  50.  
  51. TCCR0 = _BV(WGM01) | _BV(CS02) | _BV(CS00);
  52.  
  53. OCR0 = 71; //bez 2 jer se racuna vrijeme i nema blinkanja nikakvog
  54.  
  55. TIMSK = _BV(OCIE1A) | _BV(OCIE0);
  56.  
  57. sei();
  58.  
  59.  
  60. while (1)
  61. {
  62. PORTB = seg[0];
  63. PORTA = br[sec/10];
  64. _delay_ms(1);
  65.  
  66. PORTB = seg[1];
  67. PORTA = br[sec%10];
  68. PORTA ^= state;
  69. _delay_ms(1);
  70.  
  71. PORTB = seg[2];
  72. PORTA = br[msec/10];
  73. _delay_ms(1);
  74.  
  75. PORTB = seg[3];
  76. PORTA = br[msec%10];
  77. _delay_ms(1);
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement