Upload
shweta-prabhu
View
214
Download
1
Embed Size (px)
Citation preview
This Code is only visible to Registered users. Please Login/Register #include #include #define ADC_VREF_TYPE 0xE0 // Read the 8 most significant bits // of the AD conversion resultunsigned char read_adc(unsigned char adc_input){ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);// Delay needed for the stabilization of the ADC input voltagedelay_us(10); // Start the AD conversionADCSRA|=0x40;// Wait for the AD conversion to completewhile ((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;fMCUCR=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(x0xab) { PORTD=0x08; } else if(y