CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

printf and spi

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
micro2
Guest







printf and spi
PostPosted: Sun Nov 13, 2005 12:42 am     Reply with quote

how I can send a string on a LCD 4X20 in SPI modality with the Printf instruction?
Thanks
Ttelmah
Guest







PostPosted: Sun Nov 13, 2005 10:22 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Sun Nov 13, 2005 8:27 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Nov 13, 2005 8:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 13, 2005 8:54 pm     Reply with quote

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







PostPosted: Mon Nov 14, 2005 3:34 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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