void ADC()
{
P6SEL |= (BIT1+BIT2+BIT3); // 将 P6.5 选择为ADC 输入端 上电后IO口默认为输入
ADC12CTL0 = ADC12SHT02 + ADC12ON +ADC12MSC;
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_3; // ADC12SHT02——设置采样保持时间,ADC12ON——打开采样时钟
// 使用采样定时器;选择4种模式,0、2为单路,1、3为多路
// ADC12IE |= BIT0; // 允许中断 //中断使能寄存器
ADC12MCTL0 = ADC12INCH_0; // 使能转换
ADC12MCTL1 = ADC12INCH_1;
ADC12MCTL2 = ADC12INCH_2;
ADC12MCTL3 = ADC12INCH_3;
ADC12MCTL4 = ADC12INCH_4;
ADC12MCTL5 = ADC12INCH_5;
ADC12MCTL6 = ADC12INCH_6;
ADC12MCTL12 = ADC12INCH_12;
ADC12CTL1|= ADC12ENC; // 启动转换
}
void xianshi()
{
ii++;
if(ii>50)
{
LCD_CLS();
ii=0;
}
LCD_P6x8Str(6,1,"JY");
LCD_P6x8Str(24,1,"CQ");
LCD_P6x8Str(42,1,"MY");
LCD_P6x8Str(66,1,"X");
LCD_P6x8Str(90,1,"Y");
LCD_P6x8Str(0,3,"<1>");
LCD_P6x8Str(0,4,"<2>");
LCD_P6x8Str(0,5,"<3>");
LCD_P6x8Str(0,6,"<4>");
LCD_P6x8Str(60,3,"<5>");
LCD_P6x8Str(60,4,"<6>");
LCD_P6x8Str(60,5,"<7>");
LCD_P6x8Str(60,6,"<8>");
LCD_Write_6x8Int(30,3,ADC12MCTL0);
LCD_Write_6x8Int(30,4,ADC12MCTL1);
LCD_Write_6x8Int(30,5,ADC12MCTL2);
LCD_Write_6x8Int(30,6,ADC12MCTL3);
LCD_Write_6x8Int(90,3,ADC12MCTL4);
LCD_Write_6x8Int(90,4,ADC12MCTL5);
LCD_Write_6x8Int(90,5,ADC12MCTL6);
LCD_Write_6x8Int(90,6,ADC12MCTL12);
LCD_Write_6x8Int(66,2,x);
LCD_Write_6x8Int(90,2,y);
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
_EINT(); //开总中断
port_init();
LCD_Init();
LCD_CLS();
IO_init();
ADC();
while(1)
{
// caizhi();
xianshi();
// sudu();
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
ADC();
ADC12CTL1 |= ADC12SC;
Timer_A2_1_init();
Timer_A2_2_init();
shu++;
if(shu==1000)
{
nn++;
shu=0;
if(nn==60)
{
nn=0;
bb++;
}
}
}
|
|