查看: 1395|回复: 0
打印 上一主题 下一主题

发个adc0809的程序,有些东西做起来才发现,没有那么的难

[复制链接]
跳转到指定楼层
沙发
发表于 2014-12-12 09:33:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*---------------------------------------------------------------------------------------------------
程序说明:adc0809接到51单片机的P1口,P1口接有8LED,每次转换结束都可以通过LED观察到转换结果(低电平亮),ADC参考电压与单片机的电源要一致
          通过验证:输入5vLED全灭
                    输入0vLED全亮
                    通过电位器控制输入0~5v1602显示输出从0~255逐次增加
------------------------------------------------------------------------------------------------------*/

#include<reg52.h>
#include<intrins.h>
#include"1602.c"
#define uchar unsigned char
#define uint  unsigned int

sbit ADC_START=P2^0;
sbit ADC_ALE  =P2^1;
sbit ADC_OE   =P2^2;
sbit ADC_EOC  =P2^3;
sbit D0=P1^0;
sbit D1=P1^1;
sbit D2=P1^2;
sbit D3=P1^3;
sbit D4=P1^4;
sbit D5=P1^5;
sbit D6=P1^6;
sbit D7=P1^7;
uchar ad_dat;

/*---------------------------------
函数名:delayus(i)
功  能:延时t=(12*i+14)us
参  数:i
返回值:无
备  注: 晶振12MHz
-----------------------------------*/
/*void delayus(i)
{
for(i;i>0;i--);
}

*/
/*---------------------------------
       dac0809初始化
----------------------------------*/
void init0809()
{
ADC_START=0;
ADC_OE   =0;
_nop_();
ADC_ALE=0;
_nop_();
_nop_();
_nop_();
ADC_ALE=1;   //ALE=1时地址进入锁存器
_nop_();
_nop_();
_nop_();
ADC_ALE=0;   //ALE=0时地址被锁存住
_nop_();
_nop_();
_nop_();
}

/*---------------------------------
       dac0809模数转换
----------------------------------*/
void  ADC_0809()
{
ADC_START=1;      //上升沿复位
_nop_();
_nop_();
_nop_();
ADC_START=0;      //下降沿开始
_nop_();
_nop_();
_nop_();
while(!ADC_EOC);  //等待转换结束
ADC_OE =1;
w_dat_1602(0x30+(uchar)D0);
w_dat_1602(0x30+(uchar)D1);
w_dat_1602(0x30+(uchar)D2);
w_dat_1602(0x30+(uchar)D3);
w_dat_1602(0x30+(uchar)D4);
w_dat_1602(0x30+(uchar)D5);
w_dat_1602(0x30+(uchar)D6);
w_dat_1602(0x30+(uchar)D7);
delayus(5);
ADC_OE =0;

}

void main()
{
init0809();
init_1602();
delayus(10);
while(1)
{
  w_com_1602(0x80);
  ADC_0809();
}
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入因仑

本版积分规则

快速回复 返回顶部 返回列表