Author Topic: SPECIAL ASCII CHARACTERS ON LCD  (Read 4786 times)

0 Members and 1 Guest are viewing this topic.

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
SPECIAL ASCII CHARACTERS ON LCD
« on: November 11, 2016, 12:51:19 am »
 Good morning all.   
I am doing a bit more work on my micro controller project and need a little help
Below is a section of the code to display a message to LCD.

At the moment it displays
HS1: 35.03Deg C

I want to be able to display the Degree symbol "°"
HS1: 35.03°C

Can Anyone help

I am using MPLAB X IDE v2.10
The chip is 16F877A



     else if (FAULT_6==0)                    //FAULT, RC6 AT 0V
        {
            Lcd_Init();               // initialize LCD
            Lcd_Clear();              // clear LCD
            init();
            Lcd_Set_Cursor(1,1);
            Lcd_Write_String(MSG_M9A);
            Lcd_Set_Cursor(2,1);   // select line 2
            Lcd_Write_String(MSG_M9B);
            DelayMs(1000);

            Last_Value=-1; // Force update on first pass
            Lcd_Clear();
            while(1)
                {
                    // READ ADC(2) AND DISPLAY ON LINE ONE.
                    Adres=ReadADC(2);
                {
                    Degrees=( // scale to Degrees as fixed point, 2DP, with rounding.
                    Adres*(unsigned long)(MAXTEMPERATURE*100) + ADCMAX/2)/ADCMAX;
                    DeciDegrees = Degrees%100;  // extract decimals
                    Degrees = Degrees/20;      //extract integer volts
               //   Lcd_Clear();
                    Lcd_Set_Cursor(1,1);    // select line 1
                    sprintf(OutString,"HS1: %u.%2.2uDeg C  ",Degrees,DeciDegrees);
                    Lcd_Write_String(OutString);
                    Last_Value = Adres;
                }
                // READ ADC(3) AND DISPLAY ON LINE TWO.
                Adres=ReadADC(3);
                //   if(adres!=last_value)
                {
                    Degrees=( // scale to Degrees as fixed point, 2DP, with rounding.
                    Adres*(unsigned long)(MAXTEMPERATURE*100) + ADCMAX/2)/ADCMAX;
                    DeciDegrees = Degrees%100;  // extract decimals
                    Degrees = Degrees/20;      //extract integer volts
                    Lcd_Set_Cursor(2,1);    // select line 2
                    sprintf(OutString,"HS2: %u.%2.2uDeg C  ",Degrees,DeciDegrees);
                    Lcd_Write_String(OutString);
                }
                    //    Last_Value = Adres;
                    DelayMs(1000);
                }
        }

Thank you
BILL.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11882
  • Country: us
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #1 on: November 11, 2016, 12:56:03 am »
It probably depends what character encoding is used by the LCD display. The LCD is the one piece of technical data you have not included in your post.

Just for the sake of elimination, have you tried doing this to see what happens?

Code: [Select]
sprintf(OutString,"HS1: %u.%2.2u°C  ",Degrees,DeciDegrees);
 

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #2 on: November 11, 2016, 01:14:40 am »
IanB.
that was quick.

Yes I did try inserting the ° character but it was rejected
main.c:247: warning: (228) illegal character (0xB0)
I have seen some instructions on using the special ascii characters but when I search for them
I get too many variations of what i have googled.
SPECIAL CHARACTER,  UPPER ASCII CHARACTOR,  MPLAB, LCD, °, PIC16F877A,
Each have hundreds of possibilities but when using more than one field to search for, there is an INFORMATION OVERLOAD

my wife says that, Perhaps I need to find another hobby.
I suggested we go Sky Diving together.
She said NO WAY.

Thanks
BILL.
 

Offline matseng

  • Frequent Contributor
  • **
  • Posts: 563
  • Country: se
    • My Github
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #3 on: November 11, 2016, 02:01:37 am »
Have you looked at the spec of the display or display controller chip that you are using to see what characters that are supported in it?

For instance the common HD44780 have Japanese characters and some special symbols in the 128..255 number range. Among those symbols a small upper circle is available there. The hex code for it is DF so you should be able to do something like this "Temp %d \xDF C" to embed the code in a string.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #4 on: November 11, 2016, 02:06:59 am »
Assuming its a HD44780 compatible display, with Hitachi's standard A00 character ROM (slightly tweaked JIS X 0201), codes above 0x7F are a mix of symbols and katakana. Fortunately there is a ° symbol, but it isn't at the usual ASCII codepoint.  The C escape for it would be '\xDF'.  Try:
Code: [Select]
sprintf(OutString,"HS1: %u.%2.2u\xDFC  ",Degrees,DeciDegrees);
If your display isn't HD44780 compatible or has a custom character set, all bets are off . . .
« Last Edit: November 11, 2016, 02:51:53 am by Ian.M »
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5022
  • Country: ro
  • .
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #5 on: November 11, 2016, 02:47:03 am »
A lot of LCD displays also allow you to "upload" your own characters, a few of the characters can be overwritten with your own after initialization by writing a series of bits to a memory location on the lcd display. The datasheet should have all the information

