Jump to content
43oh

zeke

Members
  • Content Count

    1,782
  • Joined

  • Last visited

  • Days Won

    102

Reputation Activity

  1. Like
    zeke got a reaction from bluehash in Stand alone programming software   
    Hi Guys,
     
    Recently, I had to find a stand alone program that would give me the ability to program an MSP. This is for the factory floor. They don't want to use CCS on the factory floor, for obvious reasons.
     
    In my search, I found others asking the same question.
     
    There is the Gang Programmer.
     
    Or, you can use the Launchpad in combination with Elpotronic's FET-Pro430-Lite.
     
    I think Elpotronic's program is perfect. Give it the hex file and it will program your MSP430 using any TI USB programmer. It's cool that you can use Spy Bi-Wire to program your devices.
     
    Hope you like it.
  2. Like
    zeke reacted to bluehash in Windows Programming?   
    No experience with Realbaisc, but try Nokia's QT. It's platform independent UI framework:
     
    http://qt.nokia.com/
  3. Like
    zeke got a reaction from NatureTM in Addiction to buying parts   
    So, I'd like to bring to this topic a new entry for all of you that lust after electronic parts.
     
    I give you MDFLY.
     
    I just blew a wad of dough there. Excellent prices on SMD resistor kits and capacitor kits.
     
    Just check this out. It's a set of meter probes that let you measure SMD parts. How cool is that?!
     
    No one can touch them on what they offer. Not even Digikey.
     
    Okay, dealextreme could probably touch them but only because they're probably cousins or something.
  4. Like
    zeke got a reaction from GeekDoc in Addiction to buying parts   
    So, I'd like to bring to this topic a new entry for all of you that lust after electronic parts.
     
    I give you MDFLY.
     
    I just blew a wad of dough there. Excellent prices on SMD resistor kits and capacitor kits.
     
    Just check this out. It's a set of meter probes that let you measure SMD parts. How cool is that?!
     
    No one can touch them on what they offer. Not even Digikey.
     
    Okay, dealextreme could probably touch them but only because they're probably cousins or something.
  5. Like
    zeke got a reaction from gatesphere in Addiction to buying parts   
    So, I'd like to bring to this topic a new entry for all of you that lust after electronic parts.
     
    I give you MDFLY.
     
    I just blew a wad of dough there. Excellent prices on SMD resistor kits and capacitor kits.
     
    Just check this out. It's a set of meter probes that let you measure SMD parts. How cool is that?!
     
    No one can touch them on what they offer. Not even Digikey.
     
    Okay, dealextreme could probably touch them but only because they're probably cousins or something.
  6. Like
    zeke got a reaction from bluehash in Addiction to buying parts   
    So, I'd like to bring to this topic a new entry for all of you that lust after electronic parts.
     
    I give you MDFLY.
     
    I just blew a wad of dough there. Excellent prices on SMD resistor kits and capacitor kits.
     
    Just check this out. It's a set of meter probes that let you measure SMD parts. How cool is that?!
     
    No one can touch them on what they offer. Not even Digikey.
     
    Okay, dealextreme could probably touch them but only because they're probably cousins or something.
  7. Like
    zeke got a reaction from Fe2o3Fish in CNX.org has MSP430 training materials online   
    I was smurfing the web tonight and stumbled across this webpage at CNX.org:
     
    Teaching and classroom laboratories based on the
  8. Like
    zeke got a reaction from GeekDoc in CNX.org has MSP430 training materials online   
    I was smurfing the web tonight and stumbled across this webpage at CNX.org:
     
    Teaching and classroom laboratories based on the
  9. Like
    zeke got a reaction from microcozmoz in Best information for those new to the MSP430?   
    So, now you got a job doing hardware design and you want to use the MSP430 in your design.
     
    But you've discovered that your boss has insisted on using this "wicked cool awesome" and ancient 5V sensor because they have a bazillion in stock.
     
    "What's the problem with that?" you ask.
     
    The problem is this: the MSP430 is a 3.6V device and it doesn't have 5V tolerant I/O's. This means that you'll probably hurt the part if you put 5V into an input. Go ahead and google it. You'll find our very own OCY schooling someone on this topic back in 2008. I'll let you find the article. OCY is shy. And he's probably gonna rip me open for giving away his secret identity.
     
    So, what's the answer? SLAA148 is the answer.
     
    It will take you through the various input and output scenarios that you may face trying to interface to higher voltage systems - not just 5V.
     
    Using this information, you should be able to measure the status of a 12V power supply with the A/D inputs or figure out how to drive a 12V relay.
     
    Have a read. It's useful info.
  10. Like
    zeke got a reaction from Dimiric in Best information for those new to the MSP430?   
    As you progress in your development of an embedded system based upon the MSP430, you will eventually have to cut your dependency on your dev board. When you do this, you will have to give your system the ability to be programmed.
     
    Whether by JTAG or by Spy-Bi-Wire, you will have to assimilate and understand the information inside this document. Otherwise, you will have a brick coming off the assembly line.
     
    Do want to make a million bricks or a million dollars?
     
    Knowing this information will save you time, money and prevent ulcers!
     
     
    4. slau320: Programming via the JTAG Interface
     
    This document describes the functions that are required to erase, program, and verify the memory module
    of the MSP430
  11. Like
    zeke got a reaction from Rei Vilo in Best information for those new to the MSP430?   
    If you are new to the MSP430 then you're probably drowning in information right now.

    It's true that there are a zillion configurations to make before the 430 will do what you want it do do.

    So I'm betting that you are asking yourself "Where do I start?"

    I humbly suggest the following TI application notes and books that will get you going in the right direction:

    1. slaa294: MSP430 Software Coding Techniques

    This application report covers software techniques and topics of interest to all MSP430
    programmers. The first part of the document discusses the MSP430 standard
    interrupt-based code flow model, recommended for the vast majority of applications.
    The next part discusses a handful of techniques that should be considered by any
    developer that sets out to develop an MSP430 application. Using these methods can
    greatly reduce debug time and/or provide additional robustness in the field. They
    include initialization procedures, validation of supply rails before performing
    voltage-sensitive operations, and use of special functions. Code examples are
    provided.

    2. : MSP430 32-kHz Crystal Oscillators

    Selection of the right crystal, correct load circuit, and proper board layout are important
    for a stable crystal oscillator. This application report summarizes crystal oscillator
    function and explains the parameters to select the correct crystal for MSP430
    ultralow-power operation. In addition, hints and examples for correct board layout are
    given. The document also contains detailed information on the possible oscillator tests
    to ensure stable oscillator operation in mass production.

    3. MSP430 Microcontroller Basics by John H. Davies

    The best thing I can say about this book at this time is that it describes well how to make use of the clocking system of the MSP430. This book should be in your personal library or at least on your wishlist.

    Once you digest the information above then you will be in good shape for success in working with the msp430.

    Have something to add?
    Then post up your valuable sources of knowledge.
  12. Like
    zeke got a reaction from gatesphere in CNX.org has MSP430 training materials online   
    I was smurfing the web tonight and stumbled across this webpage at CNX.org:
     
    Teaching and classroom laboratories based on the
  13. Like
    zeke got a reaction from bluehash in CNX.org has MSP430 training materials online   
    I was smurfing the web tonight and stumbled across this webpage at CNX.org:
     
    Teaching and classroom laboratories based on the
  14. Like
    zeke reacted to RobG in 3.3V LCD Displays with 5V back-light   
    Most of 3.3V LCD displays come with 5V back-light and one way of powering it in such displays is using step up converter. There are many available, like LT1300 from LT or MAX756/856 from Maxim.
    For my display, I am using LT1300 which requires 4 additional parts only:
    L1 - 22uH inductor (10uH-22uH will work)
    C1,C2 - 47uF (47uF-100uF)
    D1 - 1N5817 Schottky diode
     

     

  15. Like
    zeke got a reaction from vicvelcro in Best information for those new to the MSP430?   
    So, now you got a job doing hardware design and you want to use the MSP430 in your design.
     
    But you've discovered that your boss has insisted on using this "wicked cool awesome" and ancient 5V sensor because they have a bazillion in stock.
     
    "What's the problem with that?" you ask.
     
    The problem is this: the MSP430 is a 3.6V device and it doesn't have 5V tolerant I/O's. This means that you'll probably hurt the part if you put 5V into an input. Go ahead and google it. You'll find our very own OCY schooling someone on this topic back in 2008. I'll let you find the article. OCY is shy. And he's probably gonna rip me open for giving away his secret identity.
     
    So, what's the answer? SLAA148 is the answer.
     
    It will take you through the various input and output scenarios that you may face trying to interface to higher voltage systems - not just 5V.
     
    Using this information, you should be able to measure the status of a 12V power supply with the A/D inputs or figure out how to drive a 12V relay.
     
    Have a read. It's useful info.
  16. Like
    zeke reacted to OCY in 3-Pin MSP430?   
    3-pin? No. But 4 pins is possible. Vcc, Vss, RST, and TEST are needed to program the Flash.
    After programming the Flash, you could cut RST and TEST too and get a 2-pin "functional" chip!
    The "function" is to sense Vcc and Temperature and transmit them to a near by radio.
    I did that without connecting anything to any Port Pins. But I have not tried actually cutting off those pins,
  17. Like
    zeke got a reaction from aravind90 in connecting the launchpad with EZ430-RF2500T   
    Yes, but only for the purpose of programming the rf2500 target board.
  18. Like
    zeke reacted to RobG in 16 segment bi-color LED displays   
    I got few very nice 16 segment bi-color LED displays from ERC electronics and here's my first stab at controlling them. Additional parts are 74hc595 (2) and TPIC6C595. Displays in the movie appear dim because pretty large current limiting resistors are used, they are very bright when used with the right resistors.
    Displays are bi-color, so you can get red, green , and any color in between (yellow.)
     


  19. Like
    zeke reacted to bluehash in max timer period?   
    Not the timer, but you can count the no. of ticks to get a time out. eg. count a 1 second timer 65536 times gives you 65536/60/60 = ~18t hours
  20. Like
    zeke got a reaction from GeekDoc in printf() function   
    If you need the printf() function and you have enough code space in your device then this routine will be your best bet, in my opinion.
     
    Help! CCS4.0 with MSP430F2252 has Trouble with 32 bit (Long) Data.
     
    For long term storage, this is the message that contains the code:

    Posted by Bin replied on 30 Dec 2009 1:55 PM Verified by Bin Verified Answer Prodigy80 Points Good inspiration. I casted all numbers with (long int) when calling printf() and it works! I think it is acceptable. A warning (is also an explanation) is written into the printf() comment section. See following source code. The printf() is ok to use now. Everyone is free to use and modify the source code below and I assume no responsibility. /*------------------------------------------------------------------- DESCRIPTION: Send one char in TX buffer, if it is not busy. Wait until not busy. INPUTS: One char. OUTPUTS: Send all the char in TX buffer. RETURNS: None. ---------------------------------------------------------------------*/ // Modify this routine so that it points to YOUR UART (zeke) void putChar(unsigned char byte) { while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = byte; // Load Tx register that clear UCA0TXIFG } /*------------------------------------------------------------------- DESCRIPTION: Move numbers of lines up in the HyperTerminal. INPUTS: None. OUTPUTS: Line up to TX buffer. RETURNS: None. ---------------------------------------------------------------------*/ void linesUp(unsigned char lines) { unsigned char i; for (i = 0; i < lines; ++i) { putChar(0x1b); putChar(0x5b); putChar(0x41); } } /*------------------------------------------------------------------- DESCRIPTION: Send out charater strings with defined width, justification and padding. Width = 0 or width < string length means unlimited width. Normal padding is space and left justification, but it can pad '0' or pad to the right side, depending on pad value. pad justification padding char bxxxxxx00 left ' ' bxxxxxx1x right ' ' or '0' bxxxxxxx1 left or right '0' INPUTS: Valid string and special charater in form of "\n" for example refered by pointer *string. Output field width. Justification and padding flag pad. OUTPUTS: Sent formated string to com port output. RETURNS: Total of chars sent. ---------------------------------------------------------------------*/ #define PAD_RIGHT 0x01 #define PAD_ZERO 0x02 int prints(char *string, unsigned char width, unsigned char pad) { int pc = 0; unsigned char padchar = ' '; // The pading char is space normally if (width > 0) // If output width is defined { unsigned char len = 0; char *ptr; for (ptr = string; *ptr; ++ptr) ++len; // Calculate string length and put it in len if (len >= width) width = 0; // If string is longer than width, then width is not applicable define as zero else width -= len; // Else redefine width as padding spaces if (pad & PAD_ZERO) padchar = '0'; // If padding char is zero, then get padchar as zero ready instead of original space } if (!(pad & PAD_RIGHT)) // If not right padding - left justification { for (; width > 0; --width) // If ther is padding width. Output padding char as '0' or ' '. { putChar (padchar); ++pc; } } for (; *string ; ++string) // Output the full string { putChar (*string); ++pc; } for (; width > 0; --width) { // Write padding char to the right if normal left justification putChar (padchar); ++pc; } return pc; // Return the output char number } /*------------------------------------------------------------------- * DESCRIPTION: Print 32 bit signed interger in dec or hex. In specific * width, padding and justification using prints(). Use 12 byte buffer * which is enough for 32 bit int. * INPUTS: Up to 32 byte signed interger i. Counting base: 10 or 16. * Sign flag sg. Output string width. padding and justification flag. * Leter base for number conversion. * OUTPUTS: Sent formated interger as string to com port output. * RETURNS: Total of chars sent. ---------------------------------------------------------------------*/ #define PRINT_BUF_LEN 12 int printi(long int i, unsigned char b, unsigned char sg, unsigned char width, unsigned char pad, unsigned char letbase) { char print_buf[PRINT_BUF_LEN]; // Interger as string array char *s; char neg = 0; unsigned long int t; unsigned long int u = i; int pc = 0; if (i == 0) // If output char is 0, then just output it with padding and width. { print_buf[0] = '0'; print_buf[1] = '\0'; // Always remenber to put string end return prints(print_buf, width, pad); //Print out zero and done. } if (sg && (b == 10) && (i < 0)) // If it is a negative int, then record the '-' and number as positive { neg = 1; u = -i; } s = print_buf + PRINT_BUF_LEN-1; // Point s to the end of the output buffer and put a null there. *s = '\0'; while (u) // Convert the positive int to string with whatever counting base, dec, or hex. { t = u % b; if( t >= 10 ) t += letbase - '0' - 10; *--s = t + '0'; u /= b; } if (neg) { // If it is a negative number if( width && (pad & PAD_ZERO) ) { // If there is width, right justified and pad with zero, output negative sign. putChar ('-'); ++pc; --width; } else *--s = '-'; // Otherwise put the '-' to string buffer. } return pc + prints (s, width, pad); // Output the string buffer and return the output counter. } /*------------------------------------------------------------------- * DESCRIPTION: short form of printf. Print argument strings with mixed * varables (string or interger)inside formated. * INPUTS: Argument string pointer. * OUTPUTS: print out the argument with style using prints() and printi(). * RETURNS: Total of chars sent. * Warning!!! varables and constant numbers even 0, must casted with * (long int)in printf(), if it is going to print out using * format "u", "d", "X" and "x"! Or the complier will assigned * 16-bit for data smaller than 16 bit and the argument pointer * will fetch a wrong 32-bit data and the argument point * increament will be in wrong size. * Limitations: 1) It treats all interger as 32 bit data only. * 2) No floating point data presentation. * 3) Has left/right alignment with 0 padding. * 4) Has format code "s", "d", "X", "x", "u" and "c" only. ---------------------------------------------------------------------*/ int printf(char *format, ...) { int width, pad; int pc = 0; char scr[2]; va_list args; va_start(args, format); for (; *format != 0; ++format) { if (*format == '%') { ++format; width = pad = 0; if (*format == '\0') break; if (*format == '%') goto out; if (*format == '-') { ++format; pad = PAD_RIGHT; } while (*format == '0') { ++format; pad |= PAD_ZERO; } for ( ; *format >= '0' && *format <= '9'; ++format) { width *= 10; width += *format - '0'; } if( *format == 's' ) { char *s = (char *)va_arg( args, int ); pc += prints (s?s:"(null)", width, pad); continue; } if( *format == 'd' ) { pc += printi (va_arg( args, long int ), 10, 1, width, pad, 'a'); continue; } if( *format == 'x' ) { pc += printi (va_arg( args, long int ), 16, 0, width, pad, 'a'); continue; } if( *format == 'X' ) { pc += printi (va_arg( args, long int ), 16, 0, width, pad, 'A'); continue; } if( *format == 'u' ) { pc += printi (va_arg( args, long int ), 10, 0, width, pad, 'a'); continue; } if( *format == 'c' ) { // char are converted to int then pushed on the stack scr[0] = (char)va_arg( args, int ); scr[1] = '\0'; pc += prints (scr, width, pad); continue; } } else { out: putChar(*format); ++pc; } } va_end( args ); return pc; } /* Test printf() below */ main { char *ptr = "Hello world!"; char *np = 0; long int i = 5; int bs = sizeof(long int)*8; // Bit to shift long int mi = ((long int)1 << (bs-1)) + 1; // Maximum negative number printf("%s\n", ptr); printf("printf test\n"); printf("%s is null pointer\n", np); printf("%d = 5\n", (long int)i); printf("%d = - max int\n", mi); printf("Long int 123456789 print out is %u", (long int)123456789); printf("\nmi in hex is %x\n", (long int)mi); printf("bs in dec is %u\n", (long int)bs); printf("char %c = 'a'\n", 'a'); printf("hex %x = ff\n", (long int)0xff); printf("hex %02x = 00\n", (long int)0); printf("signed %d = unsigned %u = hex %x\n", (long int)-32767, (long int)-32767, (long int)-32767); printf("signed %d = unsigned %u = hex %x\n", (long int)-3, (long int)-3, (long int)-3); printf("%d %s(s)%", (long int)0, "message"); printf("\n"); printf("%d %s(s) with %%\n", (long int)0, "message"); printf("justif: \"%-10s\"\n", "left"); printf("justif: \"%10s\"\n", "right"); printf(" 3: %04d zero padded\n", (long int)3); printf(" 3: %-4d left justif.\n", (long int)3); printf(" 3: %4d right justif.\n", (long int)3); printf("-3: %04d zero padded\n", (long int)-3); printf("-3: %-4d left justif.\n", (long int)-3); printf("-3: %4d right justif.\n\n\n", (long int)-3); } Result: Hello world! printf test (null) is null pointer 5 = 5 -2147483647 = - max int Long int 123456789 print out is 123456789 mi in hex is 80000001 bs in dec is 32 char a = 'a' hex ff = ff hex 00 = 00 signed -32767 = unsigned 4294934529 = hex ffff8001 signed -3 = unsigned 4294967293 = hex fffffffd 0 message(s) 0 message(s) with % justif: "left " justif: " right" 3: 0003 zero padded 3: 3 left justif. 3: 3 right justif. -3: -003 zero padded -3: -3 left justif. -3: -3 right justif.
     
    To use this code, modify the putChar() function so that it points to your UART.
     
    To verify it works, run the sample main() routine and compare the output to what is posted here.
     
    @Bin, wherever you are, Thank you!
  21. Like
    zeke got a reaction from GeekDoc in getting printf() working   
    I just wanted to follow up and say that if you need the printf() function then this routine will be your best bet, in my opinion.
     
    Help! CCS4.0 with MSP430F2252 has Trouble with 32 bit (Long) Data.
     
    For long term storage, I post the message that contains the code here:

    Posted by Bin replied on 30 Dec 2009 1:55 PM Verified by Bin Verified Answer Prodigy80 Points Good inspiration. I casted all numbers with (long int) when calling printf() and it works! I think it is acceptable. A warning (is also an explanation) is written into the printf() comment section. See following source code. The printf() is ok to use now. Everyone is free to use and modify the source code below and I assume no responsibility. /*------------------------------------------------------------------- DESCRIPTION: Send one char in TX buffer, if it is not busy. Wait until not busy. INPUTS: One char. OUTPUTS: Send all the char in TX buffer. RETURNS: None. ---------------------------------------------------------------------*/ // Modify this routine so that it points to YOUR UART (zeke) void putChar(unsigned char byte) { while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = byte; // Load Tx register that clear UCA0TXIFG } /*------------------------------------------------------------------- DESCRIPTION: Move numbers of lines up in the HyperTerminal. INPUTS: None. OUTPUTS: Line up to TX buffer. RETURNS: None. ---------------------------------------------------------------------*/ void linesUp(unsigned char lines) { unsigned char i; for (i = 0; i < lines; ++i) { putChar(0x1b); putChar(0x5b); putChar(0x41); } } /*------------------------------------------------------------------- DESCRIPTION: Send out charater strings with defined width, justification and padding. Width = 0 or width < string length means unlimited width. Normal padding is space and left justification, but it can pad '0' or pad to the right side, depending on pad value. pad justification padding char bxxxxxx00 left ' ' bxxxxxx1x right ' ' or '0' bxxxxxxx1 left or right '0' INPUTS: Valid string and special charater in form of "\n" for example refered by pointer *string. Output field width. Justification and padding flag pad. OUTPUTS: Sent formated string to com port output. RETURNS: Total of chars sent. ---------------------------------------------------------------------*/ #define PAD_RIGHT 0x01 #define PAD_ZERO 0x02 int prints(char *string, unsigned char width, unsigned char pad) { int pc = 0; unsigned char padchar = ' '; // The pading char is space normally if (width > 0) // If output width is defined { unsigned char len = 0; char *ptr; for (ptr = string; *ptr; ++ptr) ++len; // Calculate string length and put it in len if (len >= width) width = 0; // If string is longer than width, then width is not applicable define as zero else width -= len; // Else redefine width as padding spaces if (pad & PAD_ZERO) padchar = '0'; // If padding char is zero, then get padchar as zero ready instead of original space } if (!(pad & PAD_RIGHT)) // If not right padding - left justification { for (; width > 0; --width) // If ther is padding width. Output padding char as '0' or ' '. { putChar (padchar); ++pc; } } for (; *string ; ++string) // Output the full string { putChar (*string); ++pc; } for (; width > 0; --width) { // Write padding char to the right if normal left justification putChar (padchar); ++pc; } return pc; // Return the output char number } /*------------------------------------------------------------------- * DESCRIPTION: Print 32 bit signed interger in dec or hex. In specific * width, padding and justification using prints(). Use 12 byte buffer * which is enough for 32 bit int. * INPUTS: Up to 32 byte signed interger i. Counting base: 10 or 16. * Sign flag sg. Output string width. padding and justification flag. * Leter base for number conversion. * OUTPUTS: Sent formated interger as string to com port output. * RETURNS: Total of chars sent. ---------------------------------------------------------------------*/ #define PRINT_BUF_LEN 12 int printi(long int i, unsigned char b, unsigned char sg, unsigned char width, unsigned char pad, unsigned char letbase) { char print_buf[PRINT_BUF_LEN]; // Interger as string array char *s; char neg = 0; unsigned long int t; unsigned long int u = i; int pc = 0; if (i == 0) // If output char is 0, then just output it with padding and width. { print_buf[0] = '0'; print_buf[1] = '\0'; // Always remenber to put string end return prints(print_buf, width, pad); //Print out zero and done. } if (sg && (b == 10) && (i < 0)) // If it is a negative int, then record the '-' and number as positive { neg = 1; u = -i; } s = print_buf + PRINT_BUF_LEN-1; // Point s to the end of the output buffer and put a null there. *s = '\0'; while (u) // Convert the positive int to string with whatever counting base, dec, or hex. { t = u % b; if( t >= 10 ) t += letbase - '0' - 10; *--s = t + '0'; u /= b; } if (neg) { // If it is a negative number if( width && (pad & PAD_ZERO) ) { // If there is width, right justified and pad with zero, output negative sign. putChar ('-'); ++pc; --width; } else *--s = '-'; // Otherwise put the '-' to string buffer. } return pc + prints (s, width, pad); // Output the string buffer and return the output counter. } /*------------------------------------------------------------------- * DESCRIPTION: short form of printf. Print argument strings with mixed * varables (string or interger)inside formated. * INPUTS: Argument string pointer. * OUTPUTS: print out the argument with style using prints() and printi(). * RETURNS: Total of chars sent. * Warning!!! varables and constant numbers even 0, must casted with * (long int)in printf(), if it is going to print out using * format "u", "d", "X" and "x"! Or the complier will assigned * 16-bit for data smaller than 16 bit and the argument pointer * will fetch a wrong 32-bit data and the argument point * increament will be in wrong size. * Limitations: 1) It treats all interger as 32 bit data only. * 2) No floating point data presentation. * 3) Has left/right alignment with 0 padding. * 4) Has format code "s", "d", "X", "x", "u" and "c" only. ---------------------------------------------------------------------*/ int printf(char *format, ...) { int width, pad; int pc = 0; char scr[2]; va_list args; va_start(args, format); for (; *format != 0; ++format) { if (*format == '%') { ++format; width = pad = 0; if (*format == '\0') break; if (*format == '%') goto out; if (*format == '-') { ++format; pad = PAD_RIGHT; } while (*format == '0') { ++format; pad |= PAD_ZERO; } for ( ; *format >= '0' && *format <= '9'; ++format) { width *= 10; width += *format - '0'; } if( *format == 's' ) { char *s = (char *)va_arg( args, int ); pc += prints (s?s:"(null)", width, pad); continue; } if( *format == 'd' ) { pc += printi (va_arg( args, long int ), 10, 1, width, pad, 'a'); continue; } if( *format == 'x' ) { pc += printi (va_arg( args, long int ), 16, 0, width, pad, 'a'); continue; } if( *format == 'X' ) { pc += printi (va_arg( args, long int ), 16, 0, width, pad, 'A'); continue; } if( *format == 'u' ) { pc += printi (va_arg( args, long int ), 10, 0, width, pad, 'a'); continue; } if( *format == 'c' ) { // char are converted to int then pushed on the stack scr[0] = (char)va_arg( args, int ); scr[1] = '\0'; pc += prints (scr, width, pad); continue; } } else { out: putChar(*format); ++pc; } } va_end( args ); return pc; } /* Test printf() below */ main { char *ptr = "Hello world!"; char *np = 0; long int i = 5; int bs = sizeof(long int)*8; // Bit to shift long int mi = ((long int)1 << (bs-1)) + 1; // Maximum negative number printf("%s\n", ptr); printf("printf test\n"); printf("%s is null pointer\n", np); printf("%d = 5\n", (long int)i); printf("%d = - max int\n", mi); printf("Long int 123456789 print out is %u", (long int)123456789); printf("\nmi in hex is %x\n", (long int)mi); printf("bs in dec is %u\n", (long int)bs); printf("char %c = 'a'\n", 'a'); printf("hex %x = ff\n", (long int)0xff); printf("hex %02x = 00\n", (long int)0); printf("signed %d = unsigned %u = hex %x\n", (long int)-32767, (long int)-32767, (long int)-32767); printf("signed %d = unsigned %u = hex %x\n", (long int)-3, (long int)-3, (long int)-3); printf("%d %s(s)%", (long int)0, "message"); printf("\n"); printf("%d %s(s) with %%\n", (long int)0, "message"); printf("justif: \"%-10s\"\n", "left"); printf("justif: \"%10s\"\n", "right"); printf(" 3: %04d zero padded\n", (long int)3); printf(" 3: %-4d left justif.\n", (long int)3); printf(" 3: %4d right justif.\n", (long int)3); printf("-3: %04d zero padded\n", (long int)-3); printf("-3: %-4d left justif.\n", (long int)-3); printf("-3: %4d right justif.\n\n\n", (long int)-3); } Result: Hello world! printf test (null) is null pointer 5 = 5 -2147483647 = - max int Long int 123456789 print out is 123456789 mi in hex is 80000001 bs in dec is 32 char a = 'a' hex ff = ff hex 00 = 00 signed -32767 = unsigned 4294934529 = hex ffff8001 signed -3 = unsigned 4294967293 = hex fffffffd 0 message(s) 0 message(s) with % justif: "left " justif: " right" 3: 0003 zero padded 3: 3 left justif. 3: 3 right justif. -3: -003 zero padded -3: -3 left justif. -3: -3 right justif.
     
    To use this code, modify the Putchar() function so that it points to your UART.
    To verify it works, run the sample main() routine and compare the output to what is posted here.
     
    @Bin, wherever you are, Thank you!
  22. Like
    zeke reacted to bluehash in Switches: Polled or Interrupts?   
    Just found an application note by TI : Implementing An Ultralow-Power Keypad Interface with MSP430
  23. Like
    zeke reacted to Mac in Switches: Polled or Interrupts?   
    No! It's not 'overkill'. That's one of a few excellent ways to do it...
     
    Take care & cheerful regards...
  24. Like
    zeke got a reaction from bluehash in Freebyte's Guide to... Free C++ (and C) Programming Tools   
    My friend sent me this link today and I thought it was good enough to share with you all.
     
    Freebyte's Guide to... Free C++ (and C) Programming Tools
     
    It might be useful if people start developing software on their PC's to talk with the MSP430's over serial or usb links.
  25. Like
    zeke reacted to bluehash in Does anyone have this book?   
    Yes, It's MSP430 Microcontroller Basics.
×
×
  • Create New...