Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. //NESTO FALIII
  2.  
  3. #define F_CPU 7372800UL
  4.  
  5.  
  6. #include <avr/io.h>
  7. #include <util/delay.h>
  8. #include <avr/interrupt.h>
  9. uint16_t time = 0;
  10. uint8_t data[4];
  11. uint8_t dotOn = 0;
  12. static uint8_t fStop = 1;
  13. static uint8_t debounce = 0;
  14.  
  15. void time2data(uint16_t time, uint8_t data[])
  16. {
  17.     uint8_t i;
  18.     for (i = 0; i < 4; i++) {
  19.         data[3-i] = time % 10;
  20.         time /= 10;
  21.     }
  22. }
  23.  
  24. ISR(TIMER1_COMPA_vect){
  25.     if (!fStop) {
  26.         time = (time >= 10000) ? 0 : time + 1;
  27.         if(!(time % 50)){
  28.             dotOn = ~dotOn;
  29.  
  30.             } else{
  31.             dotOn = dotOn;
  32.         }
  33.         time2data(time,data);
  34.     }
  35. }
  36.  
  37. int main(void)
  38. {
  39.     DDRA = 0xff;
  40.     DDRB = 0xf0;
  41.     uint8_t values[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
  42.     uint8_t i;
  43.  
  44.     TCCR1A = 0;
  45.     TCCR1B = _BV(WGM12) | _BV(CS11);
  46.     OCR1A = 9216;
  47.     TIMSK = _BV(OCIE1A);
  48.     sei();
  49.  
  50.  
  51.     //time2data(8888, data);
  52.     //dotOn = 1;
  53.  
  54.     /* Replace with your application code */
  55.     while (1)
  56.     {
  57.         for (i = 0; i < 4; i++)
  58.         {
  59.             PORTA = values[data[i]];
  60.  
  61.             if (dotOn) {
  62.                 PORTA |= _BV(7);
  63.             }
  64.            
  65.             PORTB = (PORTB & 0x0f) | _BV(4 + i);
  66.             _delay_ms(1);
  67.             if(debounce) debounce--;
  68.            
  69.             if(!debounce && bit_is_clear(PINB, 0)) {
  70.                 fStop ^= 1;
  71.                 debounce = 200;
  72.             } else if (bit_is_clear(PINB, 1)) {
  73.                
  74.             }
  75.            
  76.             PORTB = _BV(4 + i);
  77.             _delay_ms(1);
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement