C51 ADC0804LCN 应用

来源:互联网 发布:大数据商机 编辑:程序博客网 时间:2024/05/19 22:59

这里写图片描述

#include<reg51.h>  //stdio.h,string.h用于printf函数原型  #include<stdio.h>  #include<INTRINS.H>sbit AD_CS = P1^2; sbit AD_WR = P1^0;sbit AD_RD = P1^1;sbit AD_PORT = P0;/****************************************  启动ADC****************************************/void AdcStart(void){    AD_CS = 0;    _nop_();    AD_WR = 0;    _nop_();    AD_WR = 1;    _nop_();    AD_CS = 1;    _nop_();}/****************************************  读取ADC值****************************************/int AdcRead(void){    int temp;    AD_PORT = 0xFF; //单片机读取AD值之前PORT口先写高       AD_CS = 0;    _nop_();    AD_RD = 0;    _nop_();    _nop_();    _nop_();    temp = P0;    _nop_();    AD_RD = 1;    _nop_();    AD_CS = 1;    _nop_();    return temp;}