我的单片机芯片是STC12C5A60S2,我用自带的P1口采集ADC电压,结果按照下面程序串口输出的值一直为0,请教下,哪里有问题啊
#include "includes.h"
#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 FOSC 1843200L
#define BAUD 9600
INT8U ch =0;
void InitUart();
void InitADC();
void Send_Byte(INT8U c)
{
while(!TI); //TI发送中断标志位,手动清零
TI = 0;
SBUF = c;
}
void Delay(INT8U n)
{
INT8U i;
while(n--)
{
i = 5000;
while(i--);
}
}
void main()
{
InitUart();
InitADC();
IE = 0xa0;
while(1);
}
void adc_isr() interrupt 5 using 1
{
ADC_CONTR&= !ADC_FLAG;
//Send_Byte(ch);
Send_Byte(ADC_RES);
//Send_Byte(ADC_RESL);
if(++ch>7)ch = 0;
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START |ch;
}
void InitADC()
{
P1ASF = 0xff;
ADC_RES = 0;
ADC_CONTR = ADC_POWER|ADC_SPEEDLL|ADC_START|ch;
Delay(2);
}
void InitUart()
{
SCON = 0x5a;
TMOD = 0x20;
TH1 = TL1 =-(FOSC/12/32/BAUD);
TR1 = 1;
} |