//----- Include Files ---------------------------------------------------------
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
#include <avr/iom32.h> // include I/O definitions (port names, pin names, etc)
#include <avr/interrupt.h> // include interrupt support
#include "global.h" // include our global settings
#include "uart.h" // include uart function library
#include "rprintf.h" // include printf function library
#include "timer.h" // include timer function library (timing, PWM, etc)
void timerTest(void);
//----- Begin Code ------------------------------------------------------------
uint32_t numofinterrupts; // total number of time interrupts since reset
uint64_t time; // total number of microseconds since reset
// Real time interupt function
// time will equal the number of ticks that have happened
// each tick is 4e-6 microseconds
int rtc(void)
{
numofinterrupts++;
time = (uint64_t)numofinterrupts * 250 + TCNT2;
return 0;
}
int setup(void)
{
// initialize our libraries
// initialize the UART (serial port)
uartInit();
// set the baud rate of the UART for our debug/reporting output
uartSetBaudRate(2400);
// initialize rprintf system
rprintfInit(uartSendByte);
// set the OC1A and OC1B for PWM output
sbi(DDRD, PD4);
sbi(DDRD, PD5);
// initialize the timer for RTC
timer2Init();
timer2SetPrescaler(64);
timerAttach(TIMER2OUTCOMPARE_INT, rtc);
// setup the sonar pins
sbi(DDRB, ); // sets PC0 to be an output
sbi(DDRB, ); // sets PC1 to be an output
return 0;
}
int main(void)
{
// Setup
setup();
return 0;
}
int pingSonar(int distance)
{
int starttime;
int elapsed;
// check the current time
starttime = time;
// initiate ping
}