分享

ADC0809与单片机仿真

 共同成长888 2015-07-13

ADC0809与单片机仿真 

点击查看原图 adc0809单片机仿真 

程序:

//************ccp************//

#include<reg51.h>
#include<AD0809.h>

void main()  //主函数

 init_timer0();
   while(1)
   {
     handle_ad();
   }
}


void init_timer0()
{
 TMOD=0x02; //2
    TH0=0x14;//TH0=256-236;
    TL0=0x14; //TL0=256-236;
    IE=0x82;
    TR0=1;
}

void start()
{
  ST=0;
    ST=1;
    ST=0;
}

void set_OE()
{
 OE=1;
}

void clr_OE()
{
 OE=0;
}

void delay(uint t)   // delay 
{
 uchar i;
    while(t--)
 {
  for(i=0;i<120;i++);
 }
}
 
//*******数码管显示*******
void display()
{
 unsigned char j;
 for(j=0;j<=3;j++)
 { 
  P2=ledwei[j];
  if(j==1)
  {
   P0=display_c[count[j]];
   delay(1);
  }
  P0=display_cc[count[j]];
  delay(1);
 }
}

void handle(uint num)
{
 num=num*250;
 num= num/256;
 num=num*40; 
 count[0]=  num %10;
 count[1]=  num %100/10;     
 count[2]=  num %1000/100;
 count[3]=  num /1000;
}

void handle_ad()
{
 start();
    while(EOC==0);//等待转换结束,转换EOC=0
 set_OE();
    handle(P3);
    display();  // OE=0;   //高阻
 clr_OE();   //高阻
}

void timer0() interrupt 1
{

   CLK=~CLK;
}

 

//*************ccp*********************//

 

#ifndef _D0809_
#define _0809_

#include<reg51.h>

#define uint unsigned int
#define uchar unsigned char
uchar code display_cc[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共阴
uchar code display_c[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//共阴
uchar code ledwei[]={0xf7,0xfb,0xfd,0xfe};  
static uint count[]={0,0,0,0};  
sbit CLK=P1^3;
sbit ST=P1^2;
sbit EOC=P1^1;
sbit OE=P1^0;

//定义函数
void init_timer0(); //初始化
void start();
void set_OE();
void clr_OE();
void delay(uint t);
void display();
void handle(uint num);
void handle_ad();    //处理


#endif

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多