Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include "lcd.h"
  3. #include <avr/interrupt.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. uint8_t stotinke = 0;
  9. uint8_t sekunde = 0;
  10. uint8_t minute = 0;
  11. uint8_t sati = 0;
  12. uint8_t state = 0;
  13. char intStr[10];
  14. char intStr2[10];
  15.  
  16. void time2data()
  17. {
  18.  
  19. sprintf(intStr, "%.2d:%.2d:%.2d", sati, minute, sekunde);
  20. lcd_clrscr();
  21. lcd_puts(intStr);
  22. lcd_gotoxy(0, 1);
  23. lcd_puts(intStr2);
  24. }
  25.  
  26. ISR(TIMER0_COMP_vect)
  27. {
  28. if(state == 0)
  29. {
  30. stotinke++;
  31. if(stotinke == 100)
  32. {
  33. sekunde++;
  34. stotinke = 0;
  35. }
  36. if(sekunde == 60)
  37. {
  38. minute++;
  39. sekunde = 0;
  40. }
  41. if(minute == 60)
  42. {
  43. sati++;
  44. minute = 0;
  45. }
  46. if(sati == 24)
  47. {
  48. sati = 0;
  49. }
  50. time2data();
  51. }
  52. }
  53.  
  54. int main(void)
  55. {
  56. DDRD = 0xff;
  57. DDRB = 0xf0;
  58.  
  59. PORTB = 0x03;
  60.  
  61. TCCR1A = _BV(COM1B1) | _BV(COM1B0) | _BV(WGM10);
  62. TCCR1B = _BV(WGM12) | _BV(CS11);
  63. OCR1B = 200;
  64.  
  65. lcd_init(LCD_DISP_ON);
  66. lcd_clrscr();
  67.  
  68. TCCR0 = _BV(WGM01) | _BV(CS02) | _BV(CS00);
  69. OCR0 = 71;
  70. TIMSK = _BV(OCIE0);
  71.  
  72. sei();
  73.  
  74. while (1)
  75. {
  76. if(bit_is_clear(PINB, 0))
  77. {
  78. strcpy(intStr2, intStr);
  79. }
  80. if(bit_is_clear(PINB, 1))
  81. {
  82. if(state == 0)
  83. {
  84. state = 1;
  85. }
  86. else
  87. {
  88. state = 0;
  89. }
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement