单片机 STC 12C5A60S2 AD 疑问
时间:10-02
整理:3721RD
点击:
STC 12C5A60S2 自带AD 有个疑问, 下边是我写的。 就是在 ADC_FLAG 没有办法直接操作, 比如ADC_FLAG 为1 后要软件清0 ,没有办法 ADC_FLAG=0, 编译的时候出错
#include <STC12C5a60s2.H>
#include <intrins.H>
#define uchar unsigned char
#define uint unsigned int:
unsigned int x,g;
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0xef};
sbit shi=P2^4;
sbit ge=P2^5;
void delay1ms() //1ms 延时
{
unsigned char i, j;
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
void xs(x)
{
shi=0;
P0=tab[x/10];
delay1ms();
shi=1;
delay1ms();
ge=0;
P0=tab[x%10];
delay1ms();
ge=1;
delay1ms();
}
void main()
{
P1ASF=0x01; //P1.0 做为ADC 输入
ADC_CONTR=0xc0; //开ADC电源,180周期转换一次,标志位清0,P1.0做为输入
AUXR1=0x03; // 结果 高8位放 RES 低8位放 RESL
g=ADC_RESL; // 结果 取8位放 g
ADC_CONTR=0xc8; // 开始转换
delay1ms(); // 等一会方便读到 ADC_TCNTR值
while(1)
{
while( ADC_FLAG==0); //等待 转换完成
ADC_CONTR=0xc0;
x=g*50/256;
xs(x );
}
}
compiling AD 采样.c...
AD 采样.c(44): error C202: 'ADC_FLAG': undefined identifier
AD 采样.c - 1 Error(s), 0 Warning(s).
我看了他官方的程序 不太清白 :#define ADC_FLAG 0x10 这是什么意思,不知道它想表达什么,是数据,还是地址,是地址的话他有什么意义呢? 谢谢了
#include <STC12C5a60s2.H>
#include <intrins.H>
#define uchar unsigned char
#define uint unsigned int:
unsigned int x,g;
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0xef};
sbit shi=P2^4;
sbit ge=P2^5;
void delay1ms() //1ms 延时
{
unsigned char i, j;
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
void xs(x)
{
shi=0;
P0=tab[x/10];
delay1ms();
shi=1;
delay1ms();
ge=0;
P0=tab[x%10];
delay1ms();
ge=1;
delay1ms();
}
void main()
{
P1ASF=0x01; //P1.0 做为ADC 输入
ADC_CONTR=0xc0; //开ADC电源,180周期转换一次,标志位清0,P1.0做为输入
AUXR1=0x03; // 结果 高8位放 RES 低8位放 RESL
g=ADC_RESL; // 结果 取8位放 g
ADC_CONTR=0xc8; // 开始转换
delay1ms(); // 等一会方便读到 ADC_TCNTR值
while(1)
{
while( ADC_FLAG==0); //等待 转换完成
ADC_CONTR=0xc0;
x=g*50/256;
xs(x );
}
}
compiling AD 采样.c...
AD 采样.c(44): error C202: 'ADC_FLAG': undefined identifier
AD 采样.c - 1 Error(s), 0 Warning(s).
我看了他官方的程序 不太清白 :#define ADC_FLAG 0x10 这是什么意思,不知道它想表达什么,是数据,还是地址,是地址的话他有什么意义呢? 谢谢了
