The Code
#include
#include
#include
#include
#define enable PORTD3
#define registerselection PORTD5
void send_a_command(unsigned char command);
void send_a_character(unsigned char character);
void send_a_string(char *string_of_characters);
uint16_t us_measurement();
void set_compare(uint16_t);
void set_period(uint16_t);
void timer3_init();
static volatile int pulse = 0;
static volatile int i = 0;
int kalle;
int main(void)
{
DDRB = 0xFF;
DDRD = 0xFF;
DDRC |=(1< 0)
{
send_a_character(*string_of_characters++);
}
}
void timer3_init() {
TCCR3A &= ~(1 << COM3A1);
TCCR3A &= ~(1 << COM3A0);
TCCR3A |= (1 << WGM31);
TCCR3B |= (1 << WGM33) | (1 << WGM32) | (1 << CS30) | (1 << CS32);
}
void set_compare(uint16_t ocr){
OCR3A = ocr;
}
void set_period(uint16_t icr){
ICR3 = icr;
}
uint16_t us_measurement(){
_delay_ms(60);
TCNT1 = 0;
PORTC |= (1 << PORTC0);
_delay_us(10);
PORTC &= ~(1 << PORTC0);
while(!(PIND & (1 << PIND7)));
TCCR1B |= (1 << CS12) | (1 << CS10) ;
while((PIND & (1 << PIND7)));
TCCR1B = 0;
kalle = TCNT1;
return TCNT1;
}