avrinput/main.c

82 lines
1.3 KiB
C

#include "time.h"
#include "usart.h"
#include "analogin.h"
#include "configuration.h"
#include "analogout.h"
#include <util/delay.h>
#include <stdlib.h>
#include <avr/io.h>
volatile int measurement_complete;
volatile unsigned char channel_measured;
volatile unsigned int value_measured;
void
on_channel_measured(unsigned char channel
, unsigned int value)
{
measurement_complete = 1;
channel_measured = channel;
value_measured = value;
}
int main(void)
{
unsigned char channel;
unsigned int value;
configuration_init();
time_init();
usart_init();
analogin_init();
analogout_init();
while(1)
{
if(measurement_complete)
{
measurement_complete = 0;
channel = channel_measured;
value = value_measured;
struct eigentime_s eigentime;
get_eigentime(&eigentime);
char buffer[32];
int i;
utoa(eigentime.high, buffer, 16);
i = 0;
while(buffer[i])
{
usart_putc(buffer[i++]);
}
usart_putc(',');
utoa(eigentime.low, buffer, 16);
i = 0;
while(buffer[i])
{
usart_putc(buffer[i++]);
}
usart_putc(',');
usart_putc('0' + channel);
usart_putc(',');
utoa(value, buffer, 16);
i = 0;
while(buffer[i])
{
usart_putc(buffer[i++]);
}
for(i = 0; i < 3; i++)
{
usart_putc('\n');
}
}
}
return 0;
}