Jump to content

GeekDoc

Members
  • Content Count

    1,391
  • Joined

  • Last visited

  • Days Won

    13

Reputation Activity

  1. Like
    GeekDoc reacted to NatureTM in Arduino for the launchpad   
    I've got a couple snippets that are similar to arduino functions. I just assumed this stuff was already out there.
     
    Here's what I have for millis and delayMillis:
     

    #include "msp430g2231.h" #define MCLK_FREQUENCY 1000000 #define WDT_DIVIDER 512 const unsigned long WDT_FREQUENCY = MCLK_FREQUENCY / WDT_DIVIDER; volatile unsigned long wdtCounter = 0; unsigned long millis(){ return wdtCounter / ((float)WDT_FREQUENCY / 1000); } void delayMillis(unsigned long milliseconds){ // todo: handle rollover unsigned long wakeTime = wdtCounter + (milliseconds * WDT_FREQUENCY / 1000); while(wdtCounter < wakeTime); } void main(void){ DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; WDTCTL = WDTPW + WDTTMSEL + WDTIS1; IE1 |= WDTIE; _BIS_SR(GIE); // toggle pin every second P1DIR |= BIT0; while(1){ P1OUT ^= BIT0; delayMillis(1000); } } #pragma vector=WDT_VECTOR __interrupt void watchdog_timer(void){ wdtCounter++; }
     
    And here's what I have for analogRead:
     

    #include "msp430g2231.h" #define ANALOG_PIN 4 unsigned int analogRead(){ ADC10CTL0 |= ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM; } void analogPinSelect(unsigned int pin){ if(pin < 8){ ADC10CTL0 &= ~ENC; ADC10CTL1 = pin << 12; ADC10CTL0 = ADC10ON + ENC + ADC10SHT_0; } } void main(void){ unsigned int analogValue; DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; WDTCTL = WDTPW + WDTHOLD; // read adc repeatedly analogPinSelect(ANALOG_PIN); while(1){ analogValue = analogRead(); } }
  2. Like
    GeekDoc got a reaction from aravind90 in connecting the launchpad with EZ430-RF2500T   
    Well, the first problem is that (in the photo) you have TWO 430's connected to that LaunchPad: The RF2500 module, and the one in the LaunchPad socket! :shock:
  3. Like
    GeekDoc got a reaction from JMLB in powering a wierless router   
    Ahhh, the old Smoke Test. Won't always show a positive result, but you're always positive when you get a negative result.
  4. Like
    GeekDoc reacted to zeke 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!
  5. Like
    GeekDoc reacted to zeke 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!
  6. Like
    GeekDoc reacted to RobG in Saving data to flash on power down   
    Here is a simple solution to the problem I had, saving data when power goes down.
    There are two parts needed, a diode (1N4148) and a capacitor (~47uF.)
    The way it works, you isolate main power from MCU and connect capacitor on the MCU's side.
    One of the pins is connected to the main power and will trigger an interrupt.
    In the interrupt routine, we will be saving data to flash.
    This is a simple proof of concept, the final code should include low voltage detection for situations like dying battery.
     

     


     

    #include "msp430g2231.h" unsigned int data = 0; unsigned int * const savedDataPtr = (unsigned int *)(0x1000); void main(void) { WDTCTL = WDTPW + WDTHOLD; P1DIR &= ~BIT1; P1IE |= BIT1; P1IES |= BIT1; P1IFG &= ~BIT1; P1REN |= BIT1; P1OUT &= ~BIT1; P1DIR |= BIT0; P1OUT |= BIT0; data = *savedDataPtr; if(data == 0xFFFF) data = 100; unsigned int counter = data; _bis_SR_register(GIE); while(1) { counter = data; while(counter > 0) { _delay_cycles(1000); counter--; } P1OUT ^= BIT0; } } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1OUT &= ~BIT0; data += 100; // Save value FCTL2 = FWKEY + FSSEL0 + FN1; FCTL1 = FWKEY + ERASE; FCTL3 = FWKEY; *savedDataPtr = 0; FCTL1 = FWKEY + WRT; *savedDataPtr = data; FCTL1 = FWKEY; FCTL3 = FWKEY + LOCK; P1IFG &= ~BIT1; }
  7. Like
    GeekDoc reacted to gatesphere in Found a site with a lot of EE/CS books, looks legit   
    Hey all
     
    Found a site with a lot of EE/CS books. The links (for the most part) are legit. Might be worth looking into.
     
    http://www.sciencebooksonline.info/engi ... ronic.html
  8. Like
    GeekDoc reacted to Mac in 2x16 HD44780, White on Blue, $3.49 (incl shpg)   
    A chap on another forum bought a few of these displays from the Hong Kong vendor and he says they're pretty nice. I thought it was a pretty good price and so I thought you guys wouldn't mind me passing along the link to the vendor.
     
    Cheerful regards, Mike McLaren, K8LH
     

  9. Like
    GeekDoc reacted to RobG in LaunchPad, ADC, and LCD   
    It's time to play with ADC. I put together 2 examples, single channel and sequence of channels.Both use Vcc as reference.
    In the first example value of ADC10MEM register is displayed and the same value converted to show actual voltage.
    In the second example, 4 inputs are sampled, values are not converted, binary data is displayed (don't get fooled by the period.)


     
    #include "msp430g2231.h" #define sendData(data) send(data, 1) #define sendInstruction(data) send(data, 0) #define initDisplay() sendInstruction(0x3C); sendInstruction(0x0C); clearDisplay(); sendInstruction(0x06) #define clearDisplay() sendInstruction(0x01); _delay_cycles(2000) #define DATAPIN BIT6 #define CLOCKPIN BIT5 #define ENABLEPIN BIT4 const char charMap[10] = { 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39 }; void send(char data, char registerSelect); void sendDataArray(char data[], char length); char charIndex = 0; char bitCounter = 0; char charsToSend[5] = {0,0,0,0,0}; void main(void) { WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; _delay_cycles(100000); P1OUT &= ~(CLOCKPIN + DATAPIN); P1OUT |= ENABLEPIN; P1DIR |= ENABLEPIN + CLOCKPIN + DATAPIN; initDisplay(); ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; ADC10CTL1 = INCH_1; ADC10AE0 |= BIT1; CCTL0 = CCIE; CCR0 = 12500; TACTL = TASSEL_2 + MC_1 + ID_3; _bis_SR_register(LPM0_bits + GIE); } // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { clearDisplay(); charIndex = 0; while(charIndex < 4) { charsToSend[charIndex] = charMap[0]; charIndex++; } unsigned int binary = ADC10MEM; charIndex = 3; while(binary > 0) { charsToSend[charIndex] = charMap[binary % 10]; binary /= 10; charIndex--; } sendDataArray(charsToSend, 4); charIndex = 0; while(charIndex < 5) { charsToSend[charIndex] = charMap[0]; charIndex++; } charsToSend[1] = 0x2E; binary = ADC10MEM * 3.52; charIndex = 4; while(binary > 0) { charsToSend[charIndex] = charMap[binary % 10]; binary /= 10; charIndex--; if(charIndex == 1) charIndex--; } sendInstruction(0xC0); sendDataArray(charsToSend, 5); sendData(0x56); } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { ADC10CTL0 |= ENC + ADC10SC; } void sendDataArray(char data[], char length) { charIndex = 0; while(charIndex < length) { sendData(data[charIndex]); charIndex++; } } void send(char data, char registerSelect) { bitCounter = 0; while(bitCounter < 8) { (data & BIT7) ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN); data <<= 1; P1OUT |= CLOCKPIN; P1OUT &= ~CLOCKPIN; bitCounter++; } registerSelect ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN); P1OUT &= ~ENABLEPIN; P1OUT |= ENABLEPIN; }


    #include "msp430g2231.h" #define sendData(data) send(data, 1) #define sendInstruction(data) send(data, 0) #define initDisplay() sendInstruction(0x3C); sendInstruction(0x0C); clearDisplay(); sendInstruction(0x06) #define clearDisplay() sendInstruction(0x01); _delay_cycles(2000) #define DATAPIN BIT6 #define CLOCKPIN BIT5 #define ENABLEPIN BIT4 const char charMap[10] = { 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39 }; const char addressMap[4] = { 0x80, 0x88, 0xC0, 0xC8 }; void send(char data, char registerSelect); void sendDataArray(char data[], char length); char charIndex = 0; char valueIndex = 0; char bitCounter = 0; char charsToSend[5] = {0,0,0,0,0}; int values[4] = {0,0,0,0}; void main(void) { WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; _delay_cycles(100000); P1OUT &= ~(CLOCKPIN + DATAPIN); P1OUT |= ENABLEPIN; P1DIR |= ENABLEPIN + CLOCKPIN + DATAPIN; initDisplay(); ADC10CTL1 = INCH_3 + CONSEQ_1; ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; ADC10DTC1 = 0x04; ADC10AE0 |= 0x0F; CCTL0 = CCIE; CCR0 = 12500; TACTL = TASSEL_2 + MC_1 + ID_3; _bis_SR_register(LPM0_bits + GIE); } // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { clearDisplay(); while (ADC10CTL1 & BUSY) ; valueIndex = 0; while(valueIndex < 4) { charIndex = 0; while(charIndex < 5) { charsToSend[charIndex] = charMap[0]; charIndex++; } charsToSend[1] = 0x2E; unsigned int binary = values[valueIndex]; charIndex = 4; while(binary > 0) { charsToSend[charIndex] = charMap[binary % 10]; binary /= 10; charIndex--; if(charIndex == 1) charIndex--; } sendInstruction(addressMap[valueIndex]); sendDataArray(charsToSend, 5); valueIndex++; } } // Timer A0 interrupt service routine #pragma vector = TIMERA0_VECTOR __interrupt void Timer_A (void) { ADC10CTL0 &= ~ENC; while (ADC10CTL1 & BUSY) ; ADC10SA = (unsigned int)&values[0]; ADC10CTL0 |= ENC + ADC10SC; } void sendDataArray(char data[], char length) { charIndex = 0; while(charIndex < length) { sendData(data[charIndex]); charIndex++; } } void send(char data, char registerSelect) { bitCounter = 0; while(bitCounter < 8) { (data & BIT7) ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN); data <<= 1; P1OUT |= CLOCKPIN; P1OUT &= ~CLOCKPIN; bitCounter++; } registerSelect ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN); P1OUT &= ~ENABLEPIN; P1OUT |= ENABLEPIN; }
  10. Like
    GeekDoc got a reaction from RobG in Using 3 wires to control parallel LCD display   
    How's this? I just hand routed the traces that would carry the most current, then auto-routed the rest. It's about 1.75 x 0.75; I got kind of lazy in the placement to allow easier routing. Top is for 16-pin header on bottom to attach to LCD (M/F to mate with header on LCD). Other header pulls everything needed out.
     

    LCD-Serial-Backpack.zip
  11. Like
    GeekDoc got a reaction from RobG in Using 3 wires to control parallel LCD display   
    Do it with a 16-pin header row, and you've got a "backpack"! [me-fires up Eagle to try it out]
  12. Like
    GeekDoc reacted to ZeroSkillz in n00b tutorial - AND; OR and NOT   
    I'm a total n00b, and from what I have seen, there are a lot of us here so I figured I'd share what I've been learning and maybe help some others along the way! While running demos and looking at the code that makes them tick you will come across things like this:
     
    P1OUT |= BIT6
    P1OUT &= ~BIT6
     
    And to a n00b this looks like gibberish! Lets break it down and learn! - as taught to me by my mentor & friend Sven (Thanks bub!).
     
    There are three basic functions in play here AND; OR and NOT. Lets start with NOT.
     
    1101 1010 <- binary representation of a byte (8bits)
     
    What NOT does is INVERT the bits:
     
    NOT
    1101 1010
    0010 0101 <- RESULT
     
    What was ON is now OFF (and vice versa)
     
    Now, lets look at OR. While NOT operates on ONE value, OR (as well as AND) operate on TWO values and combines them in a way to create a result. OR sets all the bits that are in either (a) OR (.
     
    1100 0000 (a)
    OR
    0001 0001 (
     
    1101 0001 <- RESULT
     
    Another example:
    1100 001 (a)
    OR
    1101 000 (
     
    1101 001 <- RESULT (same as the first result)
     
    If a bit at a certain position is set to 1 in either the first (a) OR the second ( var, the bit in the result will be set to 1 also.
     
    Now, lets look at AND. The difference between OR and AND is that the bit in the result will be set only if BOTH the first (a) and the second ( var are set.
     
    1100 0001 (a)
    AND
    1000 0100 (
     
    1000 0000 <-RESULT
     
    Only the topmost bit (BIT7) is set in (a) AND (, so only the topmost bit is set in the result.
     
    SO - NOW WHAT!? well, in C we don't write OR, AND and NOT...we use symbols.
     
    & is AND
    | is OR
    ~ is NOT
     
    Lets look at a line of code:
     
    P1OUT =P1OUT &~BIT6
     
    What this line of code does is MASK bit number 6. It takes what is currently in P1OUT then does an AND with EVERYTHING except BIT6 and writes it back to P1OUT. Whatever was written to P1OUT still be there EXCEPT for BIT6, which will be set to zero. We can make this line shorter:
     
    P1OUT &= ~BIT6
     
    On a LaunchPad it turns off the Green LED located at 1.6 - ISN'T THAT GREAT TO KNOW!?
     
    When you want to change a bit in a port, you CANNOT access just that one bit. You can only write a WHOLE byte to memory, which effects all 8 port bits. So, since you do not want to change the other bits you need to read the current state, leaving all the other bits unchanged by using AND with ALL bits except the one you want to clear (BIT6).
     
    Lets say that P1OUT looks like this:
     
    1101 0001
     
    BIT0, BIT4, BIT6 and BIT7 are set (Zero is rightmost Seven is topmost). Now you create your mask by doing a NOT on a single BIT (BIT6). BIT6 Looks like this:
     
    0100 0000
     
    NOT BIT6 (~BIT6) Looks like this:
     
    1011 1111
     
    Now, if you do an AND operation with this MASK all bits will remain unchanged except BIT6 which will always result in zero. You write the result back to the port byte and you have only affected ONE bit (BIT6) while all the others remain the unchanged.
     
    SO - HOW DO I TURN BIT6 ON!?
     
    You just OR the port with the desired bit:
     
    P1OUT |= BIT6
     
    If BIT6 is already set, there is no change. If BIT6 was not set it is now. On a Launchpad the green LED would turn ON or STAY ON.
     
    Just for fun:
     
    P1OUT &= ~(BIT6|BIT0)
     
    This line of code will turn OFF BOTH LED's on a Launchpad.
     
    Happy coding!
    ZeroSkillz
  13. Like
    GeekDoc got a reaction from gatesphere in Nicer code formatting?   
    There's what looks like a nice code formatting mod (a bit old, but should still work) here:
    http://www.phpbb.com/community/viewtopi ... 0&t=564569
     
    Another here:
    http://www.zerozaku.com/viewtopic.php?f=66&t=4972
     
    I'm sure there are more, but I think displaying code as something better than green text would be nice.
  14. Like
    GeekDoc reacted to sucotronic in Playing music   
    I've written a simple program adapted from the rttl example in the Arduino Tone library. It only need a launchpad, a piezo buzzer and a compiler (in my case mspgcc). You take a look in my blog(I don't want to seem spam, only want to share with others my madness .P).
     


     

    /* Buzzer example */ #include #include typedef unsigned char byte; #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978 #define OCTAVE_OFFSET 0 int notes[] = { 0, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7 }; //char *song = "The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6"; //char *song = "Indiana:d=4,o=5,b=250:e,8p,8f,8g,8p,1c6,8p.,d,8p,8e,1f,p.,g,8p,8a,8b,8p,1f6,p,a,8p,8b,2c6,2d6,2e6,e,8p,8f,8g,8p,1c6,p,d6,8p,8e6,1f.6,g,8p,8g,e.6,8p,d6,8p,8g,e.6,8p,d6,8p,8g,f.6,8p,e6,8p,8d6,2c6"; //char *song = "TakeOnMe:d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5"; //char *song = "Entertainer:d=4,o=5,b=140:8d,8d#,8e,c6,8e,c6,8e,2c.6,8c6,8d6,8d#6,8e6,8c6,8d6,e6,8b,d6,2c6,p,8d,8d#,8e,c6,8e,c6,8e,2c.6,8p,8a,8g,8f#,8a,8c6,e6,8d6,8c6,8a,2d6"; //char *song = "Muppets:d=4,o=5,b=250:c6,c6,a,b,8a,b,g,p,c6,c6,a,8b,8a,8p,g.,p,e,e,g,f,8e,f,8c6,8c,8d,e,8e,8e,8p,8e,g,2p,c6,c6,a,b,8a,b,g,p,c6,c6,a,8b,a,g.,p,e,e,g,f,8e,f,8c6,8c,8d,e,8e,d,8d,c"; //char *song = "Xfiles:d=4,o=5,b=125:e,b,a,b,d6,2b.,1p,e,b,a,b,e6,2b.,1p,g6,f#6,e6,d6,e6,2b.,1p,g6,f#6,e6,d6,f#6,2b.,1p,e,b,a,b,d6,2b.,1p,e,b,a,b,e6,2b.,1p,e6,2b."; //char *song = "Looney:d=4,o=5,b=140:32p,c6,8f6,8e6,8d6,8c6,a.,8c6,8f6,8e6,8d6,8d#6,e.6,8e6,8e6,8c6,8d6,8c6,8e6,8c6,8d6,8a,8c6,8g,8a#,8a,8f"; //char *song = "20thCenFox:d=16,o=5,b=140:b,8p,b,b,2b,p,c6,32p,b,32p,c6,32p,b,32p,c6,32p,b,8p,b,b,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,g#,32p,a,32p,b,8p,b,b,2b,4p,8e,8g#,8b,1c#6,8f#,8a,8c#6,1e6,8a,8c#6,8e6,1e6,8b,8g#,8a,2b"; //char *song = "Bond:d=4,o=5,b=80:32p,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d#6,16d#6,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d6,16c#6,16c#7,c.7,16g#6,16f#6,g#.6"; //char *song = "MASH:d=8,o=5,b=140:4a,4g,f#,g,p,f#,p,g,p,f#,p,2e.,p,f#,e,4f#,e,f#,p,e,p,4d.,p,f#,4e,d,e,p,d,p,e,p,d,p,2c#.,p,d,c#,4d,c#,d,p,e,p,4f#,p,a,p,4b,a,b,p,a,p,b,p,2a.,4p,a,b,a,4b,a,b,p,2a.,a,4f#,a,b,p,d6,p,4e.6,d6,b,p,a,p,2b"; //char *song = "StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6"; //char *song = "GoodBad:d=4,o=5,b=56:32p,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,d#,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,c#6,32a#,32d#6,32a#,32d#6,8a#.,16f#.,32f.,32d#.,c#,32a#,32d#6,32a#,32d#6,8a#.,16g#.,d#"; //char *song = "TopGun:d=4,o=4,b=31:32p,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,16f,d#,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,g#"; //char *song = "A-Team:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#"; //char *song = "Flinstones:d=4,o=5,b=40:32p,16f6,16a#,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,d6,16f6,16a#.,16a#6,32g6,16f6,16a#.,32f6,32f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,a#,16a6,16d.6,16a#6,32a6,32a6,32g6,32f#6,32a6,8g6,16g6,16c.6,32a6,32a6,32g6,32g6,32f6,32e6,32g6,8f6,16f6,16a#.,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c.6,32d6,32d#6,32f6,16a#,16c.6,32d6,32d#6,32f6,16a#6,16c7,8a#.6"; //char *song = "Jeopardy:d=4,o=6,b=125:c,f,c,f5,c,f,2c,c,f,c,f,a.,8g,8f,8e,8d,8c#,c,f,c,f5,c,f,2c,f.,8d,c,a#5,a5,g5,f5,p,d#,g#,d#,g#5,d#,g#,2d#,d#,g#,d#,g#,c.7,8a#,8g#,8g,8f,8e,d#,g#,d#,g#5,d#,g#,2d#,g#.,8f,d#,c#,c,p,a#5,p,g#.5,d#,g#"; //char *song = "Gadget:d=16,o=5,b=50:32d#,32f,32f#,32g#,a#,f#,a,f,g#,f#,32d#,32f,32f#,32g#,a#,d#6,4d6,32d#,32f,32f#,32g#,a#,f#,a,f,g#,f#,8d#"; //char *song = "Smurfs:d=32,o=5,b=200:4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8f#,p,8a#,p,4g#,4p,g#,p,a#,p,b,p,c6,p,4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8b,p,8f,p,4f#"; //char *song = "MahnaMahna:d=16,o=6,b=125:c#,c.,b5,8a#.5,8f.,4g#,a#,g.,4d#,8p,c#,c.,b5,8a#.5,8f.,g#.,8a#.,4g,8p,c#,c.,b5,8a#.5,8f.,4g#,f,g.,8d#.,f,g.,8d#.,f,8g,8d#.,f,8g,d#,8c,a#5,8d#.,8d#.,4d#,8d#."; //char *song = "LeisureSuit:d=16,o=6,b=56:f.5,f#.5,g.5,g#5,32a#5,f5,g#.5,a#.5,32f5,g#5,32a#5,g#5,8c#.,a#5,32c#,a5,a#.5,c#.,32a5,a#5,32c#,d#,8e,c#.,f.,f.,f.,f.,f,32e,d#,8d,a#.5,e,32f,e,32f,c#,d#.,c#"; char *song = "MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d"; volatile unsigned int time = 0; #define isdigit(n) (n >= '0' && n <= '9') /** Delay function. **/ delay(unsigned int ms) { volatile unsigned int i,ms2; i = time; ms2 = ms*2; while ((time-i) < ms2) { nop(); } } play(unsigned int hz){ CCR0 = (1000000/hz) -1; CCR1 = (1000000/hz)/2; TACTL = TASSEL_2 + MC_1; } stop(){ TACTL = TASSEL_2 + MC_3; //stop CCR0 = 0; } int main(void) { WDTCTL = WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1; // Set interval mode, set to zero and interval to 0.5 ms IE1 |= WDTIE; // Enable WDT interrupt BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; eint(); P1DIR |= BIT2; // P1.2 to output P1DIR |= BIT1; // P1.1 to output P1OUT |= ~BIT1; P1SEL |= BIT2; // P1.2 to TA0.1 CCTL1 = OUTMOD_7; // CCR1 reset/set byte default_dur = 4; byte default_oct = 6; int bpm = 63; int num; long wholenote; long duration; byte note; byte scale; char *p=song; while(*p != ':') p++; // ignore name p++; // skip ':' // get default duration if(*p == 'd') { p++; p++; // skip "d=" num = 0; while(isdigit(*p)) { num = (num * 10) + (*p++ - '0'); } if(num > 0) default_dur = num; p++; // skip comma } // get default octave if(*p == 'o') { p++; p++; // skip "o=" num = *p++ - '0'; if(num >= 3 && num <=7) default_oct = num; p++; // skip comma } // get BPM if(*p == 'b') { p++; p++; // skip "b=" num = 0; while(isdigit(*p)) { num = (num * 10) + (*p++ - '0'); } bpm = num; p++; // skip colon } // BPM usually expresses the number of quarter notes per minute wholenote = (60 * 1000L / bpm) * 4; // this is the time for whole note (in milliseconds) // now begin note loop while(*p) { // first, get note duration, if available num = 0; while(isdigit(*p)) { num = (num * 10) + (*p++ - '0'); } if(num) duration = wholenote / num; else duration = wholenote / default_dur; // we will need to check if we are a dotted note after // now get the note note = 0; switch(*p) { case 'c': note = 1; break; case 'd': note = 3; break; case 'e': note = 5; break; case 'f': note = 6; break; case 'g': note = 8; break; case 'a': note = 10; break; case 'b': note = 12; break; case 'p': default: note = 0; } p++; // now, get optional '#' sharp if(*p == '#') { note++; p++; } // now, get optional '.' dotted note if(*p == '.') { duration += duration/2; p++; } // now, get scale if(isdigit(*p)) { scale = *p - '0'; p++; } else { scale = default_oct; } scale += OCTAVE_OFFSET; if(*p == ',') p++; // skip comma for next note (or we may be at the end) // now play the note if(note) { play(notes[(scale - 4) * 12 + note]); delay(duration); stop(); } else { delay(duration); } } dint(); _BIS_SR(LPM4_bits); } interrupt(WDT_VECTOR) watchdog_timer (void) //__interrupt void watchdog_timer { time++; }
  15. Like
    GeekDoc got a reaction from bluehash in 20-pin MSP430G2452 Samples Arrive...   
    I saw Mac's post and decided to check the FedEx tracking number TI sent. Surprise! It said "Delivered". I checked my front porch, and there they were!
     

  16. Like
    GeekDoc reacted to RobG in Serial to 7 Segment LED   
    Teaser
     


  17. Like
    GeekDoc reacted to zeke in LCD-I2C For HD44780 LCDs and PCF8574 Expanders   
    It's obvious now.
     
    Change your board preferences back to "prosilver" and the thumbs will show up.
     
    @BlueHash: You should probably remove the choice of "Bl@ck" as a theme option.
     
    We should probably prune these theme questions off of this thread and put them into the non-existent "board issues" forum.
  18. Like
    GeekDoc got a reaction from SugarAddict in Eagle first attempt...   
    I'll have a look at them. Just so you know, you can adjust traces once they autoroute. I ended up doing most of mine by hand because autoroute comes out kind of convoluted sometimes.
     
    Edit: They look fine. There are a few unnecessary vias, and some of the clearances are a bit tight for my taste, but that's what you get with autoroute. Make sure to get a rules file from your manufacturer to run against this design so you can be sure the tolerances are okay. Also, you may want thicker traces on those carrying higher currents; all of the traces in your designs are pretty thin (autoroute strikes again).
     
    BTW: To show your board, you only need send the board (.brd) file; it's self-contained and editable. If you want to allow someone to change the design (components, connections, etc.), include the schematic (.sch) file as well. The two files are all you need for your project; the remainder are mostly backups from changes.
  19. Like
    GeekDoc reacted to cde in Interface 3v MSP430 to 5v Circuits!   
    I know this was mentioned back in the day in the Parallex Sensor thread we had, but I'd figure this is a really useful document (That I just refound and was surprised by) that should be highlighted as this is one of the most common issues.
     
    TI's guide to Interfacing the 3v MSP430 to 5v Circuits.
    Document slaa148
    http://focus.ti.com/lit/an/slaa148/slaa148.pdf
     
    Covers both input and output, and dual direction communication of intervoltage circuits/ics.
     
    A bit dated (Oct 2002) so it doesn't include things like (active or passive) i2c or spi voltage translators but covers most of the useful steps/ideas in a beginner accessible way.
  20. Like
    GeekDoc got a reaction from lpdc in Beginner's question : software PWM + Charlieplexing   
    Yes, I was referring to the original project. It was a game for his daughter, I believe. I have it bookmarked somewhere, but I have hundreds of bookmarks, which makes them less than convenient. :?
     
    The code to use the two extra pins is:

    //select i/o function of pins P2SEL &= ~(BIT6|BIT7); //set them as outputs P2DIR = 0x00 | BIT6 | BIT7;
    Then just treat them as other i/o pins. P2.6 is pin 12 ("XOUT") and P2.7 is pin 13 ("XIN"). Yay! Extra i/o!
  21. Like
    GeekDoc reacted to nobody in Help to optimize   
    Just one quick question:
     
    You turn on optimization in mspgcc?
     
    Tip can be found on this page: http://mspgcc.sourceforge.net/manual/c1509.html
     
    ... And one little hint: Try to change your code. Do not use LONG variables. Use only "natural" type of variables. For MSP430 natural types are INT, UNSIGNED, CHAR. Each non-natural type variable add additional libraries to your code.
  22. Like
    GeekDoc reacted to bluehash in Help to optimize   
    That results in a lot of generated intermediate code.
    Try breaking it up, us an if statement for the comparison.
     
    If you have to multiply x by 2, right shifting by 1 might be faster.
    y= x
  23. Like
    GeekDoc reacted to zeke in Reading the ds18b20 temperature sensor   
    If you find realterm less than adequate then give this program a try.
     
    It looks a little more refined.
     

  24. Like
    GeekDoc reacted to RobG in Beginner's question : software PWM + Charlieplexing   
    Charlieplexing not worth in this case.
    1. You can use 2 crystal pins bringing total number of available pins to 10
    2. You do not need to Charlieplex, just multiplex, with 5 pins you can control 6 LEDs.
    3. Charlieplexing will add complexity since you have to switch outputs to inputs to get hi-z state and cycle through 6 LEDs, with multiplexing, all you do is alternate between 2 sets of 3 LEDs.
  25. Like
    GeekDoc reacted to zeke 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
×
×
  • Create New...