kgavionics
Full Member level 3
- Joined
- Jun 12, 2012
- Messages
- 167
- Helped
- 7
- Reputation
- 14
- Reaction score
- 11
- Trophy points
- 1,298
- Location
- Alberta.Canada
- Activity points
- 2,482
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
#include <stdlib.h>
int main(void)
{
unsigned char str[3],value=0;
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
LCDcursorOFF();
itoa(value,str,10);
LCDstring(str,3);
//LCDsendChar(value);
while(1);//loop demos
return 0;
}
//working on hardware
You don't need to know my hardware, this is C program and an LCD library which works fine! I'm using an arduino uno if that you want to know!You tell us absolutely nothing about your hardware. You tell us next to nothing about your software, other than the fact that you're calling some undefined subroutines.
Impossible to even GUESS what's going on.
Have you looked at the data you're sending to the display? Does it look right?
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
#include <stdlib.h>
int main(void)
{
unsigned char str[17],value=0; /* make str large enough to hold the maximum output of itoa() */
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
LCDcursorOFF();
memset(str,' ',sizeof(str)); /* fill str with blanks */
itoa(value,str,10); /* WARNING: unsafe string function, buffer overflow possible */
str[sizeof(str)-1] = 0; /* mark end of a maximum size string */
LCDstring(str,3);
//LCDsendChar(value);
while(1);//loop demos
return 0;
}
//working on hardware
Thank you for the code, it still shows a weird character instead of 2!Perhaps if you wrote better code with comments you may achieve better results.
C:#include <avr/io.h> #include <avr/pgmspace.h> #include <util/delay.h> #include "lcd_lib.h" #include <stdlib.h> int main(void) { unsigned char str[17],value=0; /* make str large enough to hold the maximum output of itoa() */ LCDinit();//init LCD bit, dual line, cursor right LCDclr();//clears LCD LCDcursorOFF(); memset(str,' ',sizeof(str)); /* fill str with blanks */ itoa(value,str,10); /* WARNING: unsafe string function, buffer overflow possible */ str[sizeof(str)-1] = 0; /* mark end of a maximum size string */ LCDstring(str,3); //LCDsendChar(value); while(1);//loop demos return 0; } //working on hardware
Perhaps if you wrote better code with comments you may achieve better results.
C:#include <avr/io.h> #include <avr/pgmspace.h> #include <util/delay.h> #include "lcd_lib.h" #include <stdlib.h> int main(void) { unsigned char str[17],value=0; /* make str large enough to hold the maximum output of itoa() */ LCDinit();//init LCD bit, dual line, cursor right LCDclr();//clears LCD LCDcursorOFF(); memset(str,' ',sizeof(str)); /* fill str with blanks */ itoa(value,str,10); /* WARNING: unsafe string function, buffer overflow possible */ str[sizeof(str)-1] = 0; /* mark end of a maximum size string */ LCDstring(str,3); //LCDsendChar(value); while(1);//loop demos return 0; } //working on hardware
AFAIK, in C we can use either of the two symbols!Just curious, should not this -
str[sizeof(str)-1] = 0;
be this -
str[sizeof(str)-1] = '\0';
Regards, Dana.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include <avr/io.h> #include <avr/pgmspace.h> #include <util/delay.h> #include "lcd_lib.h" #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char str[4],value=1; LCDinit();//init LCD bit, dual line, cursor right LCDclr();//clears LCD LCDcursorOFF(); sprintf(str,"%03d",value); LCDstring(str,3); while(1);//loop demos return 0; }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include <avr/io.h> #include <avr/pgmspace.h> #include <util/delay.h> #include "lcd_lib.h" #include <stdlib.h> unsigned char lowb,medb,hib,hexv; int main(void) { hexv=0x0; // hex value to convert lowb=(hexv%10)| 0x30; //low byte binary to decimal conversion, then OR it with 0x30 to obtain the ascii code! medb=((hexv/10)%10)|0x30; //middle byte binary to decimal conversion, then OR it with 0x30 to obtain the ascii code! hib=((hexv/10/10)%10) | 0x30; //high byte binary to decimal conversion, then OR it with 0x30 to obtain the ascii code! LCDinit();//init LCD bit, dual line, cursor right LCDclr();//clears LCD LCDcursorOFF(); LCDsendChar(hib); LCDsendChar(medb); LCDsendChar(lowb); while(1);//loop demos return 0; }
Everything works fine with the last code I wrote!Hello!
Is it solved now?
For your information, the characters you see are not that weird to me, they are simply
Japanese. The character LCDs usually have means to reconfigure the character set, so I don't think it's a matter of wrong atoi or anything else, it's just a matter of LCD configuration. There must be a register somewhere allowing you to choose plain ascii rom or "katakana" as you show. Is this LCD a new one that you bought for instance at Digikey, or was it used earlier, and potentially configured for Japanese fonts?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?