www.pudn.com > ADC.zip > main.c, change:2012-11-16,size:2010b


/* MAIN.C file 
 *  
 * Copyright (c) 2002-2005 STMicroelectronics 
 */ 
#include "stm8s207r.h" 
_Bool PB0 @PB_ODR:   0 ; 
_Bool LED @PD_ODR:   4; 
//_Bool LED @PD_ODR : 4 ; 
//_Bool EOC        @ADC_CSR:     7 ;  // AD转换结束标志,EOC = 1 转换结束 
//_Bool ADON       @ADC_CR1:     0 ;  // ADC使能位 
unsigned int temp,max,min;   
unsigned int x,i,H,L; 
void disp(); 
void GPIO(void) 
{ 
	PB_DDR=0x00; 
	PB_CR1=0x00; 
	PB_CR2=0x00; 
	PD_DDR=0x10; 
	PD_CR1=0x10; 
	PD_CR2=0x00; 
	 
 
} 
void delay(unsigned int ms) 
{ 
	unsigned char i; 
	while(ms!=0) 
{ 
	for(i=0;i<126;i++) 
		for(i=0;i<75;i++); 
		ms--; 
} 
 
} 
 
void CLK_init(void) 
{ 
	CLK_CKDIVR=0x01; 
} 
 
void ADC_init(void) 
{ 
CLK_PCKENR2|=0x08; 
	ADC_CR2=0x08; 
	ADC_CR1=0x00; 
	 
	 
	 
} 
void disp(void) 
{ 
	ADC_CSR=0x00; 
	for(i=0;i<5;i++) ; 
	ADC_CR1=ADC_CR1|0x01; 
	 
	while(!(ADC_CSR&0x80)==0); 
	 
	 
	ADC_CSR&=0x7f; 
	LED=1; 
	L = ADC_DRL; 
	H=ADC_DRH; 
	temp=(H<<8)+L; 
	//delay(100); 
} 
/*void ADCvalue(void) 
{ 
 
 
	ADC_CSR=0x00; 
	for(i=0;i<5;i++) ; 
	ADC_CR1=ADC_CR1|0x01; 
	while((ADC_CSR&0x80)==0); 
 
	 
	ADC_CSR&=0x7f; 
	L = ADC_DRL; 
	H=ADC_DRH; 
	temp=L; 
 
 
}*/ 
/*void ADCvalue(void)	 
{ //@near unsigned int temp,max,min;   
  //@near unsigned char x,i,H,L; 
	ADC_CSR=0x00; 
 //ADC_CSR = 0x06;     // 选择通道6 禁止中断 电流测量 
	  
  for(i=0;i<5;i++) ;//I_admem[i] = I_admem[i+1]; 	 
	 
 // ADON = 1; // 启动转换 ADC_CR1 |= 0x01;  
	ADC_CR1 |= 0x01; 
  while((ADC_CSR&0x80)==0);  // 等待转换结束 14个时钟周期 while(!(ADC_CSR&0x80)); 
	 
  //EOC = 0; // 清除中断标志 ADC_CSR &= 0x7f; 
	ADC_CSR &= 0x7f; 
  L = ADC_DRL; // 因为是右对齐所以先读低位   
  H = ADC_DRH;  
	 
  temp = (H<<8) + L;  
}*/ 
 
 
main() 
{ 
	 
	GPIO(); 
	CLK_init(); 
	ADC_init(); 
		 
	while(1) 
{ 
	disp(); 
	/*ADC_CSR=0x00; 
	for(i=0;i<5;i++) ; 
	ADC_CR1=ADC_CR1|0x01; 
	 
	while(!(ADC_CSR&0x80)==0); 
	 
	 
	ADC_CSR&=0x7f; 
	LED=1; 
	L = ADC_DRL; 
	H=ADC_DRH; 
	temp=(H<<8)+L; 
	delay(100); 
	//ADCvalue(); 
 
	//delay(10000);*/ 
} 
	 
}