使用STC8H1K08单片机,其ADC1(P11口)作为ADC输入口,程序进入ADC中断让LED灭,但一次没灭过,也就是没有进入过ADC中断的意思?请问是什么原因呢?
# include <STC8.h>
# include <intrins.h>
#include <stdio.h>
sbit LED = P3 ^ 4;
unsigned int adc1;
void Init_IO()
{
P0M1 = 0x00;
P0M0 = 0x00;
P1M1 = 0x00;
P1M0 = 0x00;
P2M1 = 0x00;
P2M0 = 0x00;
P3M1 = 0x00;
P3M0 = 0x00;
P4M1 = 0x00;
P4M0 = 0x00;
P5M1 = 0x00;
P5M0 = 0x00;
P6M1 = 0x00;
P6M0 = 0x00;
P7M1 = 0x00;
P7M0 = 0x00;
}
void adcIsr(void) interrupt 5 //ADC中断
{
ADC_CONTR &= ~0x20; //清中断标志
adc1=ADC_RES; //高位值
adc1+=ADC_RESL; //低位值
printf("ADC ISR value=%d",adc1); //打印输出
ADC_RES=0;//高八位寄存器清零
ADC_RESL = 0;//低八位寄存器清零
LED=0; //判断是否进入ADC中断
ADC_CONTR |= 0x40; //继续AD转换
}
void main()
{
LED = 1;
P_SW2 |= 0x80;
Init_IO();
P1M0 = 0x00;
P1M1 = 0x02; //P11为高阻输入模式,作为ADC输入口
ADCTIM = 0x3f; //设置ADC内部时序
ADCCFG = 0x0f; //设置ADC时钟为系统时钟/2/16,左对齐
ADC_CONTR =0x81; //使能ADC模块,使能ADC1
EADC=1; //使能ADC中断
EA=1; //总中断
ADC_CONTR |= 0x40; //启动AD转换
while (1);
}
|