Advertisement
zujankaaa

Untitled

Mar 25th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. /*
  2. 1. Spojit 7seg, znamenke na PORTB, segmente na PORTD
  3. 2. Key1 datum, Key2 godina
  4. 3. Implementirat da kad se Key3 pritisne da se moze mijenjat godina - na Key1 se povecava, Key2 smanjuje,
  5. kad se opet Key3 pritisne - Key1 prikazuje opet datum, a Key2 godinu, znaci sa Key3 se mijenja stanje sto
  6. Key1 i Key2 rade -- koliko-toliko napravljeni taj zadatak
  7. */
  8. #define F_CPU 7372800UL
  9.  
  10. #include <avr/io.h>
  11. #include <util/delay.h>
  12.  
  13. int main(void)
  14. {
  15. DDRD = 0xff;
  16. PORTD = 0x00;
  17.  
  18. DDRB = 0xf0;
  19. PORTB = 0x0f;
  20.  
  21. uint8_t date[] = {0x5b, 0x5b, 0x3f, 0x4f};
  22. uint8_t year[] = {0x5b, 0x3f, 0x06, 0x07};
  23. uint8_t values[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
  24. uint8_t i, state = 0;
  25. uint8_t counter = 7;
  26. uint8_t funkcija = 0;
  27.  
  28. while (1)
  29. {
  30. if(bit_is_clear(PINB, 2))
  31. {
  32. funkcija ^= 0x01;
  33. }
  34.  
  35. if(funkcija == 0)
  36. {
  37. PORTB = 0x0f;
  38. if(bit_is_clear(PINB, 0)){
  39. state = 1;
  40. PORTD = 0x00;
  41. PORTB = 0x0f;
  42. }else if(bit_is_clear(PINB, 1)){
  43. state = 2;
  44. PORTD = 0x00;
  45. PORTB = 0x0f;
  46. }
  47.  
  48. if(state == 1){
  49. for(i = 0; i < 4; i++){
  50. PORTD = date[i];
  51. PORTB = _BV(4 + i);
  52. _delay_us(1000);
  53. }
  54. } else if(state == 2){
  55. for(i = 0; i < 4; i++){
  56. PORTD = year[i];
  57. PORTB = _BV(4 + i);
  58. _delay_us(1000);
  59. }
  60. }
  61. }
  62. else if(funkcija == 1)
  63. {
  64. PORTB = 0x0f;
  65. for(i = 0; i < 4; i++)
  66. {
  67. PORTD = year[i];
  68. PORTB = _BV(4 + i);
  69.  
  70. if(bit_is_clear(PINB, 0) && (PORTB == _BV(7)))
  71. {
  72. if(counter > 9){
  73. counter = 0;
  74. }
  75. counter += 1;
  76. year[3] = values[counter];
  77.  
  78. _delay_ms(200);
  79. } else if(bit_is_clear(PINB, 1) && (PORTB == _BV(7)))
  80. {
  81. if(counter <= 0){
  82. counter = 0;
  83. }
  84.  
  85. counter -= 1;
  86. year[3] = values[counter];
  87. _delay_ms(200);
  88. }
  89.  
  90. _delay_us(1000);
  91.  
  92. }
  93. }
  94. _delay_us(10); // za debounce
  95.  
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement