hello there here it is my code for adc and uart. in code variable a,b,c make digit which is i am transmitting through UART. now i want to set threshold like if value is less than 1.9 then i want to turn on LED .but it doesn't work for me.
i am asking about this part
if(a << 1 && b << 9 ) { P1OUT |= BIT6; serial_charTX('t'); } else { P1OUT &= ~BIT6; }
complete code is below
#include <msp430.h> unsigned char name[] = "RUSHIN\n"; //unsigned char surname[] = "THAKKAR\n"; int a,b,c,v; void serial_init(void); void serial_charTX(char c); void UART0_Write_Text(unsigned char msg[]); char serial_charRX(void); void clock_init(void); void adc_init(void); void main(void) { WDTCTL = WDTHOLD + WDTPW; // P1DIR |= BIT6; clock_init(); // Set clock frequency to 1 MHz serial_init(); //serial_charTX('t'); //UART0_Write_Text(name); //UART0_Write_Text(surname); //serial_charTX('r'); while (1) { //__delay_cycles(500000); // __delay_cycles(500000); // __delay_cycles(500000); //int a,b,c,v =0; // ADC10MEM= 0; // Initialize UART module adc_init(); v = ADC10MEM; v=v/3; v=v+6; a=v/100; b=v/10; b=b%10; c=v%10; if(a << 1 && b << 9 ) { P1OUT |= BIT6; serial_charTX('t'); } else { P1OUT &= ~BIT6; } serial_charTX(a+0x30); serial_charTX('.'); serial_charTX(b+0x30); serial_charTX(c+0x30); serial_charTX(0x0D); serial_charTX(0x0A); //TimerA_UART_print("\n"); } } void adc_init(void) { ADC10CTL1 |= ADC10SSEL_3 + ADC10DIV_7 + CONSEQ_2; //continuous sample mode, MUST BE SET FIRST! ADC10CTL0 |= ADC10ON + ADC10SHT_3 + MSC + REFON + REF2_5V; //sample and hold time, adc on, cont. sample ADC10AE0 |= 0x01; // select channel A0 ADC10CTL0 |= ADC10SC + ENC; } void serial_init(void) //Initialize TX { P1SEL = BIT1 + BIT2;// ****** mask based on pin (same process we used in Lab 6) ****** // P1SEL2 =BIT1 + BIT2; // ****** mask based on pin (same process we used in Lab 6) ****** // UCA0CTL1 |= UCSWRST; // Disable UART module for configuration UCA0CTL1 |=UCSSEL_2; // ****** SMCLK source, keep in reset state p. 440 User's Guide ****** // UCA0BR0 =104; // ****** 9600 Baud rate - Assumes 1 MHz clock pg 441 & 435 User's Guide ****** // UCA0MCTL =UCBRS0; // ****** 2nd Stage modulation = 1, Oversampling off p. 442 & 435 User's Guide ****** // IE2 = 0x00; // Interrupts disabled UCA0CTL1 &= ~UCSWRST; // Enable UART module } void serial_charTX(char c) { while( !(IFG2 & UCA0TXIFG) ); // Wait until the transmit buffer is empty UCA0TXBUF = c; // Send the character through the Xmit buffer } void UART0_Write_Text(unsigned char msg[]) { while(*msg) { serial_charTX(*msg); msg++; } } char serial_charRX(void) { while( !(IFG2 & UCA0RXIFG) ); // Wait until a character has been received return UCA0RXBUF; // Return received character } void clock_init(void) { DCOCTL = 0x00; BCSCTL1 = CALBC1_1MHZ; // Calibrate to 1 MHz DCOCTL = CALDCO_1MHZ; }