Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #define F_CPU 7372800UL
  2.  
  3. #include <avr/io.h>
  4. #include "lcd.h"
  5. #include <avr/interrupt.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.  
  13. void write2lcd()
  14. {
  15. char string[16];
  16.  
  17. sprintf(string, "%.2d:%.2d:%.2d", sati, minute, sekunde);
  18.  
  19. lcd_clrscr();
  20. lcd_gotoxy(2,1);
  21. lcd_puts(string);
  22. }
  23.  
  24. ISR(TIMER0_COMP_vect)
  25. {
  26. stotinke++;
  27. if(stotinke == 100)
  28. {
  29. sekunde++;
  30. stotinke = 0;
  31. }
  32. if(sekunde == 60)
  33. {
  34. minute++;
  35. sekunde = 0;
  36. }
  37. if(minute == 60)
  38. {
  39. sati++;
  40. minute = 0;
  41. }
  42. if(sati == 24)
  43. {
  44. sati = 0;
  45. }
  46. write2lcd();
  47. }
  48.  
  49. int main(void)
  50. {
  51. DDRD = _BV(4);
  52. TCCR1A = _BV(COM1B1) | _BV(WGM10);
  53. TCCR1B = _BV(WGM12);
  54. OCR1B = 50;
  55.  
  56. TCCR0 = _BV(WGM01) | _BV(CS00) | _BV(CS02);
  57. OCR0 = 71;
  58.  
  59. TIMSK = _BV(OCIE0);
  60. sei();
  61.  
  62.  
  63. lcd_init(LCD_DISP_ON);
  64. lcd_clrscr();
  65.  
  66. while (1)
  67. {
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement