Jump to content
43oh

flying4fun

Members
  • Content Count

    2
  • Joined

  • Last visited

Reputation Activity

  1. Like
    flying4fun reacted to kff2 in Time & Temperature on Nokia 7110   
    Some notes on compiling this with msp430-gcc.
     
    1) To handle C++ templates in nokia7110tl.h, you need to a version of msp430-gcc with C++ support. If building from sources, configure with --enable_languages=c,c++. The packaged msp430-gcc in recent versions of Ubuntu should already be C++ enabled.
     
    To compile C++ code, use msp430-g++ instead of msp430-gcc. You will likely get the error
     
    ld: cannot find -lstdc++
     
    This is because msp430-g++ links against the C++ standard library by default, which is not included with msp430-gcc. To work around, run msp430-g++ as follows:
     
    msp430-g++ -mmcu=msp430g2452 -o time.elf main.cpp -nodefaultlibs -fno-rtti -fno-exceptions -lc -lgcc
     
    This tells msp430-g++ not to use default libraries. You then need to explicitly list the default libraries that you need (-lc and -lgcc). -fno-rtti -fno-exceptions eliminates some C++ bloat and reduces code size.
     
    2) time.h is not included with msp430-gcc. I used this version which I found somewhere on the internet:
     

    typedef long time_t; /* for representing times in seconds */ struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; }; const unsigned char moninit[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static unsigned dylen(unsigned yr) { if(yr%4 || (yr % 100) == 0 && ((yr+300)%400) != 0) return(365); return(366); } struct tm * gmtime(time_t * tp) { time_t t; static struct tm tim; t = *tp; tim.tm_sec = t % 60L; t /= 60L; tim.tm_min = t % 60L; t /= 60L; tim.tm_hour = t % 24L; tim.tm_mday = t / 24L; tim.tm_wday = (tim.tm_mday + 4) % 7; tim.tm_year = 70; while(tim.tm_mday >= dylen(tim.tm_year)) { tim.tm_mday -= dylen(tim.tm_year); tim.tm_year++; } tim.tm_yday = tim.tm_mday; if(tim.tm_mday >= 59 && dylen(tim.tm_year) == 366) tim.tm_mday--; tim.tm_mon = 0; while(tim.tm_mday >= moninit[tim.tm_mon]) { tim.tm_mday -= moninit[tim.tm_mon]; tim.tm_mon++; } tim.tm_mday++; return &tim; } struct tm * localtime(time_t * tp) { time_t t; t = *tp - 7 * 3600L; return gmtime(&t); }
     
    Notice that there is no mktime function here. Instead, in main.cpp, I set tt to the current unix timestamp (obtained with "date +%s" in Linux). Also, the localtime function here hardcodes my timezone. Change accordingly.
     
    3) This original code causes the LCD to go berserk when compiled under msp430-gcc:
     

    for(c = 32; c < 128; ++c) { lcd.print(c); if(++x >= 16) x = 0, lcd.pos(x, ++y); }
     
    That's because c is a signed byte value, and the compiler treats 128 as -1, causing an infinite loop. What you want instead is
     

    for(c = 32; c < 128U; ++c) { lcd.print(c); if(++x >= 16) x = 0, lcd.pos(x, ++y); }
     
    Hope this will be useful to somebody.
  2. Like
    flying4fun reacted to PentiumPC in i2c HD44780 LCD Booster Shield   
    Hi, 
     
    I have made some changes since I posted this but it should work as it is.
     
    I will attach the new code here so you try it.
     
    Regards,
    Terence
     
    LCD.c
    LCD.h
    main.c
×
×
  • Create New...