Advertisement
Guest User

Untitled

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