#include
//********************************************
//表区
unsigned char display_par[10]={0xbe,0x84,0x37,0x97,0x8d,0x9b,0xbb,0x8e,0xbf,0x9f};
unsigned char timp,i=0;
//变量区
unsigned char display_buffer[]={0,0,0,0};
unsigned long ADC0 ;
void ADC12setup(void)//ADC12初始化
{
//ADC12设置**************************
P6SEL |= 0x01; //使用A/D通道 A0
ADC12CTL0 = ADC12ON ; //开ADC12内核,设SHT0=2 (N=4)
ADC12CTL1 = SHP ; //SAMPCON信号选为采样定时器输出
ADC12MCTL0 |= SREF_0; //R+=AVCC R-=VSS //转换允许
ADC12CTL0 |= ENC ; //转换允许(上升沿)
ADC0=0x00;
}
void data_converter(unsigned int value) //数据变换
{
display_buffer[0]=value/1000;
display_buffer[1]=value%1000/100;
display_buffer[2]=value%1000%100/10;
display_buffer[3]=value%1000%100%10;
}
void int_io(void)
{
WDTCTL = WDTPW + WDTHOLD; // 停止WDT
P1DIR=0x01;P1OUT=0x0f; //LED设置
P4DIR=0xff;P4OUT=0xff; //LED设置
P5DIR=0xff;P5OUT=0x00; //LED设置
ADC12setup();
// _EINT(); // 全局中断使能
}
void display_led(void)
{
unsigned char a;
a=0;
P4OUT=0xff;
P5OUT=0x00;
if(i==0){P4OUT=0xbf;a=0x40;}
if(i==1)P4OUT=0xdf;
if(i==2)P4OUT=0xef;
if(i==3)P4OUT=0x7f;
P5OUT=display_par[display_buffer]|a;
i++;if(i>3)i=0;
}
void main(void)
{
unsigned char n=0;
unsigned long bb,aa[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int_io();
while(1)
{
ADC12CTL0 |= ADC12SC; //sampling open,AD转换完成后(ADC12BUSY=0),ADC12SC自动复位;
while((ADC12IFG & BIT0) == 0); //等转换结束
bb = ADC12MEM0; //读转换数据值,同时清ADC12IFG0标志
if(bb<3)bb=0;
aa[n]=bb;
if(n==0)ADC0=(((aa[0]+aa[1]+aa[2]+aa[3]+aa[4]+aa[5]+aa[6]+aa[7]+aa[8]+aa[9]
+aa[10]+aa[11]+aa[12]+aa[13]+aa[14]+aa[15])>>4)*808)/1000;
data_converter(ADC0) ;
display_led();
n++;if(n>15)n=0;
}
}
|