Here's a typical LCD display with chip that's clone of those HD447800: http://uk.farnell.com/midas/mc42004a6w-bnmlw/lcd-4x20-neg-stn-white-led-b-l/dp/2063162
Just click on "Technical Data Sheet" and download it, can't attach it here because it's 3 MB+.

Have a look in it, and lok at the instructions and you'll see there.. Set CGRAM address, Set DDRAM address, Write data to RAM ..
The datasheet also has a map of the character set contained in it, but the stored characters can vary between lcd displays.
 

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #6 on: November 11, 2016, 03:42:19 am »
Thanks Ian
that worked with a very minor change
I had to move the C to have a space between  the F and C  (not being rude!)
sprintf(OutString,"HS1: %u.%2.2u\xDFC  ",Degrees,DeciDegrees);
sprintf(OutString,"HS1: %u.%2.2u\xDF C  ",Degrees,DeciDegrees);
attached is a picture

Thanks
BILL.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11882
  • Country: us
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #7 on: November 11, 2016, 04:14:18 am »
I had to move the C to have a space between  the F and C  (not being rude!)
sprintf(OutString,"HS1: %u.%2.2u\xDF C  ",Degrees,DeciDegrees);

If you want to avoid the extra space between the ° and the C, try it like this:

Code: [Select]
sprintf(OutString,"HS1: %u.%2.2u\xDF" "C  ",Degrees,DeciDegrees);
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #8 on: November 11, 2016, 04:19:01 am »
Ah yes. That's an ANSI C standard issue. It takes the longest possible sequence of characters that are valid digits as a Hex escape sequence even when the resulting wide character isn't supported by the compiler  You got '\xFC' after the high byte of 0x0D was dropped.  You can either break the string and rely on concatenation to reassemble it:
Code: [Select]
sprintf(OutString,"HS1: %u.%2.2u\xDF" "C  ",Degrees,DeciDegrees);or the other approach would be to use the octal equivalent '\337'  as octal escape sequences are bounded at three digits:
Code: [Select]
sprintf(OutString,"HS1: %u.%2.2u\337" "C  ",Degrees,DeciDegrees);Personally I'd use the former for clarity:
Code: [Select]
#define sDEG "0xDF" // HD44780 degree symbol

//...

sprintf(OutString,"HS1: %u.%2.2u" sDEG "C  ",Degrees,DeciDegrees);
 

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #9 on: November 11, 2016, 04:34:14 am »
Ian,
I found to avoid the gap between ° & C
add a back slash
 sprintf(OutString,"HS1: %u.%2.2u\xDF\C   ",Degrees,DeciDegrees);

BILL.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #10 on: November 11, 2016, 05:24:43 am »
*NOT* recommended.  Some compilers implement extra non-standard escape sequences (which could be introduced with any new version) so putting extra backslashes in strings other than prefixing a valid ANSI C escape sequence is littering your code with timebombs.  Also a standards compliant compiler will generate a diagnostic for invalid escape sequences so you are likely to get warnings littering the compiler output.   Why not use the Octal form '\337' instead, as it doesn't need to be separated from the following 'C' ?
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #11 on: November 11, 2016, 06:58:43 am »
How about:

Code: [Select]
#define DEGREEDOT '\xdf'
#define DEGREESYM 'C'
sprintf(OutString,"HS1: %u.%2.2u%c%c  ",Degrees,DeciDegrees, DEGREEDOT, DEGREESYM);
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2217
  • Country: 00
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #12 on: November 11, 2016, 07:31:56 am »
I want to be able to display the Degree symbol "°"
HS1: 35.03°C

That is not an ascii character. And "special" ascii characters do not exist. Not even "extended" ascii characters...
 

Offline neko efecktzTopic starter

  • Regular Contributor
  • *
  • Posts: 153
  • Country: au
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #13 on: November 11, 2016, 02:06:39 pm »
Thanks everyone for your input.
I've gone with using the hex value as suggested by IanM
sprintf(OutString,"HSink +1: %u.%2.2u\337" "C  ",Degrees,DeciDegrees);
although I may go back to using the hex code, it works either way.

Thank you
BILL.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: SPECIAL ASCII CHARACTERS ON LCD
« Reply #14 on: November 11, 2016, 02:54:04 pm »
If you use a three digit Octal escape (not Hex), you *don't* need to break the string:
Code: [Select]
sprintf(OutString,"HSink +1: %u.%2.2u\337C  ",Degrees,DeciDegrees);
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf