Buffer size is the longest string, so 16 for one line of a 16x2 LCD, or 32 for both lines, or the longest you'll expect it to be (whichever is shorter), each extra takes a byte of RAM, so don't declare it any longer than you need it to be.
If you would go with my advice then it will be much more simple. There is no reason to do it the way you are doing it unless you are dealing with floating point numbers as integers.hahah.. true.. all I am seeing is 'A' on the screen. Why is that and How can I deal with that? By parsing the values?
You need to allow one character for the null character as I mentioned above.So I can simply say char buffer[15]. That will take care of the only the first 15 characters on the LCD? If so, then I indeed have to be careful with alloting the size. But in my actual code, i left the number of elements blank:
char buffer[];----> I figured in this way, it'll take up as much as it needs to get the job done. Rational thinking or stroke of luck?
You are suggesting that I should use %i instead of %u in the sprintf? With %i, i cannot see my integer that I am trying to display. But when I use %u, I canIf you would go with my advice then it will be much more simple. There is no reason to do it the way you are doing it unless you are dealing with floating point numbers as integers.
The way the LCD is lined up, if I have to display exactly 16 characters on one line, I go ahead and do it. The null character goes onto the next address, which exsists in the DDRAM of the LCD but does not gets displayed. This data is avaliable on the HD44780 Hitachi LCD 16x2 data sheet.The length of your buffer is going to depend on the width of your display. If it is a 16 character display then use 17 (one character for null). I usually pad it a bit if using sprintf. That way I don't need to worry that I get a data overrun if printing a larger number than expected.
You are suggesting that I should use %i instead of %u in the sprintf? With %i, i cannot see my integer that I am trying to display. But when I use %u, I can
If your Print function is written properly, it will not be sending a null to the LCD. Post your code for Print (char *buffer).The way the LCD is lined up, if I have to display exactly 16 characters on one line, I go ahead and do it. The null character goes onto the next address, which exsists in the DDRAM of the LCD but does not gets displayed. This data is avaliable on the HD44780 Hitachi LCD 16x2 data sheet.
void Print(char *Text)
{
char *c;
c=Text;
if(!Text) return;
for( c = Text; *c != '\0'; ++c)
{
SendByte(*c, TRUE);
}
}
#include <msp430g2231.h>
#include <stdio.h>
#include "lcd.h"
char buffer[17];
int a = 2456;
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
P1DIR=0xF9; // microcontroller
P1OUT=0; // microcontroller
LCD_init(); // Initialize LCD
clear(); // Clear LCD
sprintf(buffer, "Value=%i",(a+'0'));
Print(buffer);
}
here is the code for Print and the actual program that I am using it in. I keep telling you that %i doesnt work. BTW, %i is for integers and %c is for characters from what I have gathered.
Look at what I gave you again.main code:Rich (BB code):void Print(char *Text) { char *c; c=Text; if(!Text) return; for( c = Text; *c != '\0'; ++c) { SendByte(*c, TRUE); } }
The above only works for 1- %c and 2- for a single integer, because 1- when I use %i, the 'text' shows up but the actual number its self doesnt and 2- When I use %c, then only the 'text' and the first digit shows up (not all of them). I have to send each digits manually by parcing them (not shown in the above main code). Hope this clarifies my situation. But I really do appreciate your help. THANKS!Rich (BB code):#include <msp430g2231.h> #include <stdio.h> #include "lcd.h" char buffer[17]; int a = 2456; void main(void) { WDTCTL = WDTPW + WDTHOLD; P1DIR=0xF9; // microcontroller P1OUT=0; // microcontroller LCD_init(); // Initialize LCD clear(); // Clear LCD sprintf(buffer, "Value=%i",(a+'0')); Print(buffer); }
#include <msp430g2231.h>
#include <stdio.h>
#include "lcd.h"
char buffer[17];
int a = 2456;
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
P1DIR=0xF9; // microcontroller
P1OUT=0; // microcontroller
LCD_init(); // Initialize LCD
clear(); // Clear LCD
sprintf(buffer, "Value=%i",a);
Print(buffer);
}
If this is the value of your buffer before it makes a call to your Print function then your Print function is not the problem. Or at least not yet.Please look at post# 30 to see my Print function, maybe that might be the problem (although it wont caz I can see it working )
By the way, the buffer = 0x0200
[0] = V
[1] = a
[2] = l
[3] = u
[4] = e
[5] = =
[6] = .
[7] = 0
[8] = 3
[9] = .
[10] = .
[11] = .
[12] = .
[13] = .
[14] = .
[15] = .
[16] = ,
#include <msp430g2231.h>
#include <stdio.h>
#include "lcd.h"
char buffer[17];
int x;
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
P1DIR0xF9; // microcontroller
P1OUT=0; // microcontroller
LCD_init(); // Initialize LCD
clear(); // Clear LCD
x=314;
memset(buffer,0,17);
sprintf(buffer,"Value=%i",x);
Print(buffer);
}
When I try to compile it, it says that the memset function is declared implicitly
Rich (BB code):#include <msp430g2231.h> #include <stdio.h> #include "lcd.h" char buffer[17]; int x; void main(void) { WDTCTL = WDTPW + WDTHOLD; P1DIR0xF9; // microcontroller P1OUT=0; // microcontroller LCD_init(); // Initialize LCD clear(); // Clear LCD x=314; memset(buffer,0,17); sprintf(buffer,"Value=%i",x); Print(buffer); }
That is one bizarre compiler. Do a file find on string.h in the directory that has your compiler files. Make sure it is just not a path issue.nope, my compiler does not recongnize <string.h> lol.
I have yet to see where that is documented in the C18 compiler. So.....Have you looked in the helpfile for "String operations"?
It should list useful functions for this, AND tell you the name of the header file you need to include.
Maybe you need to add strings.h to your project? (in addition to including it. that's if you are including "strings.h" and not <strings.h>)