51单片机,ADC0808芯片,AD转换电压采集!!
#include<reg51.h>sbitOE=P2^3;sbitEOC=P2^2;sbitST=P2^1;sbitCLK=P2^0;sbitADDRA=P2^5;sbi...
#include<reg51.h>
sbit OE=P2^3;
sbit EOC=P2^2;
sbit ST=P2^1;
sbit CLK=P2^0;
sbit ADDRA=P2^5;
sbit ADDRB=P2^6;
sbit ADDRC=P2^7;
void delayms(unsigned int ms)
{ unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<1141;i++);}
void delayus(unsigned int us)
{ unsigned int i;
for(i=0;i<us;i++) ;}
void inituart(void){
SCON=0x50;
TMOD=0x22;
PCON=0x00;
TH1=0xfd;
TL1=0xfd;
TI=1;
TR1=1;}
void send(unsigned char x)
{ SBUF=x;
while(TI==0);
TI=0;}
void main(){
unsigned char temp;
inituart();
TH0=0x14;
TL0=0x00;
ET0=1;
TR0=1;
EA=1;
while(1){
delayms(100);
ADDRA=1;
ADDRB=0;
ADDRC=0;
ST=0;
ST=1;
delayus(10);
ST=0;
while(EOC==0);
OE=1;
delayus(10);
temp=P1;
OE=0;
send(P1);
delayms(100);
ADDRA=0;
ADDRB=0;
ADDRC=1;
ST=0;
ST=1;//ST上升沿,复位
delayus(10);
ST=0;//ST下降沿,启动A/D转换
while(EOC==0);//EOC=1时,A/D转换结束
OE=1;//打开输出三态门
delayus(10);
temp=P1;
OE=0;
send(temp);
delayms(100);
ADDRA=1;
ADDRB=1;
ADDRC=1;
ST=0;
ST=1;
delayus(10);
ST=0;
while(EOC==0);
OE=1;
delayus(10);
temp=P1;
OE=0;
send(temp);
}}
void Timer0_INT()interrupt 1{CLK=!CLK;}
大神,我这个程序能把采集到的信号从串口输出吗?我用proteus仿真了好多次,不知道哪里的问题!求助! (1,4,7口输入的信号!) 展开
sbit OE=P2^3;
sbit EOC=P2^2;
sbit ST=P2^1;
sbit CLK=P2^0;
sbit ADDRA=P2^5;
sbit ADDRB=P2^6;
sbit ADDRC=P2^7;
void delayms(unsigned int ms)
{ unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<1141;i++);}
void delayus(unsigned int us)
{ unsigned int i;
for(i=0;i<us;i++) ;}
void inituart(void){
SCON=0x50;
TMOD=0x22;
PCON=0x00;
TH1=0xfd;
TL1=0xfd;
TI=1;
TR1=1;}
void send(unsigned char x)
{ SBUF=x;
while(TI==0);
TI=0;}
void main(){
unsigned char temp;
inituart();
TH0=0x14;
TL0=0x00;
ET0=1;
TR0=1;
EA=1;
while(1){
delayms(100);
ADDRA=1;
ADDRB=0;
ADDRC=0;
ST=0;
ST=1;
delayus(10);
ST=0;
while(EOC==0);
OE=1;
delayus(10);
temp=P1;
OE=0;
send(P1);
delayms(100);
ADDRA=0;
ADDRB=0;
ADDRC=1;
ST=0;
ST=1;//ST上升沿,复位
delayus(10);
ST=0;//ST下降沿,启动A/D转换
while(EOC==0);//EOC=1时,A/D转换结束
OE=1;//打开输出三态门
delayus(10);
temp=P1;
OE=0;
send(temp);
delayms(100);
ADDRA=1;
ADDRB=1;
ADDRC=1;
ST=0;
ST=1;
delayus(10);
ST=0;
while(EOC==0);
OE=1;
delayus(10);
temp=P1;
OE=0;
send(temp);
}}
void Timer0_INT()interrupt 1{CLK=!CLK;}
大神,我这个程序能把采集到的信号从串口输出吗?我用proteus仿真了好多次,不知道哪里的问题!求助! (1,4,7口输入的信号!) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询