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

📄 hanfa.txt

📁 基于51单片机和ad9850实现的信号发生器程序实现输出1k-1m步进可调
💻 TXT
字号:
源程序
#include<reg51.h>
unsigned char f_h;
unsigned int yichu_count;
bit count_over;
sbit s1=P0^5;
sbit s2=P0^6;
sbit rl=P2^0;
char zixing[10]={ 0x88,0xEB,0x4C,0x49,0x2B,0x19,0x18,0xCB,0x08,0x09};
unsigned long f;
void main(void)
{
     void Delay(char i);
	 char shift_164(char a);
     void test_f(void);
     shift_164(0x88);
	 Delay(200);
	 shift_164(0xEB);
	 Delay(200);
	 shift_164(0x4C);
	 Delay(200);
	 shift_164(0x49);
	 Delay(200);
	 shift_164(0x2B);
	 Delay(200);
    // while(1);
     if(P0^2==0)
          {   
            s1=0;
            s2=1;
			test_f();
         }
	   if(P0^3==0)
          {   
            s1=0;
            s2=0;
			test_f();
         }
	    if(P0^4==0)
          {   
            s1=1;
            s2=0;
			test_f();
         } 
}
void test_f(void)
{
     unsigned long get_f();
	 char x1,x2,x3,x4,x5,x6;
	 void Delay(char i);
loop:    
     f=get_f();
	 if(f==0)
	 {
	   rl=0;
       T0=1;
	   f=get_f();
	   }
	 //           x6=f/100000;
	 x5=(f-x6*100000)/10000;
	 x4=(f-x6*100000-x5*10000)/1000;
	 x3=(f-x6*100000-x5*10000-x4*1000)/100;
	 x2=(f-x6*100000-x5*10000-x4*1000-x3*100)/10;
	 x1=f-x6*100000-x5*10000-x4*1000-x3*100-x2*10;

	 shift_164(zixing[x1]);
	 Delay(200);
	 shift_164(zixing[x2]);
	 Delay(200);
	 shift_164(zixing[x3]);
	 Delay(200);
	 shift_164(zixing[x4]);
	 Delay(200);
	 shift_164(zixing[x5]);
	 Delay(200);
	 shift_164(zixing[x6]);
	 Delay(200);
	 goto loop;
}
//******************************测频率子程序*******************
void intt0_f()interrupt 1//T0作为频率值最高八位,频率值共24位
{
 	f_h=f_h+1;
}
void intt1_time()interrupt 3//T1作为门控时间产生器200US中断一次
{
 	if (yichu_count>=5000)
        {
			TR0=0;//频率停止计数
			TR1=0;//时间停止计数
            EA=0;//关中断
			count_over=1;
			yichu_count=0;
			return;
			}
 	yichu_count=yichu_count+1;
}

unsigned long get_f()
{
 	unsigned long f;
 	count_over=0;
 	TMOD=0X25;
 	TH1=TL1=0X9C;//设置T1计数初值,可以100US中断一次
 	f_h=TH0=TL0=0;//频率值清零
 	count_over=0;//清零计数完成标志
 	EA=1;//开所有中断
 	ET0=1;
 	ET1=1;
 	TR0=1;//频率计数器开始计数
 	TR1=1;//时间计数器开始计时
wait_count_over:
 	if(count_over!=1)
	goto wait_count_over;
 	f=(TL0+TH0*256+f_h*65536);
 	return (f);
 }
void Delay(char i)
{   int j;
    for(;i>0;i--)
    for(j=0;j<125;j++)
    {;}
}
char shift_164(char a)
{
	 SCON=0x00;
	 TI=0x00;
	 SBUF=a;
     if(TI==0)
	 {};
	 return(a);
    
}

⌨️ 快捷键说明

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