【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《模数转换C程序》,欢迎阅读!
/************************************************
硬件结构框架:
1,八位AD转换芯片ADC0804
2,MCU STC89C52
显示效果:
1,调节模拟电压量的值在数码管上显示
相关知识点:
1,类似ADC0804数模转换的操作
************************************************/
#include"AT89x52.h"
#include"intrins.h"
#include"math.h"
#define uint unsigned int
#define uchar unsigned char
sbit ADC0804_SC=P3^5;
sbit ADC0804_RD=P3^7;
sbit ADC0804_WR=P3^6;
sbit DUAN=P2^0; //74HC573的LE端 LED的段选端
sbit WEI=P2^1; //74HC573的LE端 LED的位选端
sbit SJ=P1^4; //LED的使能端
uchar Temp[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //共阴显示字库
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void adc0804_start() //AD0804的启动函数
{
ADC0804_WR=1;
ADC0804_WR=0;
ADC0804_WR=1;
}
void wei_1(uchar wei)
{
WEI=1;
P0=wei;
WEI=0;
}
void duan_1(uchar duan)
{
uint i;
DUAN=1;
P0=Temp[duan];
DUAN=0;
for(i=150;i>0;i--);
}
show(uchar DATA) //显示
{
uint a,b,c;
a=DATA%100%10;
b=DATA%100/10;
c=DATA/100;
wei_1(0xdf);
duan_1(c);
wei_1(0xbf);
duan_1(b);
wei_1(0x7f);
duan_1(a);
wei_1(0xff);
}
main()
{
uchar ADC0804_data;
ADC0804_SC=0; //让SC一直为低
while(1)
{
adc0804_start(); //启动ADC0804
delay(5); //延时
ADC0804_RD=0; //RD为低
delay(5); //延时
ADC0804_data=P1; //将ADC0804的数据传出
delay(5); //延时
ADC0804_RD=1; //RD为高
delay(5); //延时
show(ADC0804_data); //把数据让数码管显示出来,
} //这个函数在原来的动态扫描中直接调用就行了
}
本文来源:https://www.wddqxz.cn/9ad90c5428f90242a8956bec0975f46526d3a700.html