梦上飞天舞吧 关注:106贴子:16,766
  • 3回复贴,共1
#include <msp430f5529.h>
#include"HAL_Dogs102x6.h"
#include<stdio.h>
long temp;
volatile long IntDegF;
volatile long IntDegC;
char buff1[];
char buff2[];
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // 关闭看门狗定时器
REFCTL0 &= ~REFMSTR; // 复位REFMSTR控制位以控制ADC12参考电压控制寄存器
ADC12CTL0 = ADC12SHT0_8 + ADC12REFON + ADC12ON;
// 打开ADC12,设置采样间隔,打开内部参考电压产生器,参考电压设置为1.5V
ADC12CTL1 = ADC12SHP; // 采样保持触发信号选择采样定时器
ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_10; // A10通道作为输入,采样温度
ADC12IE = 0x001; // 使能ADC12IFG0中断
__delay_cycles(75); // 延时75us以使参考电压稳定
ADC12CTL0 |= ADC12ENC; // 使能转换
Dogs102x6_init();
Dogs102x6_backlightInit();
Dogs102x6_setBacklight(50);
//Dogs102x6_clearAllPixelsOn();
Dogs102x6_clearScreen();
while(1)
{
ADC12CTL0 |= ADC12SC; // 开始采样转换
__bis_SR_register(LPM4_bits + GIE); // 进入LPM4,并使能全局中断
IntDegC = ((temp - 1855) * 667) / 4096; // 采样结果转化为摄氏温度
IntDegF = ((temp - 1748) * 1200) / 4096;// 采样结果转化为华氏温度
sprintf(buff1,"temp=%d",IntDegC);
Dogs102x6_stringDraw(3,10,buff1,0);
__delay_cycles(1000000);
Dogs102x6_clearScreen();
__no_operation(); // 可在此处设置端点查看变量
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
switch(__even_in_range(ADC12IV,34))
{
case 6: // Vector 6: ADC12IFG0
temp = ADC12MEM0; // 读取采样存储结果,自动清除中断标志位
__bic_SR_register_on_exit(LPM4_bits); // 退出低功耗模式
break;
default: break;
}
}


IP属地:天津1楼2014-04-19 14:56回复
    #include <msp430f5529.h>
    #include"HAL_Dogs102x6.h"
    long TEMP1=0,TEMP2=0;
    long y=60;
    int i;
    #define Num_of_Results 8
    volatile unsigned int results[Num_of_Results];
    // Needs to be global in this
    // example. Otherwise, the
    // compiler removes it because it
    // is not used for anything.
    void main(void)
    {
    WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
    Dogs102x6_init();
    Dogs102x6_backlightInit();
    Dogs102x6_setBacklight(50);
    Dogs102x6_setContrast(10);
    Dogs102x6_clearScreen();
    P8DIR|=BIT0;
    P8OUT|=BIT0;
    P6DIR &= ~BIT5;
    P6SEL |= BIT5; // Enable A/D channel A5
    ADC12CTL0 = ADC12ON+ADC12SHT00+ADC12MSC; // Turn on ADC12, set sampling time // set multiple sample conversion
    ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2; // Use sampling timer, set mode
    ADC12MCTL0 = ADC12INCH_5;
    ADC12IE = 0x01; // Enable ADC12IFG.0
    ADC12CTL0 |= ADC12ENC; // Enable conversions
    ADC12CTL0 |= ADC12SC; // Start conversion
    Dogs102x6_clearScreen();
    while (1)
    {
    ADC12CTL0 |= ADC12SC; // Start sampling/conversion
    Dogs102x6_circleDraw(y,30,8,0);//画圆
    __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
    __no_operation(); // For debugger
    }
    }
    #pragma vector=ADC12_VECTOR
    __interrupt void ADC12ISR (void)
    {
    switch(__even_in_range(ADC12IV,34))
    {
    case 0: break; // Vector 0: No interrupt
    case 2: break; // Vector 2: ADC overflow
    case 4: break; // Vector 4: ADC timing overflow
    case 6: // Vector 6: ADC12IFG0
    TEMP2=TEMP1;
    TEMP1 = ADC12MEM0;
    // P1.0 = 0
    if(TEMP1>(TEMP2+8))
    { y=y-10;
    Dogs102x6_clearScreen();
    Dogs102x6_circleDraw(y,30,8,0);}
    else if(TEMP1<(TEMP2-8))
    {
    y=y+10;
    Dogs102x6_clearScreen();
    Dogs102x6_circleDraw(y,30,8,0);
    }
    if(y<20)y=20;
    if(y>=90)y=90;
    __bic_SR_register_on_exit(LPM0_bits);
    case 8: break; // Vector 8: ADC12IFG1
    case 10: break; // Vector 10: ADC12IFG2
    case 12: break; // Vector 12: ADC12IFG3
    case 14: break; // Vector 14: ADC12IFG4
    case 16: break; // Vector 16: ADC12IFG5
    case 18: break; // Vector 18: ADC12IFG6
    case 20: break; // Vector 20: ADC12IFG7
    case 22: break; // Vector 22: ADC12IFG8
    case 24: break; // Vector 24: ADC12IFG9
    case 26: break; // Vector 26: ADC12IFG10
    case 28: break; // Vector 28: ADC12IFG11
    case 30: break; // Vector 30: ADC12IFG12
    case 32: break; // Vector 32: ADC12IFG13
    case 34: break; // Vector 34: ADC12IFG14
    default: break;
    }
    }


    IP属地:天津2楼2014-04-19 14:57
    回复
      大神switch(__even_in_range(ADC12IV,34))什么意思???


      3楼2014-07-23 13:12
      回复
        看门狗


        来自Android客户端4楼2014-07-30 20:52
        回复