Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. #include <avr/interrupt.h>
  4. #include "lcd_tat.h"
  5. #include "lcd_tat.c"
  6.  
  7. #define F_CPU 8000000
  8. #define MIKRO 1000000
  9.  
  10. void TIMER1_init();
  11. ISR(TIMER1_OVF_vect);
  12. void ADC_init();
  13. ISR(ADC_vect);
  14.  
  15. uint32_t timer_multiplier;
  16. uint16_t tot_overflow;
  17.  
  18. int main() {
  19. uint8_t pulse;
  20. DDRA |= (1 << 0);
  21. LCD_init(1,0,0);
  22. ADC_init();
  23. TIMER1_init();
  24.  
  25. while(1) {
  26. /*ADCSRA |= (1 << ADEN)|(1 << ADPS1);*/
  27.  
  28. if(pulse > 20) {
  29. LCD_SetCursorXY(0,0);
  30. LCD_WriteUINT(MIKRO/timer_multiplier);
  31. LCD_WriteChar(',');
  32. LCD_WriteUINT(MIKRO % timer_multiplier);
  33. }
  34. pulse++
  35. }
  36. }
  37.  
  38. void TIMER1_init() {
  39. TCCR1B |= (1 << CS10)(1 << CS11);
  40. TCCR1B |= (WGM10);
  41. TIMSK |= (1 << TOIE1);
  42. }
  43.  
  44. ISR(TIMER1_OVF_vect) {
  45. tot_overflow++;
  46. }
  47.  
  48. void ADC_init() {
  49. ADMUX = (1<<REFS0);
  50. ADCSRA = (1 << ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
  51. }
  52.  
  53. ISR(ADC_vect) {
  54. uint16_t adc_data = ADCW;
  55. uint16_t adc_new = 0;
  56. uint16_t adc_old = 0;
  57.  
  58. if(adc_new > 400) {
  59. adc_new = 1;
  60. }
  61. else {
  62. adc_new = 0;
  63. }
  64.  
  65. if(adc_new != adc_old) {
  66. timer_multiplier = tot_overflow * 65356;
  67. timer_multiplier += TCNT1;
  68. timer_multiplier *= 2;
  69. timer_multiplier *= 8;
  70. tot_overflow = 0;
  71. TCNT1 = 0;
  72. }
  73. adc_old = adc_new;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement