无语了 STC12C5410AD 到底有没AD采集中断啊?????
无语了STC12C5410AD 到底有没AD采集中断啊????? ADCONVERT() interrupt 5 using 1没用过STC12C5410AD,我现在用STC12C5612AD,用上面的就可以进中断 中断向量号为5? 那有没有T2? 好像STC的几款不同型号向量号都有所不同 回复【1楼】eaglelpx
adconvert() interrupt 5 using 1
没用过stc12c5410ad,我现在用stc12c5612ad,用上面的就可以进中断
-----------------------------------------------------------------------
回复【2楼】amazing030
中断向量号为5? 那有没有t2? 好像stc的几款不同型号向量号都有所不同
-----------------------------------------------------------------------
解决了哈 原来在AUXR里面设置,跟IE里那个搞混了
#include <STC12C5410AD.H>
#define FOSC 11059200L
#define BAUD 9600
#define ucharunsigned char
#define uintunsigned int
void InitUart();
void SendData(uchar dat);
void Delay(uint n);
void InitADC();
voidInitPCA() ;
uchar ch = 0; //ADC channel NO.
void main()
{
InitUart(); //Init UART, use to show ADC result
InitADC(); //Init ADC sfr
InitPCA() ;
IE = 0xa0; //Enable ADC interrupt and Open master interrupt switch
while (1) ;
}
/*----------------------------
ADC interrupt service routine
----------------------------*/
void adc_isr() interrupt 5
{
ADC_CONTR &= !ADC_FLAG; //Clear ADC interrupt flag
if(ch==0)
{
CCAP0L=ADC_DATA;
CCAP0H=ADC_DATA;
}
if(ch==1)
{
CCAP1L=ADC_DATA;
CCAP1H=ADC_DATA;
}
if(ch==2)
{
}
if (++ch > 1) ch = 0; //switch to next channel
ADC_CONTR = ADC_POWER | ADC_SPEED1 | ADC_SPEED1 | ADC_START | ch;
}
/*----------------------------
Initial ADC sfr
----------------------------*/
void InitADC( )
{
P1M0 = 0xff; //Set all P1 as analog input port
P1M1=0x00;
ADC_DATA = 0; //Clear previous result
AUXR |=0x10;
ADC_CONTR = ADC_POWER | ADC_SPEED1 | ADC_SPEED1 | ADC_START | ch;
Delay(2); //ADC power-on delay and Start A/D conversion
}
/*----------------------------
Initial UART
----------------------------*/
void InitUart()
{
SCON = 0x5a; //8 bit data ,no parity bit
TMOD = 0x20; //T1 as 8-bit auto reload
TH1 = TL1 = -(FOSC/12/32/BAUD); //Set Uart baudrate
TR1 = 1; //T1 start running
}
/*----------------------------
Send one byte data to PC
Input: dat (UART data)
Output:-
----------------------------*/
void SendData(uchar dat)
{
ES=0;
while (!TI); //Wait for the previous data is sent
TI = 0; //Clear TI flag
SBUF = dat; //Send current data
ES=1;
}
/*----------------------------
Software delay function
----------------------------*/
void Delay(uint n)
{
uint x;
while (n--)
{
x = 5000;
while (x--);
}
}
void RXD_Int() interrupt 4
{
uchar a;
if(RI){
a=SBUF;
SBUF=a;
RI=0;
}
}
voidInitPCA()
{
CMOD=0x02;
CL=0x00;
CH=0x00;
CCAP0L=0xFF;
CCAP0H=0xFF;
CCAPM0=0x42;
CCAP1L=0xFF;
CCAP1H=0xFF;
CCAPM1=0x42;
CR=1;
}
页:
[1]