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

📄 ad.c

📁 89c2051 a/d模拟转数字转换 程序
💻 C
字号:
/************************************************/

/************************************************/
#include <REG52.H>
#include <stdio.h>
#include <intrins.h>

#ifdef MONITOR51                         /* Debugging with Monitor-51 needs   */
char code reserve [3] _at_ 0x23;         /* space for serial interrupt if     */
#endif                                   /* Stop Exection with Serial Intr.   */
                                         /* is enabled                        */
const char Ledbuf[18]=/*digit convert table*//* 共阴*/
	{ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,		
	/* 0     1     2     3     4     5     6     7     8     9 */
	 0x77, 0x7C, 0x39, 0x1000E, 0x79, 0x71, 0x00, 0x40 };
	/* a    b     c     d     e     f           - */

sbit SERIALIN=P0^0;
sbit CLOCK=P0^2;
sbit LATCH=P0^1;
sbit P10=P1^0;
sbit P11=P1^1;
sbit P12=P1^2;
sbit P14=P1^4;
sbit P15=P1^5;
sbit P16=P1^6;
sbit P17=P1^7;
sbit P32=P3^2;


unsigned char th,tl;
unsigned char coun;
static unsigned int value_buf[5];
unsigned int old_val;
 
void Delay(unsigned int DelayTime)
{
	if (DelayTime == 0)return;
	 	while(DelayTime != 0)
			{DelayTime--; }
}

void computer(unsigned int dt)
{ unsigned char cledtim[5];
  unsigned int dth,dtm,dtl;
  unsigned char i,j,temp;
  	temp=0x01;
	cledtim[4]=Ledbuf[dt/10000];
	dth=dt%10000;
	cledtim[3]=Ledbuf[dth/1000];
	dtm=dth%1000;
	cledtim[2]=Ledbuf[dtm/100];
	cledtim[2]|=0x80;
	dtl=dtm%100;
	cledtim[1]=Ledbuf[dtl/10];
	cledtim[0]=Ledbuf[dtl%10];						

  	   for (i=0; i<4; i++) {
      temp=cledtim[i];
      for (j=0;j<8;j++){
         temp=temp<<1; SERIALIN=CY; CLOCK=1; CLOCK=0;
		}
	}LATCH=0; LATCH=1;			
}


 
void bust_int(void) interrupt 0 using 1
{unsigned int dc;
EA=0;
th=TH0;
tl=TL0;
coun++;
if(coun==5){coun=0;}
	dc=0x0000;
	dc=th;
	dc<<=8;
	dc|=tl;
	dc/=2;
	dc-=10001;
	dc/=10;
    value_buf[coun]=dc;
TH0=0x00;
TL0=0x00;
IE0=0;                      
EA=1;				//12/03
}


unsigned int filter(unsigned int old_value)
{	unsigned int value=0;
	bit zo=0,zt=0;	
	unsigned int temp,temp1,temp2;
    unsigned char count,i,j;
   for (j=0;j<4;j++)
   {
      for (i=0;i<5-j;i++)
      {
         if ( value_buf[i]>value_buf[i+1] )
         {
            temp = value_buf[i];
            value_buf[i] = value_buf[i+1]; 
             value_buf[i+1] = temp;
         }
      }
   }
   for(count=1;count<4;count++)
     { value+= value_buf[count];}
		value/=3;
temp1=value;
temp1-=old_value;
temp2=old_value;
temp2-=value;
if (temp1>2000){zo=0;}else{if(temp1>1){zo=1;}else{zo=0;}}
if (temp2>2000){zt=0;}else{if(temp2>1){zt=1;}else{zt=0;}}

if(zo|zt)
     {return (value);}
else {return old_value;}        
}  

void main()
{   unsigned int ptem,adtem,Hpv,Lpv,Had,Lad,Hout,Lout;
    unsigned int datt,date;
	unsigned long test,tests;
	  	CLOCK=0; 
		LATCH=1;
		TH0=0x00;
		TL0=0x00;
 		P1=0x00;
		TR0=0;
		TMOD=0x09;
		IT0=1;
		TR0=1;
		EX0=1;
		EA=1;
for(;;)
	{
		datt=filter(old_val);
		old_val=datt;
if(old_val<25){datt=0;}     
else{Lad=0;Had=3000;Lout=100;Hout=120;Lpv=250;Hpv=2000;
		ptem=Hpv-Lpv;
		adtem=Had-Lad;
		test=old_val-Lpv;
		test*=adtem;
		tests=Lad;
		tests*=ptem;
		test=test+tests;
        test/=ptem;
		date=test;
		datt=date;}
computer(old_val);
	}
}

⌨️ 快捷键说明

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