Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. #include <iom128.h>
  2. #include <inavr.h>
  3.  
  4. #define DV_50Hz 144
  5. #define DV_1Hz 25
  6.  
  7. //Program configuration
  8. //#define ISR_PROCESSING
  9. #define PTR_ACCESS
  10.  
  11. #define LED_SEG PORTE
  12. #define LED_SEG_DIR DDRE
  13. #define LED_DG PORTB
  14. #define LED_DG_DIR DDRB
  15.  
  16. #define DV_480Hz 15
  17. #define DV_DEMO 40
  18. #define DV_NEXT 13
  19.  
  20. #define DEC_OFF 0x3F
  21. #define DISP_MAX 6
  22. #define LED_BLANK 15
  23.  
  24. typedef union TRQ {
  25. //Access to entire byte
  26. unsigned char c;
  27. struct {
  28. unsigned char f_tck : 1;
  29. //other flags can be defined
  30. unsigned char not_used : 7;
  31. };
  32. } TRQ;
  33.  
  34. //Decoding table based on CD4056 -> '0123456789LHPA- '
  35. __flash unsigned char BCD_2_LED[] = {
  36. 0xDE, 0x82, 0xEC, 0xE6,
  37. 0xB2, 0x76, 0x7E, 0xC2,
  38. 0xFE, 0xF6, 0x1C, 0xBA,
  39. 0xF8, 0xFA, 0x20, 0x00, 0x5C, 0xF0 };
  40.  
  41. __flash unsigned char DEC_1_OF_6[] =
  42. {0x00, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF};
  43.  
  44. //Global variables
  45. unsigned char freq_dv, symb_ID;
  46. unsigned char disp[] = {3, 3, 3, 4, 1, 1};
  47. //unsigned char disp[6] = {0,0,0,0,0,0};
  48. unsigned char cur_disp;
  49. unsigned char dv_demo = DV_DEMO;
  50. unsigned char dv_next = DV_NEXT;
  51. __no_init unsigned char idx;
  52. #define UPDATE_DISP_RQ 0x01
  53. volatile TRQ rq;
  54. volatile unsigned int wynik;
  55. void InitDevices()
  56. {
  57. LED_DG = 0xFE;
  58. LED_DG_DIR = 0xFF;
  59. LED_SEG_DIR = 0xFF;
  60. //Prescaler fclk / 1024 = 7200Hz
  61. //Prescaler for T0 is different than for T1,T2,T3
  62. //OCR0 = DV_480Hz - 1;
  63. OCR0 = DV_50Hz - 1;
  64. TCCR0 = (1 << WGM01) | (0 << CS02) | (1 << CS01) | (1 << CS00);
  65. TCCR1B = (1 << CS12);
  66. TIMSK = (1 << OCIE0)|(1 << TOIE1);
  67.  
  68. //DDRF = 0x00; //PORT F termomentr
  69. DDRB = 0xFF; //PORT B diode output
  70. DDRD = 0xFF; //PORT D diode output
  71.  
  72. ADCSRA = (1<<ADEN) //ADEN=1 włączenie przetwornika ADC)
  73. |(0<<ADPS0) // ustawienie preskalera na 64
  74. |(1<<ADPS1)
  75. |(1<<ADPS2) | (1 << ADIE);
  76. ADMUX = (1<<REFS1) | (1<<REFS0); // REFS1:0: wybór napięcia odniesienia ADC
  77. //na wewnętrzne źródło 2,56V
  78. //z zewnętrznym kondensatorem na pinie AREF
  79. __enable_interrupt();
  80. }
  81.  
  82.  
  83. #pragma vector = TIMER0_COMP_vect
  84. __interrupt void T0_COMP_ISR()
  85. {
  86. //static -> global variabl, visible insied declaration scope (file, function)
  87. static unsigned char counter = 0;
  88.  
  89. if(counter == 2){
  90. LED_SEG = BCD_2_LED[disp[counter]] | 0x01;
  91. }
  92. else{
  93. LED_SEG = BCD_2_LED[disp[counter]];
  94. }
  95. LED_DG = DEC_1_OF_6[counter];
  96. if (++counter==6) counter=0;
  97.  
  98.  
  99. }
  100.  
  101.  
  102.  
  103. #pragma vector = TIMER1_OVF_vect
  104. __interrupt void T1_OVF_ISR()
  105. {
  106. ADCSRA |= (1<<ADSC); //rozpocznij konwersje
  107.  
  108. }
  109.  
  110. #pragma vector = ADC_vect
  111. __interrupt void ADC_ISR()
  112. {
  113. //wynik = ADC;
  114. wynik = ADC*10;
  115. wynik = (wynik>>2);
  116. //PORTB = ~wynik; //wyswietl wartosci adc na diodach
  117. //PORTD = ~(wynik>>8);
  118. }
  119. void int_to_bcd(unsigned int a)
  120. {
  121. disp[0] = a/1000;
  122. disp[1] = a%1000/100;
  123. disp[2] = a%1000%100/10;
  124. disp[3] = a%1000%100%10;
  125. disp[4] = 17;
  126. disp[5] = 16;
  127.  
  128.  
  129. }
  130.  
  131. void main()
  132. {
  133.  
  134. InitDevices();
  135.  
  136. while(1)
  137. {
  138. int_to_bcd(wynik);
  139.  
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement