#include
#include
#define uint unsigned int
#define uchar unsigned char
sfr P1ASF = 0X9D; //P1口挑选功用寄存器
sfr ADC_CONTR = 0XBC; //ADC操控寄存器
sfr ADC_RES = 0XBD; //ADC转化成果寄存器高
sfr ADC_RESL = 0XBE; //ADC转化成果寄存器低
sfr AUXR1 = 0XA2; //ADC转化成果调整位
//sfr IE = 0XA8; //ADC中止答应寄存器
//sfr IP = 0XB8; //ADC中止优先级操控寄存器高
//sfr IPH = 0XB7; //ADC中止优先级操控寄存器低
uint ADC_Result1, ADC_Result2, ADC_Result;
void ADC_init(void); //AD转化初始化
void Delay(uint z); //延时函数
void main(void)
{
uint gei, shi, bai, qian;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
while (1)
{
ADC_init();
ADC_Result = ADC_Result2 + ADC_Result1 * 256;
gei = ADC_Result % 10;
shi = ADC_Result / 10 % 10;
bai = ADC_Result / 100 % 10;
qian = ADC_Result / 1000;
//数码管动态显现显现收集数值
P2 = 1;
P0 = table[qian];
Delay(5);
P2 = 2;
P0 = table[bai];
Delay(5);
P2 = 3;
P0 = table[shi];
Delay(5);
P2 = 4;
P0 = table[gei];
Delay(5);
}
}
void ADC_init(void) //AD转化初始化
{
P1ASF = 0X01; //X挑选P1.0作为ADC转化输入通道
ADC_CONTR = 0X80; //翻开ADC转化电源
_nop_();
_nop_();
AUXR1 = 0X04; //将高两位存放在寄存器ADC_RES,低八位存放在寄存器ADC_RESL中
ADC_CONTR |= 0X68; //ADC初始化设置
_nop_();
_nop_();
_nop_();
_nop_ ();
ADC_Result1 = ADC_RES;
ADC_Result2 = ADC_RESL;
}
void Delay(uint z) //延时函数
{
uint x, y;
for (x = 0; x < z; x++)
for (y = 0; y < 140; y++);
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/xinpin/yuanjian/261588.html