Jump to content
43oh

Tiny printf() - C version


Recommended Posts

CCS requires labels in asm code to begin in the first column, so leading spaces will cause problems. This is typical for assembler code.

 

Firefox may have problems with copy/paste from the forum. Chrome, Safari and IE seem to work as expected.

 

To use the printf() with an LCD, just create a function named putc() that sends a single character to the LCD. If you find some sample code for LCD, there will probably a function that does this - just rename it.

 

You will also need a puts() function. That can be this...

 

void puts(char *s) { while(*s) putc(*s++); }

Link to post
Share on other sites
  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This is a tiny printf() function that can be used with the chips that come with the Launchpad. Code size is about 640 bytes with CCS.   There are 7 format specifiers: %c - Character %s - String %

CCS requires labels in asm code to begin in the first column, so leading spaces will cause problems. This is typical for assembler code.   Firefox may have problems with copy/paste from the forum. C

This code was written when the MSP430 Lauchpad shipped with chips that had 128 bytes of RAM, 2k of flash, and no hardware serial port. So it was important to keep code very compact and a software UART

Posted Images

AAAAAAAAAAAAA!!! YES!!!

 

I was using a sprintf to create a character string and was trying to display an integer on an LCD using %i as the format specifier.

 

It was just a luck of the draw that I logged on to this forum and saw someone had posted a reply to this thread!

 

I need %c.. My thanks goes out to oPossum who started this thread!!!!

 

YAY!!

Link to post
Share on other sites
  • 3 months later...

Dear All,

 

Im a little bit new with msp430 and uC-s. I saw that here is a lightweight printf fot msp430, im using IAR , but it is not work for me. as i saw it is for CSS.

 

Is any1 here who use IAR with printf?

I want to use the printf for debugging. Launchpad -> PC.

 

I have 2 rfm12bs modul today i was able to use them with PIC now i want to use it with msp430g2553.

i would like to debug the data what i recieved.

 

here is my simple code for hello world but no output at Putty:

 

 
   #include  "msp430g2553.h"
   #include "intrinsics.h"
#include "stdio.h"

void main(void)
{
 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
 BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
 DCOCTL = CALDCO_1MHZ;
 P1SEL = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
 P1SEL2 = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
 UCA0CTL1 |= UCSSEL_2;                     // SMCLK
 UCA0BR0 = 104;                            // 1MHz 9600
 UCA0BR1 = 0;                              // 1MHz 9600
 UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1
 UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
 //IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

//  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled




 while(1){
// UCA0TXBUF = 0x31;
// UCA0TXBUF =   printf("The color: %s\n", "blue");
//printf( "Hello %s, you are %d years old\n", name, age );
printf("Hello World ");
   __delay_cycles(800);
 }

}

Link to post
Share on other sites

Dear bluehash, thanks for your fast replay.

Somehow i missed it .

Actually im pretty new in this , i usedto used pic and i should only used printf for sending texts via rsr32 to my pc.

here is a sample snapshot of "my" pic code what i would like to print.

printf("\r\n status:%4LX  ", temp ); 
  if (temp)      // <>0
  {
     if(temp & RGITFFIT)             // Check RGIT / FFIT 
            printf("\r\n----TX ready for next byte or FIFO received data Status " );
     if(temp & POR)   // Check Power on reset
             printf("\r\n----Power on Reset Status");

 

As i mentioned im using IAR.

If someone cold show me a code part for me what is working i would go to figure out what i need. i hope.

 

Sincerely Balazs

Link to post
Share on other sites
  • 10 months later...
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...