huarens 发表于 2014-3-29 11:52
看着好像没什么问题,可能编译器的问题吧!
不过最好把完整的程序贴上来,包括变量的定义! ...
#include <msp430x13x.h> //Can use , have dot,but sllowlly
unsigned int results,ResultBuff;
unsigned char LedNumber[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x00, //Close one nixie_tube
0x38,0x5c,0x76,0x30}; // "L" ,"O", "H","I"
unsigned char buff[]={9,9,9,9};
void TimerA_Init(void)
{
WDTCTL = WDTPW+WDTHOLD;
BCSCTL1=BIT7+BIT6; // Close XT2 ,LFXT1 choose hight medol //
// BCSCTL2 = SELS + DIVS1; // ?? 4MHz 4 frequency dividing 1MHz
TACTL =TASSEL0+ ID_2+MC0+TACLR; // 0000 00 01 00 01 01 00
// Unuse ACLK ID bit67 MC bit4,5 TACLR set1
// 4 divide increase model clear
CCTL0 = CCIE; // Not TACTL|=TAIE,Because that is overflow interrupt . Enable compare and capture interrupt//
CCR0 =1000; //Generate 1mS
P5DIR=0Xff;
P5OUT=0XFF;
P4DIR=0X18;
P1DIR=0X03;
TACTL|=MC0;
_EINT();
}
void ADC_Init(void)
{
WDTCTL = WDTPW+WDTHOLD;
P6SEL |=BIT6; //P6_6 Set to ADC
ADC12CTL0 &= ~ENC; //Clear the ENC
ADC12CTL0=ADC12ON+REFON+REF2_5V+SHT0_2+MSC; //Start internal core ,refer source,choice 2.5v,
// sampling holding time 4*T_clock*N, multiply sampling control.
ADC12CTL1=ADC12SSEL_0+SHP+CONSEQ_2+CSTARTADD_4 ; //clock Source select,SHP is up edge,convert sequence modul ,
// convert store start addrss(0-15)Memery //
ADC12MCTL4=SREF_0+INCH_6+EOS; //2.5v,ADC0,end sign
//Memery control :+is AVcc(3.3v),
//-is AVss (system analog power ground) ,input channel ADC0 P6.0/A0
//ADC12MCTLx must match CSTARTADDx,
ADC12IE|= BIT4; //but Channel number does not match the Memery number,you should choice youself //
_EINT();
ADC12CTL0|= ENC+ADC12SC;
}
void main(void)
{
unsigned int j=0;
TimerA_Init();
ADC_Init();
while(1)
{
if(results<300)P1OUT=0X03; //1.4V do not have flowing
else P1OUT=0;
j++;
if(j==10) // Should not use "j=1000"
{
j=0;
ResultBuff=results*4+results/2; //results*4.5
}
buff[0]=ResultBuff%10;
buff[1]=ResultBuff/10%10;
buff[2]=ResultBuff/100%10;
buff[3]=ResultBuff/1000%10;
}
}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A(void) //timerA
{
static unsigned int i=0;
//////////////////////////////////////////////////////
//Becaerful ,here you can not add instruct any more//
// //
/////////////////////////////////////////////////////
P5OUT=0;
switch(i)
{
case 3 : {P4OUT=0X00;break;} //X0 last left,lay most bit
case 2 : {P4OUT=0X08;break;}
case 1 : {P4OUT=0X10;break;}
case 0 : {P4OUT=0X18;break;} //X3 last right
}
if(i==3)P5OUT=(LedNumber[buff]|BIT7);
else P5OUT=LedNumber[buff];
// P5OUT=LedNumber[buff];
i++;
if(i>3)i=0;
ADC12CTL0|=ENC+ADC12SC;
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12_IRQ(void) //C++ use #pragma vector=ADC_VECTOR Pre_excute instruct //
{
ADC12CTL0&=~ENC; //Stop ADC //
results=ADC12MEM4;
// if(results>1500)
// P1OUT=0X03;
// else P1OUT=0X00;
// ADC12CTL0|=ENC+ADC12SC; //Enable ADC again //
} //Must close here ,else can not
//go to timerA interrupt nomal
|