Tool/software: TI C/C++ Compiler
Hello,
I 'm using MSP430G2553 to display temperature using internal senzor.
The problem is he works fine, but sometimes the values displayed on the LCD have very large differences. For example it shows 28.5, 29.1, 29.5.... and after some minutes : 21 , 29, 18, 30 ...
The range between measurements is 2 seconds. I am using IAR IDE and in debug mode i saw in watch tool the value that is transmitted to the LCD display function looks very well, without big differences. So the problem has to be somewhere on the display function.
There is my code and thanks:
#include <msp430g2553.h> #define lcd_port P1OUT #define lcd_port_dir P1DIR #define LCD_EN BIT4 #define LCD_RS BIT5 unsigned char b[4]; int i,j = 0; int g; unsigned int aa, bb,cc,dd,ee,ff,gg; float ADCDATA; float tempInDeg; long tempInDeg1; void lcd_reset() { lcd_port_dir = 0xff; // output mode lcd_port = 0xff; __delay_cycles(20000); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; __delay_cycles(10000); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; __delay_cycles(1000); lcd_port = 0x03+LCD_EN; lcd_port = 0x03; __delay_cycles(1000); lcd_port = 0x02+LCD_EN; lcd_port = 0x02; __delay_cycles(1000); } void lcd_cmd (char cmd) { // Send upper nibble lcd_port = ((cmd >> 4) & 0x0F)|LCD_EN; lcd_port = ((cmd >> 4) & 0x0F); // Send lower nibble lcd_port = (cmd & 0x0F)|LCD_EN; lcd_port = (cmd & 0x0F); __delay_cycles(4000); } void lcd_init () { lcd_reset(); // Call LCD reset lcd_cmd(0x28); // 4-bit mode - 2 line - 5x7 font. lcd_cmd(0x0C); // Display no cursor - no blink. lcd_cmd(0x06); // Automatic Increment - No Display shift. lcd_cmd(0x80); // Address DDRAM with 0 offset 80h. lcd_cmd(0x01); // Clear screen } void lcd_data (unsigned char dat) { // Send upper nibble lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS); lcd_port = (((dat >> 4) & 0x0F)|LCD_RS); // Send lower nibble lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS); lcd_port = ((dat & 0x0F)|LCD_RS); //__delay_cycles(4000); // a small delay may result in missing char display __delay_cycles(2000); } void display_line(char *line) { while (*line) lcd_data(*line++); } int main() { // Stop Watch Dog Timer WDTCTL = WDTPW + WDTHOLD; ADC10CTL0 = ADC10SHT_3 + SREF_1 + REFON + ADC10ON; ADC10CTL1 = INCH_10 + ADC10DIV_3; __delay_cycles(30); lcd_init(); // Initialize LCD while (1){ /////temp ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start while (ADC10CTL1 & ADC10BUSY); // check for ADC conversion is completed ADCDATA = ADC10MEM; // Read ADC value tempInDeg1= 413*(long)ADCDATA-277746;/// bb =(tempInDeg1/10000)%10; // f cc =(tempInDeg1/1000)%10; // dd='.'; // ee =(tempInDeg1/100)%10; // ff=0xF8; //Symbol for dg gg='C'; lcd_cmd(0x80); // select 1st line (0x80 + addr) - here addr = 0x00 display_line("T:"); //Transfer to LCD , example: 28.5 lcd_data(bb + 48); lcd_data(cc + 48); display_line("."); lcd_data(ee + 48); lcd_cmd(0xc0); // select 2nd line (0x80 + addr) - here addr = 0x40 __delay_cycles(2000000); } }