STC12C5A60S2内部AD控制NTC温度
时间:10-02
整理:3721RD
点击:
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define FOSC 18432000L
#define BAUD 9600
typedef unsigned char BYTE;
typedef unsigned int WORD;
/*Declare SFR associated with the ADC */
sfr ADC_CONTR = 0xBC; //ADC control register
sfr ADC_RES = 0xBD; //ADC hight 8-bit result register
sfr ADC_LOW2 = 0xBE; //ADC low 2-bit result register
sfr P1ASF = 0x9D; //P1 secondary function control register
//sfr AUXR1 =0xA2;
sfr ADC_RESL =0xBE;
/*Define ADC operation const for ADC_CONTR*/
#define ADC_POWER 0x80 //ADC power control bit
#define ADC_FLAG 0x10 //ADC complete flag
#define ADC_START 0x08 //ADC start control bit
#define ADC_SPEEDLL 0x00 //540 clocks
#define ADC_SPEEDL 0x20 //360 clocks
#define ADC_SPEEDH 0x40 //180 clocks
#define ADC_SPEEDHH 0x60 //90 clocks
/*** ?¨ò? ***/
//#define uint unsigned int
sbit sadd = P2^7; //启动加热按键
sbit P1_1 =P1^1; //温度加热控制位
sbit ntc = P1^0; //AD检测位
void delayms(unsigned int ms) //延时ms程序
{
unsigned char y;
while (ms--)
{
for (y = 0; y < 114; y++)
;
}
}
void temptt2()
{
unsigned int AD_result;
P1ASF=0x01; //P1.0口作为AD使用
// AUXR1=0x04;
ADC_CONTR=0xe0; //ADC电源打开,每90个时钟转换一次,CHS选择P1.0
_nop_();
_nop_();
_nop_();
_nop_();
ADC_RES=0; //清零数据寄存器,初始化结束
ADC_CONTR|=0x08; //ADC_START置1开始转换,(ADC_CONTR=1110 0000),此时 ADC_CONTR=E8
_nop_();
_nop_();
_nop_();
_nop_(); while((ADC_CONTR&0x10)!=0x10); //等待转换完成(ADC_FAAG=1)
AD_result=(ADC_RES<<2)|(ADC_RESL&0x03); //合并高低位数据
//while(1)
//{
if(AD_result>76) //转换完成后,判断值是否大于1.5V,P1.1输出0,否则输出1.
{
P1_1=0;
}
else
{
P1_1=1;
}
ADC_CONTR&=0xef;
//}
}
//主函数
void main()
{
while (1)
{
if(sadd==0)
delayms(20);
if(sadd==0)
{
temptt2();
}
while(!sadd);
}
}
请问各位大神为什么这个程序无法控制根据P1.0采集的AD值来控制P1.1呢?问题不知道出现在哪里了?求救
AD检测
不错,感谢分享