找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1619|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

AD 轉(zhuǎn)換

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:224362 發(fā)表于 2017-8-3 14:03 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code duan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code wei[4]={0xf7,0xfb,0xfd,0xfe };
uchar buffer[3];
uchar ad_cov();
void delay(void);
void init();
sbit ALE=P3^3;
sbit START=P3^4;
sbit OE=P3^5;
sbit EOC=P2^7;
sbit CLK=P3^7;
void main()
{
init();
while(1)
{
  uchar ad;
  uchar k;
  float adf;
  ad=ad_cov();
  adf=(ad/256.0)*5.0;
  for(k=0;k<3;k++)
  {
   uchar i1,i2,i3;
   i1=(int)(adf*100)/100;//個(gè)位 //456
   i2=(int)(adf*100)/10%10;//十分位
   i3=(int)(adf*100)%10;  //百分位
   P2=wei[0];
   P0=duan[i3];
   delay();
   P2=wei[1];
   P0=duan[i2];
   delay();
   P2=wei[2];
   P0=duan[i1]+0x80;
   delay();
  }  
}
}
uchar ad_cov()
{
uchar ad_data;
P3=0x00;
ALE=1;_nop_();_nop_();ALE=0;
START=1;_nop_();_nop_();START=0;
while(!EOC);
OE=1;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
ad_data=P1;
OE=0;
return(ad_data);
}
void delay(void)
{
int i;
i=100;
while(i--);
}
void init()
{
TMOD=0X02;
TH0=156;TL0=156;
EA=1;
ET0=1;
TR0=1;
}
void TIMER0() interrupt 1
{
CLK=~CLK;
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:245836 發(fā)表于 2017-11-4 11:32 | 只看該作者
可以可以
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表