Advertisement
gauta

8.3 - 7seg štoperica - start/stop

Jan 23rd, 2018
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #define F_CPU 7372800UL
  2.  
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <avr/interrupt.h>
  8.  
  9. #include "lcd.h"
  10.  
  11. uint8_t i;
  12. uint8_t values[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
  13. uint8_t data[4] = {0, 0, 0, 0};
  14. uint16_t stotinka = 0;
  15. uint16_t counter2 = 0;
  16. uint8_t dotOn = 0;
  17. uint8_t state = 0;
  18.  
  19. void time2data(uint16_t time, uint8_t data[])
  20. {
  21. for(i=0; i<4; i++)
  22. {
  23. data[3-i] = time%10;
  24. time = time / 10;
  25. }
  26. }
  27.  
  28. ISR(TIMER1_COMPA_vect)
  29. {
  30. if(state == 0)
  31. {
  32. counter2++;
  33. if(stotinka == 10000)
  34. {
  35. stotinka = 0;
  36. }
  37. else
  38. {
  39. stotinka++;
  40. }
  41. if(counter2 % 50 == 0)
  42. {
  43. if(dotOn == 0)
  44. {
  45. dotOn = 1;
  46. }
  47. else
  48. {
  49. dotOn = 0;
  50. }
  51. }
  52. time2data(stotinka, data);
  53. }
  54. }
  55.  
  56. int main(void)
  57. {
  58. DDRA = 0xff;
  59. DDRB = 0xf0;
  60. PORTB = 0x0f;
  61.  
  62. TCCR1B = _BV(WGM12) | _BV(CS11);
  63. OCR1A = 9215;
  64.  
  65. TIMSK = _BV(OCIE1A);
  66. sei();
  67.  
  68.  
  69. while (1)
  70. {
  71. if(bit_is_clear(PINB, 0))
  72. {
  73. if(state == 0)
  74. {
  75. state = 1;
  76. }
  77. else
  78. {
  79. state = 0;
  80. }
  81. }
  82.  
  83. if(bit_is_clear(PINB, 1))
  84. {
  85. stotinka = 0;
  86. for(i=0; i<4; i++)
  87. {
  88. data[i] = 0;
  89. }
  90. }
  91.  
  92. for(i=0; i<4; i++)
  93. {
  94. PORTA = values[data[i]];
  95. if(dotOn == 1 && i == 1)
  96. {
  97. PORTA |= _BV(7);
  98. }
  99. PORTB &= 0x0f;
  100. PORTB |= _BV(4+i);
  101. _delay_ms(1);
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement