X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=rf433rcv%2Fteensy%2Fexample.c;h=649b207b7a84a85004c5af0e3ab31076e7cf1197;hb=1d25e73e3d6d789b52433afee4ab3a1f70019912;hp=635b16f613bc97f797305e92f0207f7c655b1aac;hpb=deb2b278d460a716e0e2d8be370b1ee8f8963e34;p=svn42.git diff --git a/rf433rcv/teensy/example.c b/rf433rcv/teensy/example.c index 635b16f..649b207 100644 --- a/rf433rcv/teensy/example.c +++ b/rf433rcv/teensy/example.c @@ -26,83 +26,53 @@ #include #include #include "usb_rawhid.h" -#include "analog.h" #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) volatile uint8_t do_output=0; -uint8_t buffer[64]; +uint8_t read_buffer[64]; +uint8_t write_buffer[64]; int main(void) { - int8_t r; - uint8_t i; - uint16_t val, count=0; + int8_t r; + uint8_t i; + uint16_t val, count=0; - // set for 16 MHz clock - CPU_PRESCALE(0); + // set for 16 MHz clock + CPU_PRESCALE(0); + DDRF|=3; + PORTF&=~1; + // Configure timer 0 to generate a timer overflow interrupt every + // 200*8 clock cycles, 100us + TCCR0A = 1<0) + usb_rawhid_send(read_buffer, 50); - // Wait an extra second for the PC's operating system to load drivers - // and do whatever it does to actually be ready for input - _delay_ms(1000); - - // Configure timer 0 to generate a timer overflow interrupt every - // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock - TCCR0A = 0x00; - TCCR0B = 0x05; - TIMSK0 = (1< 0) { - // output 4 bits to D0, D1, D2, D3 pins - DDRD = 0x0F; - PORTD = (PORTD & 0xF0) | (buffer[0] & 0x0F); - // ignore the other 63.5 bytes.... - } - // if time to send output, transmit something interesting - if (do_output) { - do_output = 0; - // send a packet, first 2 bytes 0xABCD - buffer[0] = 0xAB; - buffer[1] = 0xCD; - // put A/D measurements into next 24 bytes - for (i=0; i<12; i++) { - val = analogRead(i); - buffer[i * 2 + 2] = val >> 8; - buffer[i * 2 + 3] = val & 255; - } - // most of the packet filled with zero - for (i=26; i<62; i++) { - buffer[i] = 0; - } - // put a count in the last 2 bytes - buffer[62] = count >> 8; - buffer[63] = count & 255; - // send the packet - usb_rawhid_send(buffer, 50); - count++; - } - } + } } // This interrupt routine is run approx 61 times per second. -ISR(TIMER0_OVF_vect) +ISR(TIMER0_COMPA_vect) { - static uint8_t count=0; + PORTF^=2; - // set the do_output variable every 2 seconds - if (++count > 122) { - count = 0; - do_output = 1; - } }