HowTo Printf for custom LCD?

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all,

Id like to know if someone has a customizeable printf routine for output devices such as uart/lcd ?

The version im working on now is using 'ram-strings' as input, but id like to use the rom for the constants and 'ram' for the variables.

eg:
myprintf("Hello, my name is: %s.", somestring);

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi ,

You can use printf() with whatever kind of device you wish, just use fdevopen() to pass the functionpointer to your customized _putchar, _getchar routine to the printf function. If you would like to store your format strings in flash use printf_P().
Search the this forum for examples.

Koen

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah nice, putchar and getchar wouldn't be too difficult :P

Ill search for the forums and see If i can use it.

This is what ive cameup with myself:

void lcdprintf(const char *conststring, ...)
{
va_list arg;
char buffer[31];

va_start(arg, conststring);
while (*conststring != 0)
{
if (*conststring != '%')
{
t6963_putch(*conststring);
conststring++;
}
else
{
conststring++; //skip '%' sign.
if (*conststring == 'c')
{
char arg1;
arg1 = va_arg (arg, char *);
t6963_putch(arg1);
}
if (*conststring == 'd')
{
int arg1;
arg1 = va_arg (arg, int *);
itoa(buffer,arg1,10); //integer to ascii.
t6963_printfs(buffer); //print interger-ascii string.
}
if (*conststring == 'u')
{
unsigned int arg1;
arg1 = va_arg (arg, unsigned int *);
utoa(buffer,arg1,10); //unsigned integer to ascii.
t6963_printfs(buffer); //print unsigned interger-ascii string.
}
if (*conststring == 'x')
{
unsigned long arg1;
arg1 = va_arg (arg, unsigned long *);
ultoa(buffer,arg1,16); //unsigned integer to ascii.
t6963_printfs(buffer); //print unsigned interger-ascii hexidecimal string.
}
}
}
va_end(arg);

}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just don't give your custom putchar() and getchar() routines the name "putchar" and "getchar" or you'll get a bunch of error's when including stdio.h, UART_putchar() will do fine however.

HTH

Koen.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My lcd uses the memory interface for reading and writing to, and what If want to display an string from the external memory to the lcd?

I know that I need to deselect the Memory inorder to write/read from the lcd... Is this a culprit for the standard printf routine?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is your LCD actually connected to the external memory interface? If so you should have three/two different I/O addresses for it; an LCD write address for writing data to the display (R/W=0 RS=1), a read address for reading data and the busyflag from the LCD (R/W=1 RS=0) and a command address (R/W=0 RS=0). Your putchar - getchar routines should therefor yust write (or read) data to (from) these physical locations. There is no problem whatsoever to do this with the standard printf() function.

Koen.

PS. Please don't ask how to declare fixed I/O addresses i do not know. Maybe someone else can be of assistance there... (Or see the FAQ it must be there somewhere)

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure that you know what i mean?

Eg:

my ext sram:
0x2000: 'H'
0x2001: 'e'
0x2002: 'l'
0x2003: 'l'
0x2004: 'o'
0x2006: 0

Sram can only be read when the MemoryIO line is pulled low . cbi(portd,mio);
this disables all IO devices (LCD), and allows the sram to go freely.

Example problem:

char *pPointer;
pPointer = 0x2000;
printf"Sram text = %s", pPointer);

This will cause the reading of pPointer in the external SRAM, while the LCD is also in the External SRAM region only MIO but must be HIGH for LCD to operate :P

thats my biggest concern.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I still don't see a problem just read the char from SRAM turn MIO high and write it out to the LCD. All can be done inside the LCD_putchar() function.

eg.

int LCD_putchar(char c)
{
/* at this point printf() has read whatever char's you need from internal / external sram depending on the address */

const char *MyLCDaddress = 0x2000;

// Do whatever you need to address the LCD

*MyLCDaddress = c;

return 0;
}

Koen

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok thats sorted out :D

tnx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do remember however that printf() is huge in code size!

Koen.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What about my version of printF ?

I made this during the first post of this thread and the "ok thats sorted out post" .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

excuse me for my filenameing ;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"excuse me for my filenameing ;)"

But, hey, it's unique! ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"true true".
Hey wanna 'bud' ?

:P