diff -r 84249ab5d691 -r 20dbe0546a36 receiver/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/receiver/main.c Wed Nov 16 17:04:10 2011 +0100 @@ -0,0 +1,229 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "main.h" + +#include "driver/rs232.h" +//#include "driver/manchester.h" + +volatile uint8_t datalen = 0; +char data[10]; // 8 bytes data buffer + string termination + +static char buffer[RS232_BUFSIZE+1]; +static uint8_t buffer_len; + +volatile uint8_t bitbuf_len = 0; +volatile uint16_t bitbuf = 0; +volatile uint16_t bitbuf_out = 0; +volatile uint8_t bitbuf_out_len = 0; +volatile uint8_t timeout = 0; +volatile uint8_t lastbit = 0; + + + +// USART0 RX interrupt +ISR ( USART_RXC_vect ) { + char c = UDR; + + // check for buffer overflow + if (buffer_len==sizeof(buffer)) { + buffer_len=0; + if (c == 27) { + // escape sequence, store to empty buffer + buffer[buffer_len++] = c; + } + } else { + // collect characters until end of line + if (c == 27) { + // escape sequence, clear buffer + buffer_len = 0; + buffer[buffer_len++] = c; + } else if ( (c==0xff) && (buffer_len > 3) ) { + buffer[buffer_len]=0; + + // packet end received, parse the received packet + + // wait for the next packet + buffer_len=0; + } else { + buffer[buffer_len++]=c; + } + } +} + + +#define PULSE_IN PIND +#define PULSE_BIT 2 + +#define TIMER_DIVISOR 8 +#define VALUE_100US 0.47e-4 +#define TIMER_100US 0xff - (uint8_t)(VALUE_100US * F_CPU/TIMER_DIVISOR) + +ISR ( INT0_vect ) { + writeBit(GICR, INT0, 0); // disable INT0 interrupt + // Startsignal erkannt, ab hier den Timer0 starten, + // der liest dann alle 100µs den Zustand ein und schreibt das + // empfangene Bit in den Puffer + lastbit = 0b10000001; // initialize + + TCNT0 = TIMER_100US; + TIMSK |= 1< 0) { + bitbuf_out = bitbuf; + bitbuf_out_len = bitbuf_len; + } + bitbuf = 0; + bitbuf_len = 0; + GICR |= _BV(INT0); // Enable INT0 + } + + writeBit(PORTD, 4, 1); + SREG = sr; +} + +volatile uint8_t pulse_counter = 0; +volatile uint8_t measure_progress = 0; +volatile uint8_t car_id = 0; +ISR(TIMER2_OVF_vect) { + //TCNT2 = 0x90; + pulse_counter++; +} + +ISR (INT1_vect) { + // measure pulse width + //RS232_putc('x'); + if (measure_progress == 0) { + // start measuring + pulse_counter = 0; + measure_progress = 1; + // set INT1 to rising edge (stops current measurement) + //MCUCR |= _BV(ISC10); + writeBit(PORTD, 4, 1); + } else { + // stop measuring + car_id = pulse_counter; + measure_progress = 0; + // set INT1 to falling edge (initiates next measurement) + //MCUCR &= ~_BV(ISC10); + writeBit(PORTD, 4, 0); + } +} + + +int main(void) +{ + uint i; +char s[30]; + + TCCR0 = 0; //timer off + //TCCR0 = (1< 0xFF -> 0x00 + itoa( p_len, s, 10); + RS232_puts(s); + RS232_puts_p(PSTR("\n")); + p_len = 0; + } +*/ + } // main loop end +}; +