專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機教程網(wǎng) >> MCU設(shè)計實例 >> 瀏覽文章

ADC0804 模數(shù)轉(zhuǎn)換51單片機程序+電路圖

作者:huqin   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2014年10月24日   【字體:

51單片機驅(qū)動 adc0804模數(shù)轉(zhuǎn)換 ,下面是電路圖

 

 

#include<reg51.h>
#include "lcd.h"
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char

uchar lcd[]="0123456789";
sbit rd=P3^6; //IO口定義
sbit wr=P3^5;
sbit cs=P3^7;

read_adc0804()//控制并讀取adc0804轉(zhuǎn)換好的數(shù)據(jù)
{
 uchar a;          //寫入控制命令,啟動轉(zhuǎn)換
 cs=1;
 wr=1;
 cs=0;
 wr=0;
 _nop_();
 wr=1;
  
 P1=0xff;         //讀取已轉(zhuǎn)換好的數(shù)據(jù)
 rd=1;
 rd=0;
 _nop_();
 a=P1;
 rd=1;
 cs=1; 
 
 return a;
}

void main()
{
uchar a,A1,A2,A3;
lcd_init();
while(1)
 {
 a=read_adc0804();
 A1=a/100; //分出百,十,和個位
 A2=a%100/10;
 A3=a%10;
 lcd_busy();
 lcd_xy(3,0);
 lcd_write_dat(lcd[A1]);
 lcd_busy();
 lcd_xy(4,0);
 lcd_write_dat(lcd[A2]);
 lcd_busy();  
 lcd_xy(5,0);
 lcd_write_dat(lcd[A3]);
 }

關(guān)閉窗口