Jump to content
Sign in to follow this  

Strange optimization (GCC?)

Recommended Posts

The display[] array loses somehow the characters that are not updated. Instead of " 32.4*C" I get " 32".

Uncommenting the lines at the bottom 'fixes' part of the stuff, but still something is displayed wrong (the comma symbol gets extra junk at the bottom).

Setting the backlight variable to true at initialization time changes the display to " 32x4" where 'x' is some random junk character.


Either I'm doing something wrong or the compiler has a bug. I suppose since most of this code is in the Energia repository (but only for 430) it should work.




// Core library

#if defined(__MSP430G2553__) // LaunchPad MSP430G2553 specific
#include "Energia.h"
#include "Energia.h"
// Include application, user and local libraries
#include "LCD_5110.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
//#include "Thermometer_430.h"
// Variables
// Option 1: parameters with suggested pins
//LCD_5110 myScreen(P2_4, P2_3, P2_2, P2_1, P2_0, P2_5, PUSH2);
//#define _pinChipSelect  P2_4
//#define _pinSerialClock P2_3
//#define _pinSerialData  P2_2
//#define _pinDataCommand P2_1
//#define _pinReset       P2_0
//#define _pinBacklight   P2_5
//#define _pinPushButton  PUSH2
LCD_5110 myScreen(PB_1, PB_4, PE_5, PE_4, PB_0, PA_6, PUSH2); 
boolean backlight = false;
void initThermometer(){
  SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); // 250
  ADCSequenceDisable(ADC0_BASE, 1);
  ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceEnable(ADC0_BASE, 1);
// Add setup code
void setup() {   
  pinMode(PA_5, OUTPUT);
  digitalWrite(PA_5, HIGH);//vcc
  pinMode(PE_2, OUTPUT);
  digitalWrite(PE_2, HIGH);//vcc
  pinMode(PA_7, OUTPUT);
  digitalWrite(PA_7, LOW);//vss
  pinMode(PF_1, OUTPUT);
  digitalWrite(PF_1, LOW);//vss
  myScreen.text(0, 0, "Hello");
  myScreen.text(1, 2, "MSP430");
  myScreen.text(0, 0, "Thermometer");
  myScreen.text(0, 5, "Light off");
// Display mask
char display[8] = {
  ' ', ' ', ' ', '.', ' ', 0x7f, 'C', 0x00};
int32_t getTempAdcValue(){
  unsigned long ulADC0Value[4];
  ADCIntClear(ADC0_BASE, 1);
  ADCProcessorTrigger(ADC0_BASE, 1);
  while(!ADCIntStatus(ADC0_BASE, 1, false))
  ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value);
  unsigned long ulTempAvg = (ulADC0Value[0] + ulADC0Value[1] + ulADC0Value[2] + ulADC0Value[3] + 2)/4;
  int32_t ulTempValueC = 1475 - ((2475 * ulTempAvg)) / 4096;
  return ulTempValueC;
// Add loop code
void loop() {
  if (myScreen.getButton()) {
    backlight = ~backlight;
    myScreen.text(0, 5, backlight ? "Light on " : "Light off");
  // Temperature display
  int32_t number = getTempAdcValue();//myThermometer.temperatureX10();
  boolean flag = (number<0);
  if (flag) number = -number;
  display[4] = 0x30 + (number%10);
  number /= 10;
  display[2] = 0x30 + (number%10);
  number /= 10;
  if (number>0) {
    display[1] = 0x30 + (number%10);
  else if (flag) { 
    display[1] = '-';
    flag = false;
  else {
    display[1] = ' ';   
  number /= 10;
  if (number>0) display[0] = 0x30 + (number%10);
  else if (flag) display[0] = '-';
  else display[0] = ' ';
//  display[3] = '.';
//  display[5] = 0x7f;
//  display[6] = 'C';
  myScreen.text(0, 2, display);




Share this post

Link to post
Share on other sites

Outputting the display[] on serial shows this:  " 32x7  . xC" where x is some strange character.

Moving the display[] declaration inside the loop solves the problem showing the correct string " 32.5?C".

Share this post

Link to post
Share on other sites

Hard to tell without seeing your Display routine, but the degree symbol must be displayed as a single character. Otherwise it wont work,


By this i mean ive used sprintf() to format output to an Nokia 5110, and if the %s format type is used, the character will not be displayed properly. When instead -> using the single char format type, the degree symbol then is displayed correctly.

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.

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...