Hello I am using
Code composer 5.1
Microcontroller: MSP430G2533
LM35
Using Putty for m hyperterminal
Question: I can't seem to get the data of two LM35's to display on my hyperterminal? The follow code is the best I've been able to think of.
The code is based on the following website.
http://karve.in/?p=597#comment-507
code:
Code composer 5.1
Microcontroller: MSP430G2533
LM35
Using Putty for m hyperterminal
Question: I can't seem to get the data of two LM35's to display on my hyperterminal? The follow code is the best I've been able to think of.
The code is based on the following website.
http://karve.in/?p=597#comment-507
code:
Rich (BB code):
#include <msp430g2553.h>
#include <stdbool.h>
////////////////Defines////////////////
#define LED1 BIT6
#define LED0 BIT0
#define Error BIT0
#define GND BIT4
#define DAT BIT5
#define DAT2 BIT7////////////////////////////////////////////////////new
#define VCC BIT0 //port P2.0
char buffer[4];
float temp;
float temp2;
int n_temp,r_temp;
int x=0,y=0;
////////////////Function Protos////////////////
void TX(char *tx_message);
static char *i2a(unsigned i, char *a, unsigned r);
char *itoa(int i, char *a, int r);
void ADC_init(void);
static char *i2a(unsigned i, char *a, unsigned r)
{
if (i/r > 0) a = i2a(i/r,a,r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
}
char *itoa(int i, char *a, int r)
{
if ((r < 2) || (r > 36)) r = 10;
if (i < 0)
{
*a = '-';
*i2a(-(unsigned)i,a+1,r) = 0;
}
else *i2a(i,a,r) = 0;
return a;
}
void TX(char *tx_message)
{
unsigned int i=0; //Define end of string loop int
char *message; // message variable
unsigned int message_num; // define ascii int version variable
message = tx_message; // move tx_message into message
while(1)
{
if(message==0) // If end of input string is reached, break loop.
{break;}
message_num = (int)message; //Cast string char into a int variable
UCA0TXBUF = message_num; // write INT to TX buffer
i++; // increase string index
__delay_cycles(10000); //transmission delay
if(i>50) //prevent infinite transmit
{
P1OUT |= Error;
break;
}
} // End TX Main While Loop
} // End TX Function
///////////////////////////////////////////////////////////////////////////////////////////////////
void ADC_init()
{
/* Configure ADC Channel */
ADC10CTL1 = INCH_5 + ADC10DIV_3 ; // Channel 5, ADC10CLK/4
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //Vcc & Vss as reference
ADC10AE0 |= BIT5; //P1.5 ADC option
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void ADC2_init()
{
/* Configure ADC Channel */
ADC10CTL1 = INCH_7 + ADC10DIV_3 ; // Channel 7, ADC10CLK/4
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //Vcc & Vss as reference
ADC10AE0 |= BIT7; //P1.7 ADC option
}
///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////MAIN PROGRAM LOOP//////////////////////////////////////////////////
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
////////////////USCI setup////////////////
P1SEL = BIT1 + BIT2; // Set P1.1 to RXD and P1.2 to TXD
P1SEL2 = BIT1 + BIT2; //
UCA0CTL1 |= UCSSEL_2; // Have USCI use SMCLK AKA 1MHz main CLK
UCA0BR0 = 104; // Baud: 9600, N= CLK/Baud, N= 10^6 / 9600
UCA0BR1 = 0; // Set upper half of baud select to 0
UCA0MCTL = UCBRS_1; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // Start USCI
////////////////General GPIO Defines////////////////
P1DIR |= (LED1+GND+LED0); //Define GPIOs as outputs else GPIOs are inputs
P2DIR |=VCC;
P1OUT =0; //All Outputs off except for Green_LED
P2OUT|=VCC;
P1OUT&=~GND;
while(1)
{
/* do{
///////////////////SETUP ADC10 TO READ FROM CH A4 (P1.5)/////////////////////////////////////////////
ADC_init();
__enable_interrupt(); // Enable interrupts.
int value=0;
///////////////////////////////Main Loop/////////////////////////////////////////////////////////////
__delay_cycles(1000); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
value = ADC10MEM;
temp=value*0.317;
r_temp=((temp*10)-10) * ((temp*10)/10);
itoa(temp, buffer, 10);
TX("External Temp:");
TX(buffer);
TX(".");
itoa(r_temp, buffer, 10);
TX(buffer);
TX(" Celsius\r\n");
P1OUT ^= LED0;
_delay_cycles(500000);
y=0;
x++;
}while(x==1000);*/
do{
///////////////////SETUP ADC10 TO READ FROM CH A4 (P1.7)/////////////////////////////////////////////
ADC2_init();
__enable_interrupt(); // Enable interrupts.
int value2=0;
///////////////////////////////Main Loop/////////////////////////////////////////////////////////////
__delay_cycles(1000); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
value2 = ADC10MEM;
temp2=value2*0.317;
r_temp=((temp2*10)-10) * ((temp2*10)/10);
itoa(temp2, buffer, 10);
TX("Internal Temp:");
TX(buffer);
TX(".");
itoa(r_temp, buffer, 10);
TX(buffer);
TX(" Celsius\r\n");
P1OUT ^= LED0;
_delay_cycles(500000);
x=0;
y++;
}while(y==1000);
} //End while
} // End Main Program
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Return to active mode
P1OUT ^= LED1;
}
Last edited by a moderator: