|
|
View previous topic :: View next topic |
Author |
Message |
micro2 Guest
|
printf and spi |
Posted: Sun Nov 13, 2005 12:42 am |
|
|
how I can send a string on a LCD 4X20 in SPI modality with the Printf instruction?
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Sun Nov 13, 2005 10:22 am |
|
|
You write a function that can send a byte over SPI, to your target LCD. Probably using the standard SPI commands, but also probably with some extra handshaking involved (on most LCD's). If you call this something like 'LCD_SEND_BYTE', then you just use printf, as:
printf(LCD_SEND_BYTE,"This is the text to send");
The details of what will be needed in this 'wrapper' function, will depend on your LCD.
Best Wishes |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Sun Nov 13, 2005 8:27 pm |
|
|
Isn't printf() a reserved function for the UART? The SPI communication function should have a different name, like lcd_printf(...). |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Sun Nov 13, 2005 8:51 pm |
|
|
kender wrote: | Isn't printf() a reserved function for the UART? The SPI communication function should have a different name, like lcd_printf(...). |
No - you can use printf as previously mentioned. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 13, 2005 8:54 pm |
|
|
Quote: | PRINTF()
FPRINTF()
Syntax: printf (string)
or
printf (cstring, values...)
or
printf (fname, cstring, values...)
fprintf (stream, cstring, values...)
Parameters: String is a constant string or an array of characters null
terminated. Values is a list of variables separated by
commas, fname is a function name to be used for outputting
(default is putc is none is specified). Stream is a stream
identifier (a constant byte) |
|
|
|
Ttelmah Guest
|
|
Posted: Mon Nov 14, 2005 3:34 am |
|
|
kender wrote: | Isn't printf() a reserved function for the UART? The SPI communication function should have a different name, like lcd_printf(...). |
Printf, is an output formatting instruction. By default, it sends it's output to 'putc', _but_ if a function name is given as an extra variable in front of the string declarations, it instead sends it's output to this. In the example given, the output of printf, is routed to 'LCD_SEND_BYTE'.
As a little 'demo', if you declare a function like this:
Code: |
char str[30];
int8 ctr;
void reset_ctr() {
ctr=0;
}
void char_to_str(int8 chr) {
str[ctr++]=chr;
}
|
You can then use printf, like:
Code: |
reset_ctr(); //make sure I am pointed to the start of the string
printf(chr_to_str,"Test string to buffer\n");
|
and you will find that the buffer at 'str', now contains the output string, just as if you had used sprintf.
This ability to 'reroute' the output of the printf function, can be very useful indeed, if you want to achieve some formatting not supported by the function, or send the data to an output 'target', which is not a standard asynchronous serial port.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|