Antscran 35 Posted December 14, 2012 Share Posted December 14, 2012 Hi all, I have small opamp LDR circuit that provides a voltage 0-3 volts to the ADC on the MSP, the code I am using is below and all works fine. #include "msp430g2231.h" #define LED0 BIT0 #define LED1 BIT6 unsigned int value=0; // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR (void) { __bic_SR_register_on_exit(CPUOFF); // Return to active mode } } void ConfigureAdc(void) { /* Configure ADC Channel */ ADC10CTL1 = INCH_3 + ADC10DIV_3 ; // Channel 3, ADC10CLK/4 ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //Vcc & Vss as reference ADC10AE0 |= BIT3; //P1.3 ADC option } } void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 1MHz P1DIR |= LED0 + LED1; P1SEL |= BIT3; //ADC Input pin P1.3 P1OUT &= ~(LED0 + LED1); ConfigureAdc(); __enable_interrupt(); // Enable interrupts. while(1) { __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; if (value<511) { P1OUT &= ~(LED0 + LED1); P1OUT |= LED0; } else { P1OUT &= ~(LED0 + LED1); P1OUT |= LED1; } } } What I want to do is combine the 2 programs, and remove the parts of the ADC code that flash the LED's. Then take the unsigned integer value in the ADC code, and then display this on a 16x2 LCD (just the raw data for now will be fine). I have the code for the LCD and successfully connected the LCD up and can display Hello World, but don't fully understand the LCD code. LCD code used is from this very helpful website below: https://sites.google.com/site/cacheattack/msp-projects/msp430-launchpad-with-lcd-module I think I need to change the unsigned integer into a char, or possibly create a new function that mimics the PrintStr function in the LCD code, someone told me I could maybe use the function atoa. Little out of my depth with the C code now so would really appreciate some help, I am using CCS5.1 at the moment. Cheers, Ant Quote Link to post Share on other sites
RobG 1,892 Posted December 14, 2012 Share Posted December 14, 2012 Here are few examples: http://forum.43oh.com/topic/401-launchpad-adc-and-lcd/ http://forum.43oh.com/topic/904-new-take-on-adc-lcd/ If you don't have 74hc164 on hand, there are 4bit LCD examples on 43oh, like this one: http://forum.43oh.com/topic/1767-lcd-16x2-in-4-bit-mode/ Antscran 1 Quote Link to post Share on other sites
Antscran 35 Posted December 17, 2012 Author Share Posted December 17, 2012 Thanks for the information Rob, I will have a look and see if it will help me understand the other code. Quote Link to post Share on other sites
EngIP 31 Posted December 17, 2012 Share Posted December 17, 2012 When I've done this in the past, I've use a character map and a function to translate an integer to display values. Basically there's a variable with the LCD code for that particular number in it's indexed location. For my LCD it's const char charMap[10] = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39}; Then if I have an integer to display (say 341) I do the modulus operator to find the remainder after 10 (1 in this case), send charMap[1] to the display, then divide by 10 and repeat. Hope this helps Antscran 1 Quote Link to post Share on other sites
Antscran 35 Posted December 19, 2012 Author Share Posted December 19, 2012 EngIP cheers, this has been suggested to me by a tutor and they also mentioned using the function ITOA, it carries out the divide by 10, and modulus, then basically converts the Integer into a Char as I understand it. However I am yet to fully understand how to use the ITOA function and implement it, only just started C. I will persevere, at least I know the direction I am crawling now :-) Quote Link to post Share on other sites
RobG 1,892 Posted December 19, 2012 Share Posted December 19, 2012 Keep in mind that modulus and divide use a lot of clock cycles, http://forum.43oh.com/topic/852-converting-binary-to-decimal-bcd/#entry7008 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.