Advertisement
gabrielaozegovic

Untitled

Jan 19th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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. #include <string.h>
  7.  
  8. #include "lcd.h"
  9.  
  10. static uint16_t stot = 0;
  11. static uint16_t sec = 0;
  12. static uint16_t min = 0;
  13. static uint16_t h = 0;
  14. char str[16];
  15. char str2[16];
  16. static uint8_t flag = 0;
  17.  
  18. ISR(TIMER0_COMP_vect){
  19.  
  20.  
  21. stot++;
  22.  
  23. if(stot == 100){
  24. sec++;
  25. stot = 0;
  26. }
  27. if(sec == 60){
  28. min++;
  29. sec = 0;
  30. }
  31. if(min == 60){
  32. h++;
  33. min = 0;
  34. }
  35. if(h == 99){
  36. h = 0;
  37. }
  38.  
  39. sprintf(str, "%02d:%02d:%02d", h, min, sec);
  40. //sprintf(str, "%02d:%02d:%02d", h, min, sec);
  41. lcd_clrscr();
  42. lcd_gotoxy(4, 0);
  43. lcd_puts(str);
  44.  
  45.  
  46.  
  47. }
  48.  
  49. int main(void){
  50.  
  51. DDRA = 0xff;
  52. DDRD = 0xff;
  53. PORTA |= 0b10000000; //jer je boja stavljena na PORTA na 7.mjesto pa moramo dovest 1 na tu poziciju
  54.  
  55. DDRB = 0xf0;
  56. PORTB = 0xff;
  57.  
  58. TCCR1A = _BV(COM1B1) | _BV(WGM10);
  59. TCCR1B = _BV(WGM12) | _BV(CS10);
  60. OCR1B = 20;
  61.  
  62. TCCR0 = _BV(WGM01) | _BV(CS00) | _BV(CS02);
  63. OCR0 = 72;
  64. TIMSK = _BV(OCIE0);
  65. sei();
  66.  
  67.  
  68. lcd_init(LCD_DISP_ON);
  69. lcd_clrscr();
  70.  
  71. //lcd_puts("da");
  72.  
  73. while (1){
  74.  
  75.  
  76.  
  77. if(bit_is_clear(PINB, 0)){
  78. _delay_ms(100);
  79.  
  80. if(OCR1B < 250){
  81. OCR1B++;
  82. }
  83.  
  84. sprintf(str2, "%d", OCR1B);
  85. lcd_clrscr();
  86. lcd_gotoxy(11, 1);
  87. lcd_puts(str2);
  88.  
  89. }
  90.  
  91.  
  92.  
  93. if(bit_is_clear(PINB, 1)){ //dodavanje
  94. _delay_ms(100);
  95.  
  96. if(OCR1B > 10){
  97. OCR1B--;
  98. }
  99.  
  100. sprintf(str2, "%d", OCR1B);
  101. lcd_clrscr();
  102. lcd_gotoxy(11, 1);
  103. lcd_puts(str2);
  104. }
  105.  
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement