Greetings,
Thank you all for the support.
I am trying to get some text displayed on an LCD but I cannot get it to work. I found some code and got rid of everything but the basics but for some reason I cannot get it to work. There is a timer interrupt within the code I'm not 100% sure what it does but i believe it triggers the reloading of the text to the LCD could someone clarify this for me?
Here is the code:
/*
* UART TX demonstration program for MSP430G2231, using
* SparkFun Serial LCD module.
*
* Hook up the RX line on the SparkFun Serial LCD backpack to
* P1.1 (TXD) on the LaunchPad board, power everything appropriately,
* and you're all set to go.
*
* Matthew R. Wilson <mwilson@mattwilson.org>
* http://mattwilson.org/msp430/
* August 16, 2010
*
* The code to deal with serial data transmission in the following
* functions is copied and modified from the sample program that ships
* with the TI MSP430 LaunchPad:
* ConfigureTimerUart()
* Transmit()
* Timer_A()
*
* Release for demonstration and education purposes only, I make no
* promises that this code will even work properly, let alone do anything
* useful.
*/
#include "msp430g2553.h"
// Pins on the MSP430 we're using
#define TXD BIT1 // TXD on P1.1
// Conditions for 9600 Baud SW UART, SMCLK = 1MHz
#define Bitime 13 // 1,000,000 / 8 / 9600 = ~13
// variables for serial communication
unsigned char BitCnt;
unsigned int TXByte;
// function prototypes
void TXString(char *string);
void ConfigureTimerUart(void);
void Transmit();
void brag(void);
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
// Set clock to 1MHz, and SMCLK to 125kHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3); //SMCLK is DCO/8
// Set up the timer to simulate a UART
ConfigureTimerUart();
// wait for LCD display to initialize
__delay_cycles(1000000);
__enable_interrupt();
brag();
// Display the current button count, then go into LPM4. The button
// interrupt handler will turn the CPU back on which will bring us back
// to the beginning of the while() loop.
while(1)
{
brag();
__bis_SR_register(LPM4_bits);
}
}
void brag(void)
{
// Clear LCD
TXByte = 0xFE; Transmit();
TXByte = 0x01; Transmit();
TXString("You pressed the button ");
\
TXString("foo");
TXString(" times");
}
// Transmit a string via serial UART by looping through it and transmitting
// each character one at a time.
void TXString(char *string)
{
while(*string != 0)
{
TXByte = *string; Transmit();
string++;
}
}
// Set up timer for simulated UART. Copied from MSP430 LaunchPad sample code.
void ConfigureTimerUart(void)
{
TACCTL0 = OUT; // TXD Idle as Mark
TACTL = TASSEL_2 + MC_2 + ID_3; // SMCLK/8, continuous mode
P1SEL |= TXD; //
P1DIR |= TXD; //
}
// Function Transmits Character from TXByte
// Copied from MSP430 LaunchPad sample code
void Transmit()
{
BitCnt = 0xA; // Load Bit counter, 8data + ST/SP
while (TACCR0 != TAR) // Prevent async capture
TACCR0 = TAR; // Current state of TA counter
TACCR0 += Bitime; // Some time till first bit
TXByte |= 0x100; // Add mark stop bit to TXByte
TXByte = TXByte << 1; // Add space start bit
TACCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idle
while ( TACCTL0 & CCIE ); // Wait for TX completion
}
// Timer A0 interrupt service routine
// Copied from MSP430 LaunchPad sample code
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
TACCR0 += Bitime; // Add Offset to CCR0
if (TACCTL0 & CCIS0) // TX on CCI0B?
{
if ( BitCnt == 0)
TACCTL0 &= ~ CCIE; // All bits TXed, disable interrupt
else
{
TACCTL0 |= OUTMOD2; // TX Space
if (TXByte & 0x01)
TACCTL0 &= ~ OUTMOD2; // TX Mark
TXByte = TXByte >> 1;
BitCnt --;
}
}
}
Thanks once again for your patience ![]()