Advertisement
gabrielaozegovic

9 - 3 - 4

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