#include #include #include #include "atm_i2c.h" #define IR_CLOCK_HIGH 10 //time in usec, got these number from a code example #define IR_CLOCK_LOW 100 //time in usec #define clockfreq 14745600 //clock freq #define baud 9600 //UART BAUD #define SEND_REQ 100 //#define DEBUG //clock is 14.7456 MHz, and timer is 14.7456MHz/256 = 57600Hz //this is one timer inc every 1.736e-5 seconds, set counter //to 256-58=198 to give an interrupt approx every 1 msec //we want a separate interrupt event every 1 second, writing to the UART //count 500 interrupts for half second. #ifdef DEBUG unsigned int uart_counts=500; int time = 0; #endif //every 100ms we want to check the IR data unsigned int IRstart_counts=100; //need to hold IR vin low for more than 70ms unsigned int IRlow_counts=71; //unsigned int IR_raw_read_1=0, IR_good_read_1=0,IR_raw_read_2=0, IR_good_read_2=0, // IR_raw_read_3=0, IR_good_read_3=0; unsigned int IR_raw_read[3]={0,0,0}, IR_good_read[3]={0,0,0}; //from atm_i2c.c extern char TWI_state; extern char TWI_recv_buf[TWI_RECV_BUFSIZE]; extern char TWI_send_buf[TWI_SEND_BUFSIZE]; void IR_get_bits(int bitnum) { //I don't think these delay functions halt interrupts PORTA = 0x15; //bring bits high again delay_us(IR_CLOCK_HIGH); //sleep .2 msec PORTA = 0x00; //bring bits low again delay_us(IR_CLOCK_LOW); //sleep .2 msec IR_raw_read[0] += ((PINA&0x02)!=0)<