请大家帮忙看下 我的stc12c5608ad芯片AD转换程序哪里错了 采集不到AD
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define u8 unsigned char
#define u16 unsigned int
sfr P1M0=0x91;//单片机特殊寄存器地址
sfr P1M1=0x92;
sfr ADC_CONTR=0xc5;
sfr ADC_DATA=0xc6;
sfr ADC_LOW2=0xbe;
sfr AUXR=0x8e;
sbit PWM=P2^1;
sbit LED=P2^0;
u16 ad,n,t,adc[4];
void delay(u16 z) [url=]//@12.000MHz[/url]
{
u16 x, y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
P1M0=0x01; //配置IO
P1M1=0x01;
ADC_CONTR=0x80;//打开AD
TMOD=0x01;
IE=0xa2;
TR0=1;
}
main()
{
init();
LED=1;
delay(500);
while(1)
{
ADC_CONTR=0x88;
while(!(ADC_CONTR&0x10));
ad=ADC_DATA;
ADC_CONTR=0x80;
if(t<ad)
PWM=1;
else
PWM=0;
}
}
void et0()interrupt 1//T0定时器
{
t++;
if(t>255)
t=0;
TH0=0xff;
TL0=0xf6;
}
#define u8 unsigned char
#define u16 unsigned int
sfr P1M0=0x91;//单片机特殊寄存器地址
sfr P1M1=0x92;
sfr ADC_CONTR=0xc5;
sfr ADC_DATA=0xc6;
sfr ADC_LOW2=0xbe;
sfr AUXR=0x8e;
sbit PWM=P2^1;
sbit LED=P2^0;
u16 ad,n,t,adc[4];
void delay(u16 z) [url=]//@12.000MHz[/url]
{
u16 x, y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
P1M0=0x01; //配置IO
P1M1=0x01;
ADC_CONTR=0x80;//打开AD
TMOD=0x01;
IE=0xa2;
TR0=1;
}
main()
{
init();
LED=1;
delay(500);
while(1)
{
ADC_CONTR=0x88;
while(!(ADC_CONTR&0x10));
ad=ADC_DATA;
ADC_CONTR=0x80;
if(t<ad)
PWM=1;
else
PWM=0;
}
}
void et0()interrupt 1//T0定时器
{
t++;
if(t>255)
t=0;
TH0=0xff;
TL0=0xf6;
}
