interrupt [ADC_VECTOR] void ADC12(void)
书上interrupt可以这样
#include <msp430x14x.h>
void Init(void);
interrupt [ADC_VECTOR] void ADC12(void);
unsigned int Result;
unsigned int Table[4][10]={{0x040,0x0BC,0x0138,0x1B4,0x230,0x2AC,
0x328,0x3A4,0x420,0x49c},{0x518,0x594,0x610,0x68C,0x708,0x800,0x87C,
0x8F8,0x974},{0x9F0,0xA6C,0xAE8,0XB64,0xBE0,0xC5C,0xC08,0xD54,0xDD0,
0xE4C},{0xEC8,0xF44,0xFC0,0xFFF}};
void main(void)
{
P4DIR=0xFF;
P5DIR=0xFF;
Init();
_EINT();
ADC12CTL0|=ENC+ADC12SC;
while(1);
}
void Init(void)
{
WDTCTL=WDTPW+WDTHOLD;
P6SEL|=0x01;
ADC12CTL0&=~ENC;
ADC12CTL0=ADC12ON+SHT0_2+REFON+REF2_5V;
ADC12CTL1=SHP+CONSEQ_2;
ADC12MCTL0=SREF_0;
ADC12IE|=BIT0;
}
interrupt [ADC_VECTOR] void ADC12(void)
{
unsigned char seg_7[10]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,
0xDF,0x87,0xFF,0xEF};
unsigned char seg_8[10]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,
0xDF,0x87,0xFF,0xEF};
unsigned i,j;
ADC12CTL0&=~ENC;
for(i=0;i<4;i++)
{
for(j=0;j<10;j++)
{
if(ADC12MEM0<=Table[i][j])
goto xxx;
}
}
xxx:{
P4OUT=seg_7[j];
P5OUT=seg_8[i];
ADC12CTL0|=ENC+ADC12SC;
}
} |