//Grillzilla Transmit Unit //Includes #include #include<.\txrx.c> //definitions #define begin { #define end } #define data_length 2 #define tx_id 15 #define threshold 1000 //macros #define int2fix(a) (((int)(a))<<8) //Convert char to fix. a is a char #define fix2int(a) ((signed char)((a)>>8)) //Convert fix to char. a is an int #define float2fix(a) ((int)((a)*256.0)) //Convert float to fix. a is a float #define fix2float(a) ((float)(a)/256.0) //Convert fix to float. a is an int //defined constants char data[data_length]; unsigned char packet_count, packetNum; unsigned int time; unsigned char temperature; /* Faster version of A/D temp conversion //variables unsigned int multConst; unsigned int slope; unsigned int intercept; //initializations //multConst = 4*AVCC / 1024 //slope = -111.11 / 4 multConst = 0x0005; slope = float2fix(-13.88875); intercept = int2fix(70); //program code temperature1 = fix2int((multfix(slope, multfix((multConst << 2),int2fix(ADCH >> 2))) + intercept) << 3); */ // //==Fast fixed multiply================================= // // int multfix(int a,int b) // begin // #asm // ;****************************************************************************** // ;* // ;* FUNCTION // ;* muls16x16_24 // ;* DECRIPTION // ;* Signed multiply of two 16bits numbers with 24bits result. // ;* USAGE // ;* r31:r30:rxx = r23:r22 * r21:r20 // // ;****************************************************************************** // push r20 // push r21 // // LDD R22,Y+2 ;load a // LDD R23,Y+3 // // LD R20,Y ;load b // LDD R21,Y+1 // // muls r23, r21 ; (signed)ah * (signed)bh // mov r31, r0 ;r18, r0 // mul r22, r20 ; al * bl // mov r30, r1 ;movw r17:r16, r1:r0 // ;mov r16, r0 // mulsu r23, r20 ; (signed)ah * bl // add r30, r0 ;r17, r0 // adc r31, r1 ;r18, r1 // mulsu r21, r22 ; (signed)bh * al // add r30, r0 ;r17, r0 // adc r31, r1 ;r18, r1 // // pop r21 // pop r20 // #endasm // end // //********************************************************** //timer 0 compare ISR interrupt [TIM0_COMP] void timer0_compare(void) begin if(time<=threshold) time++; end //********************************************************** void generate_data(char count) begin data[0] = count; //packet count - cycles from 0-255 data[1] = temperature; end //********************************************************** //initialization void init() begin //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; PORTD.7=1; //turn d7 led on as power-on led //set up timer 0 TIMSK=2; //turn on timer 0 cmp match ISR OCR0 = 249; //set the compare re to 250 time ticks //prescalar to 64 and turn on clear-on-match TCCR0=0b00001011; //initialize the transmit parameters txrx_init(1,0,249,1);//TX only - 4000 baud - led on //initialize variables time=0; packet_count=0; generate_data(packet_count); //initialize ADC //channel 7 / left adj / Aref=AVCC with capacitor at AREF Pin (default on Bruce Land's PCB!) //!!!*DIS*CONNECT Aref jumper if using STK-500! ADMUX = 0b01100111; //enable ADC and set prescaler to 1/128*16MHz=125,000 //and clear interupt enable //and start a conversion ADCSR = 0b11000111; #asm ("sei"); packetNum=0; end //********************************************************** void main() begin init(); while(1) begin if(time==threshold) begin //**A/D CONVERSION** //get the A/D converter result, convert to fixed point //see above for faster fixed point version if necessary //the floating point version below has greater granularity //-2.16577695 = (4*AVCC / 1024)*slope //slope = -111.11 (according to experimental data) temperature = fix2int(float2fix(-2.16577695*ADCH + 560)); //**DATA TRANSMISSION** //create the packet generate_data(packet_count); //transmit the packet tx_me(data, data_length, tx_id); //**RESET FOR NEXT PACKET** //reset time, flash the LED, increase packet count time=0; PORTD.7 = 0; packet_count++; //start a new A/D conversion ADCSR.6=1; end end //while end //main