#include "msp430g2553.h" unsigned char seg_7[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; unsigned char seg_8[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; float i=0; int ge=0; int f=0; int m=0; int h=0; int temp=0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled ADC10CTL1 = INCH_1; // input A1 ADC10AE0 |= 0x02; // PA.1 ADC option select P1DIR=0xf0; // Set P1.0 to output direction P2DIR|=0xff; P2SEL&=0x00;
for (;;) { ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start // __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit i=(float)ADC10MEM; i=i/1023; i=i*3600; temp=(int)i; ge=temp/1000; temp=temp%1000; f=temp/100; temp=temp%100; m=temp/10; temp=temp%10; h=temp; P1OUT=0x7f; P2OUT=seg_7[ge]; _delay_cycles(1000); P1OUT=0xbf; P2OUT=seg_8[f]; _delay_cycles(1000); P1OUT=0xdf; P2OUT=seg_8[m]; _delay_cycles(1000); P1OUT=0xef; P2OUT=seg_8[h]; _delay_cycles(1000); } }
// ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { _delay_cycles(100000); // __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR) }
|