Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #include "lcd_tat.h"
- #include "lcd_tat.c"
- #define F_CPU 8000000
- #define MIKRO 1000000
- void TIMER1_init();
- ISR(TIMER1_OVF_vect);
- void ADC_init();
- ISR(ADC_vect);
- uint32_t timer_multiplier;
- uint16_t tot_overflow;
- int main() {
- uint8_t pulse;
- DDRA |= (1 << 0);
- LCD_init(1,0,0);
- ADC_init();
- TIMER1_init();
- while(1) {
- /*ADCSRA |= (1 << ADEN)|(1 << ADPS1);*/
- if(pulse > 20) {
- LCD_SetCursorXY(0,0);
- LCD_WriteUINT(MIKRO/timer_multiplier);
- LCD_WriteChar(',');
- LCD_WriteUINT(MIKRO % timer_multiplier);
- }
- pulse++
- }
- }
- void TIMER1_init() {
- TCCR1B |= (1 << CS10)(1 << CS11);
- TCCR1B |= (WGM10);
- TIMSK |= (1 << TOIE1);
- }
- ISR(TIMER1_OVF_vect) {
- tot_overflow++;
- }
- void ADC_init() {
- ADMUX = (1<<REFS0);
- ADCSRA = (1 << ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
- }
- ISR(ADC_vect) {
- uint16_t adc_data = ADCW;
- uint16_t adc_new = 0;
- uint16_t adc_old = 0;
- if(adc_new > 400) {
- adc_new = 1;
- }
- else {
- adc_new = 0;
- }
- if(adc_new != adc_old) {
- timer_multiplier = tot_overflow * 65356;
- timer_multiplier += TCNT1;
- timer_multiplier *= 2;
- timer_multiplier *= 8;
- tot_overflow = 0;
- TCNT1 = 0;
- }
- adc_old = adc_new;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement