SPECIAL ASCII CHARACTERS ON LCD - Page 1
Forum section: electronics / beginners

author: neko efecktz
author_rank: Regular Contributor
timestamp: November 11, 2016, 12:51:19 am
content: Good morning all.I am doing a bit more work on my micro controller project and need a little helpBelow is a section of the code to display a message to LCD.At the moment it displaysHS1: 35.03Deg CI want to be able to display the Degree symbol "°"HS1: 35.03°CCan Anyone helpI am using MPLAB X IDE v2.10The chip is 16F877Aelse if (FAULT_6==0) //FAULT, RC6 AT 0V{Lcd_Init(); // initialize LCDLcd_Clear(); // clear LCDinit();Lcd_Set_Cursor(1,1);Lcd_Write_String(MSG_M9A);Lcd_Set_Cursor(2,1); // select line 2Lcd_Write_String(MSG_M9B);DelayMs(1000);Last_Value=-1; // Force update on first passLcd_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 decimalsDegrees = Degrees/20; //extract integer volts// Lcd_Clear();Lcd_Set_Cursor(1,1); // select line 1sprintf(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 decimalsDegrees = Degrees/20; //extract integer voltsLcd_Set_Cursor(2,1); // select line 2sprintf(OutString,"HS2: %u.%2.2uDeg C ",Degrees,DeciDegrees);Lcd_Write_String(OutString);}// Last_Value = Adres;DelayMs(1000);}}Thank youBILL.

author: IanB
author_rank: Super Contributor
timestamp: November 11, 2016, 12:56:03 am
content: 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:sprintf(OutString,"HS1: %u.%2.2u°C ",Degrees,DeciDegrees);

author: neko efecktz
author_rank: Regular Contributor
timestamp: November 11, 2016, 01:14:40 am
content: IanB.that was quick.Yes I did try inserting the ° character but it was rejectedmain.c:247: warning: (228) illegal character (0xB0)I have seen some instructions on using the special ascii characters but when I search for themI 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 OVERLOADmy wife says that, Perhaps I need to find another hobby.I suggested we go Sky Diving together.She said NO WAY.ThanksBILL.

author: matseng
author_rank: Frequent Contributor
timestamp: November 11, 2016, 02:01:37 am
content: 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.

author: Ian.M
author_rank: Super Contributor
timestamp: November 11, 2016, 02:06:59 am
content: Assuming its a HD44780 compatible display, with Hitachi's standard A00 character ROM (slightly tweakedJIS 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: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 . . .

author: mariush
author_rank: Super Contributor
timestamp: November 11, 2016, 02:47:03 am
content: 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 informationHere'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/2063162Just 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.

author: neko efecktz
author_rank: Regular Contributor
timestamp: November 11, 2016, 03:42:19 am
content: Thanks Ianthat worked with a very minor changeI 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 pictureThanksBILL.

author: IanB
author_rank: Super Contributor
timestamp: November 11, 2016, 04:14:18 am
content: Quote from: neko efecktz on November 11, 2016, 03:42:19 amIf you want to avoid the extra space between the ° and the C, try it like this:Code:sprintf(OutString,"HS1: %u.%2.2u\xDF" "C ",Degrees,DeciDegrees);

author: Ian.M
author_rank: Super Contributor
timestamp: November 11, 2016, 04:19:01 am
content: 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: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:sprintf(OutString,"HS1: %u.%2.2u\337" "C ",Degrees,DeciDegrees);Personally I'd use the former for clarity:Code:#define sDEG "0xDF" // HD44780 degree symbol//...sprintf(OutString,"HS1: %u.%2.2u" sDEG "C ",Degrees,DeciDegrees);

author: neko efecktz
author_rank: Regular Contributor
timestamp: November 11, 2016, 04:34:14 am
content: Ian,I found to avoid the gap between ° & Cadd a back slashsprintf(OutString,"HS1: %u.%2.2u\xDF\C",Degrees,DeciDegrees);BILL.

author: Ian.M
author_rank: Super Contributor
timestamp: November 11, 2016, 05:24:43 am
content: *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' ?

author: Kalvin
author_rank: Super Contributor
timestamp: November 11, 2016, 06:58:43 am
content: How about:Code:#define DEGREEDOT '\xdf'#define DEGREESYM 'C'sprintf(OutString,"HS1: %u.%2.2u%c%c ",Degrees,DeciDegrees, DEGREEDOT, DEGREESYM);

author: Karel
author_rank: Super Contributor
timestamp: November 11, 2016, 07:31:56 am
content: Quote from: neko efecktz on November 11, 2016, 12:51:19 amThat is not an ascii character. And "special" ascii characters do not exist. Not even "extended" ascii characters...

author: neko efecktz
author_rank: Regular Contributor
timestamp: November 11, 2016, 02:06:39 pm
content: Thanks everyone for your input.I've gone with using the hex value as suggested by IanMsprintf(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 youBILL.

author: Ian.M
author_rank: Super Contributor
timestamp: November 11, 2016, 02:54:04 pm
content: If you use a three digit Octal escape (not Hex), you *don't* need to break the string:Code:sprintf(OutString,"HSink +1: %u.%2.2u\337C ",Degrees,DeciDegrees);