Guest User

Untitled

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