Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <avr/io.h>
  2. #define F_CPU 16000000UL
  3. #include <util/delay.h>
  4. #include <avr/interrupt.h>
  5.  
  6. /*
  7. ISR(TIMER0_COMP_vect)
  8. {
  9. static uint8_t licznik = 0;
  10.  
  11. PORTB |= 0x0F;
  12. PORTA = LED[licznik];
  13. PORTB &= ~(1 << licznik);
  14.  
  15. if (++licznik>3){
  16. licznik = 0;
  17. }
  18.  
  19. switch(key_state1){
  20. case 0: if ((PINC & 0x01) == 0) key_state1 = 1;
  21. break;
  22. case 1: if ((PINC & 0x01) == 0) key_state1 = 2;
  23. else key_state1 = 0;
  24. break;
  25. case 2: break;
  26. case 3: if ((PINC & 0x01) != 0) key_state1 = 4;
  27. break;
  28. case 4: if ((PINC & 0x01) != 0) key_state1 = 0;
  29. else key_state1 = 3;
  30. break;
  31. default:key_state1 = 0;
  32. }
  33.  
  34. switch(key_state2){
  35. case 0: if ((PINC & 0x02) == 0) key_state2 = 1;
  36. break;
  37. case 1: if ((PINC & 0x02) == 0) key_state2 = 2;
  38. else key_state2 = 0;
  39. break;
  40. case 2: break;
  41. case 3: if ((PINC & 0x02) != 0) key_state2 = 4;
  42. break;
  43. case 4: if ((PINC & 0x02) != 0) key_state2 = 0;
  44. else key_state2 = 3;
  45. break;
  46. default:key_state2 = 0;
  47. }
  48. }
  49.  
  50. ISR()
  51. {
  52.  
  53. }
  54. uint8_t seg7[]={0b11000000,
  55. 0b11111001,
  56. 0b10100100,
  57. 0b10110000,
  58. 0b10011001,
  59. 0b10010010,
  60. 0b10000010,
  61. 0b11111000,
  62. 0b10000000,
  63. 0b10010000};
  64.  
  65. volatile uint8_t LED[4];
  66. volatile uint8_t key_state1 = 0;
  67. volatile uint8_t key_state2 = 0;
  68.  
  69. int main(void)
  70. {
  71. TCCR0 |= (1 << WGM01 ) | (0 << WGM00 );
  72. TCCR0 |= (1 << CS02) | (0 << CS01) | (1 << CS00);
  73. OCR0=50;
  74. TIMSK |=(1 << OCIE0);
  75. sei();
  76.  
  77. uint16_t sec = 0000;
  78.  
  79. DDRB = 0x0F;
  80. DDRA = 0xFF;
  81.  
  82. DDRC = 0x00;
  83. PORTC = 0x03;
  84.  
  85. // Replace with your application code
  86. while (1)
  87. {
  88. uint16_t tmp = sec;
  89.  
  90. LED[3]=seg7[tmp/1000];
  91. tmp %= 1000;
  92. LED[2]=seg7[tmp/100];
  93. tmp %= 100;
  94. LED[1]=seg7[tmp/10];
  95. tmp %= 10;
  96. LED[0]=seg7[tmp];
  97.  
  98. if (key_state1 == 2){
  99. sec = 1234;
  100. key_state1 = 3;
  101. }
  102. else if(key_state2 == 2){
  103. sec = 4567;
  104. key_state2 = 3;
  105. }
  106.  
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement