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

📄 ad0809.c

📁 ADC0809做的数字电压表
💻 C
字号:
#include <AT89X51.H>


#define byte unsigned char
#define word unsigned int
#define LLSB 0.01575
#define HLSB 0.0345 
//define I/O funtion 
sbit START=P2^2;
sbit EOC=P2^1;
sbit ALE=P2^0;
sbit OE=P2^3;
sbit CLK=P2^4;

byte dispcode[4]={0,0,0,0};//data  buffer
byte codetable[]={0xbd,0x09,0xec,0x6d,0x59,0x75,0xf5,0x29,0xfd,0x7d,0xb4};//number table with pointe
byte CodeTableP[]={0xbf,0x0b,0xee,0x6f,0x5b,0x77,0xf7,0x2b,0xff,0x7f};//number table with no pointe

//word DATA=0;


void Delaylms(word count)  //延世函数
 {
	word i,j;
   	for(i=0;i<count;i++)
   	for(j=0;j<120;j++);
 }





//初始装载
void InitTimer(void)
	{
 		TMOD=0x2;
 		TH0=0xfe;
		TL0=0xfe;
	}

	
void Timer(void) interrupt 1    //interrupter output clock
	{
	
		//TH0=0xff;
 		//TL0=0xfe;
		CLK=!CLK;
	}

void InitInterrupt(void)  //initialize the interrupt
	{
		InitTimer();
		TR0=1;
		ET0=1;
		//EA=1;
	}




	
//显示部分	
void Display()
{
	 byte *a=dispcode,i;
	 for(i=0; i<4; i++)
	{	
		TI=0;  
		if(i==1)
		{
			SBUF=CodeTableP[dispcode[i]];
			i++;
		}
		SBUF=codetable[*(a+i)];
		
		Delaylms(1);
	}
	//while(TI);
	
}

void Change(word T)//divide the  data into bits
  {  
    word a,b,c;
    
	dispcode[0]=T/100;
		a=T/100; 
    
	dispcode[1]=(T-100*a)/10;
		b=dispcode[1];
    
	dispcode[2]=T-100*a-10*b;
		//c=dispcode[2];
	
	dispcode[3]=10;//T-1000*a-100*b-10*c;
    
	
	Display();
  
	
	}  





//AD转换

void Conversion(word volt) // to convert the voltage to temperature
	{	
		word temper;
	
	
		if(volt>100)
		temper=10*((300-volt)/3);
		//temper=(900-3*volt);
        else
		temper=(15-8*volt);
		
		
		Change(temper);
	} 

void Converter()   //funtion for ADC work 
	{   
		word volt=0;
		
		START=1;
		START=0;
		//ALE=1;
		//ALE=0;
		EA=1;
		
		
		while(EOC==0);
		
		EA=0;
		Delaylms(1);
		OE=1;
		
		volt=P0;
		
		START=0;	//ALE=0;
		Delaylms(1);
		//Change(volt);
		OE=0;
		Conversion(volt);
	}

main()
	{	
	
		
		while(1)
		{
			InitInterrupt();
			Delaylms(300);
			Converter();
		}
			
	}

⌨️ 快捷键说明

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