Jump to content
Sign in to follow this  
mvs

Temperature reading every second.

Recommended Posts

Thank you very much!

 

Actually, the following program I wrote displayes temperature every few centiseconds:

#include "msp430x22x4.h"

#include

 

 

static unsigned int FirstADCVal, T1,T0,Tm1; // holds 1st ADC result

float TempC;

 

void main(void)

{

// start

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

// Watchdog timer, p. 349

BCSCTL1 = CALBC1_1MHZ; // Set DCO

// Basic clock system, p. 283

DCOCTL = CALDCO_1MHZ;

// DCO Control Register, p. 283

P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD

// Port Select, p. 335

UCA0CTL1 |= UCSSEL_2; // SMCLK

UCA0BR0 = 104; // 1MHz 9600

// USCI_A0 baud rate control register 0, p. 433

UCA0BR1 = 0; // 1MHz 9600

// USCI_A0 baud rate control register 1, p. 433

UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1

// USCI_A0 modulation control register, p. 433

UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

//stop

 

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

//BCSCTL1 = RSEL0; // Set DCO to 8MHz

//DCOCTL = DCO0;

 

P2DIR |= 0x07; // P2.0,1,2 output direction

P2SEL |= 0x03; // P2.0 = ACLK, P2.1 = SMCLK

 

P1DIR |= 0x01; // P1.0 output

TACCTL0 = CCIE; // TACCR0 interrupt enabled

 

TACCR0 = 16250;

// TACCR0 Interruptor, p. 369

 

TACTL = TASSEL_2 + MC_1+ID_3; // SMCLK, contmode

TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0)

 

ADC10CTL1 = ADC10DIV_3 + INCH_10 + SHS_1 + CONSEQ_2; // TA trig., rpt, A10

// Control Register 1, p. 561

ADC10CTL0 = SREF_1 + ADC10SHT_3 + REF2_5V + ADC10IE + REFON + ADC10ON;

// Control Register 0, p. 559

ADC10CTL0 |= ENC;

 

_EINT();

while(1);

 

// __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt

}

 

// Timer A0 interrupt service routine

#pragma vector=TIMERA0_VECTOR

__interrupt void Timer_A (void)

{

P1OUT ^= 0x01; // Toggle P1.0

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

FirstADCVal = ADC10MEM; // Read out 1st ADC value

TempC=.6877*FirstADCVal-277.7; // Temperature in Celsius

 

T1=floor(TempC/10); // First digit of T

T0=floor(TempC-10*T1); // Second digit of T

Tm1=floor(TempC*10-100*T1-10*T0); // Third digit of T

 

 

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = '0'+T1; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = '0'+T0; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = '.'; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = '0'+Tm1; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = ' '; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = ' '; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = ' '; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = ' '; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = ' '; // TX -> RXed character

 

while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

UCA0TXBUF = ' '; // TX -> RXed character

//USCI_A0 transmit buffer register, p.433

}

 

Could anyone please help me display the temperature every second?

 

To what should I set TACCR0, and how should I slow the clock?

Share this post


Link to post
Share on other sites

I am sorry, but this seems to be a code for some other device.

If you had read my message you would have seen this line above my "code":

Basically the conversion goes like this in "pseudo-C":

It's call pseudo-C because it's not complete C, it's like C. It's used when all the details

of the final code are not known. The 'print' statement was a manner to express

performing the output of a single character, which was what you were already doing.

 

-Rusty-

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...