首页 > 代码库 > A//D转换
A//D转换
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit adwr=P3^6;
sbit adrd=P3^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71
};
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=100;j>0;j--);
}
void display(uchar bai,uchar shi,uchar ge)
{
dula = 1;
P0=table[bai];
dula = 0;
P0=0xff;
wela=1;
P0=0x7e;
wela=0;
delayms(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0x7d;
wela=0;
delayms(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0x7b;
wela=0;
delayms(5);
}
void main()
{
uchar a,A1,A2,A3,adval;
wela=1;
P0=0x7f;
wela=0;
while(1)
{
adwr=1; //启动A/D转换使能
_nop_();
adwr=0;
_nop_();
adwr=1;
for(a=10;a>0;a--)
{
display(A1,A2,A3);
}
P1=0xff;
adrd=1;
_nop_();
adrd=0;
_nop_();
adval=P1;
adrd=1;
A1=adval/100;
A2=adval%100/10;
A3=adval%10;
}
}
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit adwr=P3^6;
sbit adrd=P3^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71
};
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=100;j>0;j--);
}
void display(uchar bai,uchar shi,uchar ge)
{
dula = 1;
P0=table[bai];
dula = 0;
P0=0xff;
wela=1;
P0=0x7e;
wela=0;
delayms(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0x7d;
wela=0;
delayms(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0x7b;
wela=0;
delayms(5);
}
void main()
{
uchar a,A1,A2,A3,adval;
wela=1;
P0=0x7f;
wela=0;
while(1)
{
adwr=1; //启动A/D转换使能
_nop_();
adwr=0;
_nop_();
adwr=1;
for(a=10;a>0;a--)
{
display(A1,A2,A3);
}
P1=0xff;
adrd=1;
_nop_();
adrd=0;
_nop_();
adval=P1;
adrd=1;
A1=adval/100;
A2=adval%100/10;
A3=adval%10;
}
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。