Advertisement
Guest User

FINAL KEK

a guest
Jan 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #include <ioavr.h>
  2. #include <inavr.h>
  3.  
  4. #define DV_50Hz 144
  5. #define DV_1Hz 36
  6.  
  7. //Symbolic names for connecting 7-segment LED display
  8. #define LED_SEG PORTE
  9. #define LED_SEG_DIR DDRE
  10. #define LED_DG PORTB
  11. #define LED_DG_DIR DDRB
  12.  
  13. #define DEC_OFF 0x3F
  14. #define DISP_MAX 6
  15. //Decoding table based on CD4056 -> '0123456789LHPA- '
  16. __flash unsigned char bcd_to_led[] = {
  17. 0xDE, 0x82, 0xEC, 0xE6,
  18. 0xB2, 0x76, 0x7E, 0xC2,
  19. 0xFE, 0xF6, 0x1C, 0xBA,
  20. 0xF8, 0xFA, 0x20, 0x00
  21. };
  22.  
  23. unsigned char DEC_1_OF_6[] =
  24. {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF};
  25.  
  26.  
  27. //Global variables
  28. unsigned char freq_dv;
  29. unsigned char disp[6] = {0,0,0,0,0,0};
  30. unsigned static char time=0;
  31. //time should be set in form: [minute, second];
  32. unsigned static char lowerBorder[2]= {0,10};
  33. unsigned static char upperBorder[2]= {0,30};
  34.  
  35. /*
  36. const char bordersLCD[] =
  37. lowe;
  38.  
  39. void displayBorder()
  40. {
  41. LCDGoTo(LINE_1 + 21);
  42. LCDPuts(endingMes);
  43. }
  44. */
  45. void InitDevices()
  46. {
  47. LED_DG = 0xFE;
  48. LED_DG_DIR = 0xFF;
  49. LED_SEG_DIR = 0xFF;
  50. DDRA = 0x0;
  51. //Prescaler fclk / 1024 = 7200Hz
  52. //Prescaler for T0 is different than for T1,T2,T3
  53. OCR0 = DV_50Hz - 1;
  54. TCCR0 = (1 << CS02) | (1 << CS01) | (1 << CS00);
  55. TIMSK = (1 << OCIE0);
  56. __enable_interrupt();
  57. }
  58. int checkBorders(){
  59. if((time>(lowerBorder[0]*60+lowerBorder[1]) && time<(upperBorder[0]*60+upperBorder[1]))){
  60. return 1;
  61. } else {
  62. return 0;
  63. }
  64. }
  65. void Timer() {
  66. static unsigned char timer[4] = { 0, 0, 0, 0 };
  67.  
  68. time++;
  69. timer[0] = time % 10;
  70. timer[1] = ((time - (time % 10) )/ 10) % 6;
  71. timer[2] = ((time - (time % 60))/60) %10;
  72. timer[3] = ((time - (time % 60)) / 60)/10 % 6;
  73.  
  74. //bcd_to_led[
  75. // LED_SEG = bcd_to_led[(i++)%10];
  76. disp[0] = bcd_to_led[timer[0]];
  77. disp[1] = bcd_to_led[timer[1]];
  78. disp[2] = bcd_to_led[timer[2]];
  79. disp[3] = bcd_to_led[timer[3]];
  80. }
  81.  
  82.  
  83.  
  84. #pragma vector = TIMER0_COMP_vect
  85. __interrupt void T0_COMP_ISR()
  86. {
  87. //static -> global variabl, visible insied declaration scope (file, function)
  88. static unsigned char cur_disp = 0;
  89. // LED_DG |= DEC_OFF;
  90. LED_SEG = disp[cur_disp];
  91. LED_DG = DEC_1_OF_6[cur_disp];
  92. if((++cur_disp) == DISP_MAX) cur_disp = 0;
  93.  
  94. static unsigned char freq_dv = DV_1Hz;
  95. if(--freq_dv) return;
  96. freq_dv = DV_1Hz;
  97. //Update to nexy symbol from bcd_to_led array
  98. Timer();
  99.  
  100. }
  101.  
  102. void main()
  103. {
  104. InitDevices();
  105. while(1)
  106. {
  107. if(checkBorders()){
  108. DDRA = 0xFF;
  109. }else{
  110. DDRA = 0x0;
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement