sonar.c File Reference

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "usart.h"
#include "common.h"
#include "lcdproxima.h"
Include dependency graph for sonar.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TOSTR(s)   XSTR(s)
#define XSTR(s)   #s
#define LED_DDR   (DDRC)
#define LED_PORT   (PORTC)
#define LED_PIN   (PC0)
#define LED_ON   LED_PORT |= (1 << LED_PIN)
#define LED_OFF   LED_PORT &= ~(1 << LED_PIN)
#define LED_TOGGLE   LED_PORT ^= (1 << LED_PIN)
#define SONAR_INIT_DDR   (DDRC)
#define SONAR_INIT_PORT   (PORTC)
#define SONAR_INIT_PIN   (PC1)
#define SONAR_POWER_DDR   (DDRD)
#define SONAR_POWER_PORT   (PORTD)
#define SONAR_POWER_PIN   (PD6)
#define SONAR_ECHO_DDR   (DDRB)
#define SONAR_ECHO_PORT   (PINB)
#define SONAR_ECHO_PIN   (PB0)
#define SONAR_SET_INIT   SONAR_INIT_PORT |= (1 << SONAR_INIT_PIN)
#define SONAR_CLEAR_INIT   SONAR_INIT_PORT &= ~(1 << SONAR_INIT_PIN)
#define SONAR_POWER_ON   SONAR_POWER_PORT &= ~(1 << SONAR_POWER_PIN)
#define SONAR_POWER_OFF   SONAR_POWER_PORT |= (1 << SONAR_POWER_PIN)
#define SONAR_GET_ECHO   (SONAR_ECHO_PORT & (1 << SONAR_ECHO_PIN))
#define MAX_DELAY   (100000)
 Maximum delay to wait to the end of measurement.

Functions

 ISR (TIMER1_OVF_vect)
 Overflow counter interrupts service routine.
 ISR (TIMER1_CAPT_vect)
 Timer1 capture interrupt service subroutine.
int main (void)
 Entry point of program.

Variables

volatile uint16_t ov_counter = 0
 Overflow counter.
volatile uint16_t icr1 = 0
 Copy of ICR1.
volatile bool_t captured = FALSE
 Sonar echo received.

Define Documentation

#define LED_DDR   (DDRC)

Definition at line 26 of file sonar.c.

#define LED_OFF   LED_PORT &= ~(1 << LED_PIN)

Definition at line 31 of file sonar.c.

#define LED_ON   LED_PORT |= (1 << LED_PIN)

Definition at line 30 of file sonar.c.

#define LED_PIN   (PC0)

Definition at line 28 of file sonar.c.

#define LED_PORT   (PORTC)

Definition at line 27 of file sonar.c.

#define LED_TOGGLE   LED_PORT ^= (1 << LED_PIN)

Definition at line 32 of file sonar.c.

#define MAX_DELAY   (100000)

Maximum delay to wait to the end of measurement.

Definition at line 54 of file sonar.c.

#define SONAR_CLEAR_INIT   SONAR_INIT_PORT &= ~(1 << SONAR_INIT_PIN)

Definition at line 48 of file sonar.c.

#define SONAR_ECHO_DDR   (DDRB)

Definition at line 43 of file sonar.c.

#define SONAR_ECHO_PIN   (PB0)

Definition at line 45 of file sonar.c.

#define SONAR_ECHO_PORT   (PINB)

Definition at line 44 of file sonar.c.

#define SONAR_GET_ECHO   (SONAR_ECHO_PORT & (1 << SONAR_ECHO_PIN))

Definition at line 51 of file sonar.c.

#define SONAR_INIT_DDR   (DDRC)

Definition at line 35 of file sonar.c.

#define SONAR_INIT_PIN   (PC1)

Definition at line 37 of file sonar.c.

#define SONAR_INIT_PORT   (PORTC)

Definition at line 36 of file sonar.c.

#define SONAR_POWER_DDR   (DDRD)

Definition at line 39 of file sonar.c.

#define SONAR_POWER_OFF   SONAR_POWER_PORT |= (1 << SONAR_POWER_PIN)

Definition at line 50 of file sonar.c.

#define SONAR_POWER_ON   SONAR_POWER_PORT &= ~(1 << SONAR_POWER_PIN)

Definition at line 49 of file sonar.c.

#define SONAR_POWER_PIN   (PD6)

Definition at line 41 of file sonar.c.

#define SONAR_POWER_PORT   (PORTD)

Definition at line 40 of file sonar.c.

#define SONAR_SET_INIT   SONAR_INIT_PORT |= (1 << SONAR_INIT_PIN)

Definition at line 47 of file sonar.c.

#define TOSTR (  )     XSTR(s)

Definition at line 23 of file sonar.c.

#define XSTR (  )     #s

Definition at line 24 of file sonar.c.


Function Documentation

ISR ( TIMER1_CAPT_vect   ) 

Timer1 capture interrupt service subroutine.

It is called at rising edge on ICP1.

Definition at line 72 of file sonar.c.

ISR ( TIMER1_OVF_vect   ) 

Overflow counter interrupts service routine.

Definition at line 63 of file sonar.c.

int main ( void   ) 

Entry point of program.

It is an infinite loop.

Definition at line 81 of file sonar.c.


Variable Documentation

volatile bool_t captured = FALSE

Sonar echo received.

Definition at line 58 of file sonar.c.

volatile uint16_t icr1 = 0

Copy of ICR1.

Definition at line 57 of file sonar.c.

volatile uint16_t ov_counter = 0

Overflow counter.

Definition at line 56 of file sonar.c.

Generated on Sat Oct 9 20:10:52 2010 for Sonar with ATMEGA88P by  doxygen 1.6.3