Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <Arduino.h>
  2. byte lut[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
  3. byte disp[]={B111110,B111101};
  4. byte d=0;
  5. byte x=0;
  6. byte x1,x2,xx;
  7. void setup()
  8. {
  9. DDRB=0xFF;
  10. DDRD=0xFF;
  11. TCCR1A=0x00;
  12. TCCR1B=0x00;
  13. TCNT1=0xF2F7; /// Timer 1 preset value
  14. bitWrite(SREG,7,1); /// Enable global interrupt
  15. bitWrite(TIMSK1,0,1); /// Enable TIMER1_OVF interrupt
  16. TCCR1B=0x05; /// Timer 1 ON
  17. }
  18. ISR(TIMER1_OVF_vect)
  19. {
  20. TCCR1B=0x00; /// Timer 1 off
  21. TCNT1=0xF2F7;
  22. x=x+1;
  23. if(x==100)
  24. {
  25. x=0;
  26. }
  27. xx=x;
  28. x1=0;
  29. x2=0;
  30. while(xx != 0)
  31. {
  32. xx=xx-1;
  33. x1=x1+1;
  34. if(x1>9)
  35. {
  36. x2=x2+1;
  37. x1=0;
  38. }
  39. }
  40. bitSet(TIFR1,2); /// TOV1 Clear
  41. TCCR1B=0x05; /// Timer 1 Off
  42. }
  43. void loop()
  44. {
  45. digitalWrite(13,LOW);
  46. delay(1);
  47. PORTB=disp[d];
  48. if (d==0)
  49. {
  50. PORTD=lut[x2];
  51. }
  52. else if (d==1)
  53. {
  54. PORTD=lut[x1];
  55. }
  56. delay(1);
  57.  
  58. d=d+1;
  59. if (d>1)
  60. {
  61. d=0;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement