⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc.h

📁 用SL811做USB主机的源码
💻 H
字号:
#define PIN1_high {PORTD |= (1<<4);}
#define PIN2_high {PORTD |= (1<<5);}
#define PIN3_high {PORTD |= (1<<6);}
#define PIN4_high {PORTD |= (1<<7);}
#define PIN1_low {PORTD &= ~(1<<4);}
#define PIN2_low {PORTD &= ~(1<<5);}
#define PIN3_low {PORTD &= ~(1<<6);}
#define PIN4_low {PORTD	&= ~(1<<7);}
#define	ADC_start6 { ADMUX = 0x06;ADCSRA |= (1<<6);}
#define	ADC_start7 { ADMUX = 0x07;ADCSRA |= (1<<6);}

unsigned int adc_x[8],adc_y[8],AD_X,AD_Y;

void adc_process(void)
{static unsigned char state_adc=0,cishu_adc;
		unsigned char i;
		unsigned int temp=0;

		switch (state_adc) {
			   case 0: PIN2_low
 			   		   PIN4_low
					   PIN1_low
					   PIN3_high;//X轴
					   state_adc++;
					   break;
			   case 1: ADC_start7//启动ADC7
			   		   state_adc++;
					   break;
			   case 2: ADCSRA |= (1<<4);//读结果
			   		
			   		   if (ADC>1013)
					   	  	{state_adc=0;
							cishu_adc=0;
							if (ready_adc)
							   {open_adc=1;ready_adc=0;}
							}
						 else {state_adc=3;
						 	  PIN2_high
 			   		   		  PIN4_low
					   		  PIN1_low
					   		  PIN3_high;//X轴
							  cishu_adc++;
							  if (ready_adc) {state_adc=0;break;}
							  if (cishu_adc==10) {state_adc=0; close_adc=1;break;}
							  }
			   		   break;
					   
			   case 3: ADC_start7//启动ADC7
			   		   state_adc++;
					   break;
			   case 4: for (i=8;i>1;i--) {adc_x[i-1]=adc_x[i-2];}
			   		   adc_x[0]=ADC;
					   ADCSRA |= (1<<4);//读结果
			   		   state_adc++;
					   PIN2_low
 			   		   PIN4_high
					   PIN1_high
					   PIN3_low;//Y轴
					   break;
					   
			   case 5: ADC_start6//启动ADC6
			   		   state_adc++;
					   break;
			   case 6: for (i=8;i>1;i--) {adc_y[i-1]=adc_y[i-2];}
			   		   adc_y[0]=ADC;
					   ADCSRA |= (1<<4);//读结果
			   		   state_adc=0;
					   break;
				default:state_adc=0;break;}
}

/*unsigned char judge_adc(unsigned char Page)
{	if (Ktab[Page][0]!=0)
}*/


void AD(void)
{unsigned char i;
 unsigned int temp=0;

 if (close_adc)
	{close_adc=0;ready_adc=1;
	temp=adc_x[7];
	for (i=0;i<7;i++) {temp += adc_x[i];}
	AD_X=temp>>3;
	temp=adc_y[7];
	for (i=0;i<7;i++) {temp += adc_y[i];}
	AD_Y=temp>>3;
	}
 if (open_adc)
 	{fmq_low
	for (temp=0;temp<60000;temp++) {};
	fmq_high	
	open_adc=0;
	}
}

	//put_shuzi(0,0,AD_X);
	//put_shuzi(7,0,39*(940-AD_X)/810);
	//put_shuzi(0,20,AD_Y);
	//put_shuzi(7,20,6*(900-AD_Y)/19);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -