//Transmit.c #include #include #include <.\txrx.c> //I like these definitions #define begin { #define end } #define data_length 2 #define tx_id 111 #define countNum 20 // slow down sample rate //General Program Variables char newReady; //ISR communication flag unsigned int count; //state variable to slow down sampling int dA; float Area, dArea; //char PushState; //char flag; //declarations char data[data_length]; unsigned char packet_count; // /************************************************/ interrupt [TIM0_OVF] void sgen(void) begin count--; if (count==0) begin count = countNum; //read ADC and send to PWM dA = ADCH; //start another conversion ADCSR.6=1; newReady = 1; end end //********************************************************** void generate_data(char pktcount) begin data[0] = pktcount; data[1] = 100; end /************************************************/ //initialization void init() begin //PORTA is analog input DDRA = 0b0 ; //all analog inputs with pullup off. PORTA = 0b0; //Used for LED array, output DDRC = 0xff; PORTC=0xff; //starting off //PORTD used for TX. //d7 led, d1 TX, d0,d2..6 unused DDRD = 0xff; //PCB Board Test //DDRD.2=1; PORTD.2 = 0; //turn on pwm with period= 256*8 cycles = 2048 cycles // or 7812 samples/sec //fast PWM mode, TCNT0 = 0; OCR0 = 128; TCCR0 = 0b01101010; //turn on timer 0 overflow ISR TIMSK = 0b00000001; //init the A to D converter //channel zero/ left adj /EXTERNAL Aref //!!!CONNECT Aref jumper!!!! ADMUX = 0b01100000; //enable ADC and set prescaler to 1/128*16MHz=125,000 //and clear interupt enable //and start a conversion ADCSR = 0b11000111; txrx_init(1,0,249,1);//TX only - 4000 baud - led on //initialize variables packet_count=0; generate_data(packet_count); //generate_data2(packet_count); #asm ("sei"); end /************************************************/ void main(void) begin init(); //set sample rate count = countNum; while(1) begin dArea = dA; if(dArea>0){ //PORTD.2 = 0; Area = Area + dArea; //debounce(); if(Area>1500){ //Send signal to the tranceiver generate_data(packet_count); tx_me(data, data_length, tx_id); PORTD.2 = 0; //Flicker-on LED for test Area = 0; } } else{ Area = 0; PORTD.2=1; } end // end while end //end main