#include #include #define ADC_VREF_TYPE 0xE0 // Read the 8 most significant bits // of the AD conversion result unsigned char read_adc(unsigned char adc_input) { ADMUX=adc_input | (ADC_VREF_TYPE & 0xff); // Delay needed for the stabilization of the ADC input voltage delay_us(10); // Start the AD conversion ADCSRA|=0x40; // Wait for the AD conversion to complete while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; return ADCH; } void main(void) { unsigned int x,y,z; PORTB=0x00; DDRB=0xFF; PORTC=0x00; DDRC=0x00; PORTD=0x00; DDRD=0xFF; TCCR0=0x00; TCNT0=0x00; TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; ASSR=0x00; TCCR2=0x00; TCNT2=0x00; OCR2=0x00;f MCUCR=0x00; TIMSK=0x00; UCSRB=0x00; ACSR=0x80; SFIOR=0x00; ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0x83; SPCR=0x00; TWCR=0x00; while (1) { // Place your code here x=read_adc(3); y=read_adc(4); z=read_adc(5); PORTB=x; //---------------------------------------------------------------// X AXIS //--------------------------------------------------------------- if(x>0xab) { PORTD=0x0c; } else if(x<0x9b) { PORTD=0x03; } //-------------------------------------------------------------- // Y AXIS //------------------------------------------------------------------ else if(y>0xab) { PORTD=0x08; } else if(y<0x9b) { PORTD=0x0e; } //-------------------------------------------------------------- //--------------------------------------------------------------- else PORTD=0xff; } } //Receiver main program #include void main() { P2=0xff; P1=0x00; while(1) { if(P2==0x80) { P1=0xaa; } else if(P2==0xe0) { P1=0x55; } else if(P2==0x30) { P1=0xa5; } else if(P2==0xC0) { P1=0x5a; } else P1=0x00; } } [/restrict]