// Test1: Using Tiny 13 to detect field clock and to control the MOD input in the transponder to send one data byte // protocol: byte(00000000) byte(11111111) byte(11111111) 100 byte(data). //optimized to send 3 synch bites and then 100 bytes // with tempreature sensor /* This code is for the AtmelTiny13 Microcontroller */ /************************************ //Port Description Connect XT1 on PORTE to PB3(XTAL1 on 2323) on PORTB Inputs: B.2 = Field Clock Input (T0) B.4 = ADC input ADC2 Outputs: B.0 = Manchester data output B.1 = 2 KHz Clock */ #include void initialize(void); //all the ini stuff unsigned char voltageD, index, byte, halfcycle; //digital voltage, index for data,number of half-cycles field clock has gone //through transmission, byte //********************************************************** //timer 0 compare ISR interrupt [TIM0_COMPA] void timer0_com(void) { // Three sync bytes (00-ff-ff), then 100 data bytes. PORTB.1 = ~PORTB.1; // Byte boundary. if (halfcycle == 16) { halfcycle = 0; voltageD=ADCH; if (voltageD == 255) voltageD = 0; ADCSRA.6=1; if (index == 0) byte = 0x00; else if (index < 3) byte = 0xff; else byte = voltageD; bytenum++; if (index == 103) index = 0; } // On the falling edge of the clock, the output matches the data. if (halfcycle & 1) PORTB.0 = (byte >> (halfcycle >> 1)) & 0x01; // On the rising edge of the clock, the output is the data inverted. else PORTB.0 = (~(byte >> (halfcycle >> 1))) & 0x01; halfcycle++; } //********************************************************** //Entry point and task scheduler loop void main(void) { initialize(); while(1) { }//end while(1) }//end main //********************************************************** void initialize(void) { //set up the ports DDRB.0=1; // PORT.0 and PORT.1 are outputs DDRB.1=1; //DDRB.2=0; //PORTB.2 is an input PORTB.0=0; PORTB.1=0; //PORTB.2=0; //no pull-up index=0; voltageD=0x00; byte=o; halfcycle=0; //set up timer 0 //TIMSK0=12; //turn on timer 0 cmp match A and B ISR OCR0A = 32; //set the compare to 32 periods TCCR0A=0b00000010; //CTC mode TCCR0B=0b00000111; //rising edge of external clock TIMSK0=0b00000100; //enable compare match //set ADC registers in ADC noise canceler(Idle mode) ADMUX=0b01100010;// Vref=1.1v(internalV), select ADCH select input channel PB4, ADCSRA=0b10000110;//enable the ADC, single conversion mode, // clk prescaler to 64=150kHZ resolution, no adc conversion complete interrup enable //turn on the ISR #asm ("sei"); }//end initialize