#include void DisplayValue(int Value); //unsigned int TempValue = 1; // number to display, range = 0 - 1999 = max display // NOTE: DO NOT use leading zeros unsigned int h; unsigned int i; unsigned int dig_pntr; static unsigned int Voltage; //static unsigned long int TempValue; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer FLL_CTL0 |= XCAP14PF; // Configure load caps IE2 |= BTIE; // Enable BasicTimer interrupt BTCTL = BT_ADLY_125; //Interrupt 125ms from header file //BTCTL = BT_ADLY_1000; //Interrupt 1000ms from header file // initialize LCD driver (static mode) // // Setup LCD LCDCTL = 0xE5; P5DIR |= 0x02; // Set P5.1 to output direction P1DIR |= 0x01; // Set P1.0 to output direction // Setup port functions P2SEL = 0xFF; P3SEL = 0xFF; P4SEL = 0xFF; P5SEL = 0xFF; //A/D conversion P6SEL = 0x00; P6SEL |= 0x80; // Enable A/D channel A7 ADC12CTL0 = ADC12ON+SHT0_2+REFON+REF2_5V ; // Turn on and set up ADC12 ADC12CTL1 = SHP; // Use sampling timer ADC12MCTL0 = SREF_1 +INCH_7; // Vr+=Vref+ADCChannel7 for ( i=0; i<0x3600; i++) // Delay for reference start-up { } _EINT(); // Enable interrupts ADC12CTL0 |= ENC; // Enable conversions //main loop while(1) { _BIS_SR(LPM0_bits); // Enter LPM3 low power mode 0 } } // Basic Timer interrupt service routine interrupt[BASICTIMER_VECTOR] void basic_timer(void) { _BIC_SR_IRQ(LPM0_bits); // Clear LPM0 bits from 0(SR) P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR P5OUT ^= 0x02; // Toggle P5.1 ADC12CTL0 |= ADC12SC; // Start conversion while ((ADC12IFG & BIT0)==0); _NOP(); // SET BREAKPOINT HERE DisplayValue(ADC12MEM0); } void DisplayValue(int Value) { char *LCD = LCDMEM; // array declaration // char digit[40] = { 0x11, 0x11, // "0" LCD segments a+b & c+d = lower two bytes 0x11, 0x00, // "0" LCD segments e+f & g+h = upper two bytes 0x10, 0x01, // "1" 0x00, 0x00, // "1" 0x11, 0x10, // "2" 0x01, 0x01, // "2" 0x11, 0x11, // "3" 0x00, 0x01, // "3" 0x10, 0x01, // "4" 0x10, 0x01, // "4" 0x01, 0x11, // "5" 0x10, 0x01, // "5" 0x01, 0x11, // "6" 0x11, 0x01, // "6" 0x11, 0x01, // "7" 0x00, 0x00, // "7" 0x11, 0x11, // "8" 0x11, 0x01, // "8" 0x11, 0x11, // "9" 0x10, 0x01, // "9" }; // clear LCD memory to clear display // for (i=0; i<20; i++) { LCD[i] = 0; } //Calculate Voltage //Value =(2500*Value)/4095; Voltage = (int)(((long)Value*250)/4095); // display higher 4-th digit (nothing or 1) // if(Voltage <= 1999) { if (Voltage >= 1000) { LCDM15 = 0x001; // set bit = leading 1 } // display lower 3 digits // for (h=0; h<=2; h++) // loops to move 3 digits to LCD { dig_pntr = 4*(Voltage%10); // set pointer to start of digit in table for (i=0; i<4; i++) // loops to load 4 bytes of digit { LCD[i] = digit[dig_pntr++]; // byte of digit to byte of LCD memory } // and increment to next byte of digit Voltage = Voltage/10; // shifts value right to display next character if(h==0) { LCD = LCD + 4; // increment by 4 for next character location } if(h==1) { LCD = LCD + 6; // increment by 10 for next character location } } LCDM14 |= 0x010; // set bit = decimal point } else { //need added ERROR Message } }