Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include "lcd.h"
  3. #include <avr/interrupt.h>
  4.  
  5. static uint8_t ts = 0, tm = 0, th = 0, tSS = 0;
  6.  
  7. void gettime()
  8. {
  9. char time[9];
  10.  
  11. time[0] = '0' + (th / 10);
  12. time[1] = '0' + (th % 10);
  13. time[2] = ':';
  14. time[3] = '0' + (tm / 10);
  15. time[4] = '0' + (tm % 10);
  16. time[5] = ':';
  17. time[6] = '0' + (ts / 10);
  18. time[7] = '0' + (ts % 10);
  19. time[8] = '\0';
  20.  
  21. lcd_clrscr();
  22. lcd_gotoxy(4, 0);
  23. lcd_puts(time);
  24. }
  25.  
  26. ISR(TIMER0_COMP_vect)
  27. {
  28. tSS++;
  29.  
  30. if (tSS == 100) {
  31. tSS = 0;
  32.  
  33. ts++;
  34. if (ts == 60) {
  35. ts = 0;
  36. tm++;
  37. }
  38.  
  39. if (tm == 60) {
  40. tm = 0;
  41. th++;
  42. }
  43.  
  44. if (th == 24) {
  45. th = 0;
  46. }
  47. gettime();
  48. }
  49. }
  50.  
  51.  
  52. int main(void)
  53. {
  54. DDRD = _BV(4);
  55. TCCR1A = _BV(COM1B1) | _BV(COM1B0) | _BV(WGM10);
  56. TCCR1B = _BV(WGM12) | _BV(CS11);
  57.  
  58. OCR1B = 250;
  59.  
  60. TCCR0 = _BV(WGM01) | _BV(CS00) | _BV(CS02);
  61. OCR0 = 71;
  62. TIMSK = _BV(OCIE0);
  63.  
  64. sei();
  65.  
  66. lcd_init(LCD_DISP_ON);
  67. lcd_clrscr();
  68.  
  69.  
  70.  
  71. while (1)
  72. {
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement