Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <avr\signal.h>
  2. #include <avr\interrupt.h>
  3. #include <avr\delay.h>
  4. #define LED0 0b10000010
  5. #define LED1 0b11010111
  6. #define LED2 0b00100011
  7. #define LED3 0b01000011
  8. #define LED4 0b01010110
  9. #define LED5 0b01001010
  10. #define LED6 0b00001010
  11. #define LED7 0b11000111
  12. #define LED8 0b00000010
  13. #define LED9 0b01000010
  14. #define LEDA 0b00000110
  15. #define LEDB 0b00011010
  16. #define LEDC 0b10101010
  17. #define LEDD 0b00010011
  18. #define LEDE 0b00101010
  19. #define LEDF 0b00101110
  20. #define DDR_LED DDRB
  21. #define DDR_WYSW DDRD
  22. #define PORT_LED PORTB
  23. #define PORT_WYSW PORTD
  24. #define DDR_SW DDRE
  25. #define PORT_SW PORTE
  26. #define PIN_SW PINE
  27.  
  28. volatile uint16_t g_Czekaj = 0;
  29. volatile uint16_t g_Czekaj2 = 0;
  30. uint8_t g_AktWyswietlacz = 0;
  31. uint8_t g_WyborWyswietlacza[4] = { 0b11011111, 0b11101111, 0b11110111, 0b11111011 };
  32. uint8_t g_Cyfry [10] = { LED0, LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8, LED9 };
  33. uint8_t g_DaneWyswietlacza [4] = { 0, 0,0,0};
  34.  
  35. int main( void )
  36. {
  37. DDR_LED = 0xff; DDR_WYSW |= 0b00111100;
  38. TCCR0 = 1<<CS02|1<<CS00;
  39. TIMSK = 1<<TOIE0;
  40. sei();
  41. int licznik = 0000;
  42.  
  43. for(;;) {
  44.  
  45. if ( !(PIN_SW & 0b00000001) ) {
  46. if( g_Czekaj == 0 ){
  47. g_Czekaj = 100;
  48. licznik++;
  49. }
  50. }
  51.  
  52. if ( !(PIN_SW & 0b00000010) ) {
  53. if( g_Czekaj2 == 0 ){
  54. g_Czekaj2 = 100;
  55. licznik--;
  56. }
  57. }
  58.  
  59. for(int i=0;i<15;i++){
  60. _delay_loop_2(0xffff);
  61. }
  62.  
  63. if (licznik > 9999){
  64. licznik = 0;
  65. }
  66.  
  67. g_DaneWyswietlacza [3] = g_Cyfry[licznik % 10];
  68. g_DaneWyswietlacza [2] = g_Cyfry[(licznik / 10)%10];
  69. g_DaneWyswietlacza [1] = g_Cyfry[(licznik / 100)%10];
  70. g_DaneWyswietlacza [0] = g_Cyfry[(licznik / 1000)%10];
  71. }
  72. return 0;
  73. }
  74.  
  75. SIGNAL( SIG_OVERFLOW0 ){
  76. if( g_Czekaj > 0 ){
  77. g_Czekaj--;
  78. }
  79.  
  80. if( g_Czekaj2 > 0 ){
  81. g_Czekaj2--;
  82. }
  83. PORT_WYSW |= 0b00111100;
  84. PORT_LED = g_DaneWyswietlacza[g_AktWyswietlacz];
  85. PORT_WYSW &= g_WyborWyswietlacza[g_AktWyswietlacz];
  86. g_AktWyswietlacz++;
  87. if( g_AktWyswietlacz> 3 ){
  88. g_AktWyswietlacz= 0;
  89. }
  90. TCNT0 = 1;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement