#include "msp430g2553.h"
#define LED1 BIT0 // Define Red Light
char wordArray[10]; // Set character array
int n = 0; // Set integer n
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ; // Set Clock to 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
P1DIR |= LED1; // Setup Resistor
P1OUT &= ~LED1; // Turn Lights off initially
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}
void dotPulse(){
P1OUT ^= LED1; // Toggle Red Light
__delay_cycles(1000000); //Dot
P1OUT ^= LED1; // Toggle Red Light
__delay_cycles(1000000);
}
void dashPulse(){
P1OUT ^= LED1; // Toggle Red Light
__delay_cycles(3000000); //Dash
P1OUT ^= LED1; // Toggle Red Light
__delay_cycles(1000000);
}
void letterA(){
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
}
void letterB(){
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
}
void letterC(){
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
}
void letterD(){
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
}
void letterE(){
dotPulse(); // Call Dot Function
}
void letterF(){
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
}
void letterG(){
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
}
void letterH(){
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
}
void letterI(){
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
}
void letterJ(){
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
}
void letterK(){
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
}
void letterL(){
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
}
void letterM(){
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
}
void letterN(){
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
}
void letterO(){
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
}
void letterP(){
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
}
void letterQ(){
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
}
void letterR(){
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
}
void letterS(){
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
}
void letterT(){
dashPulse(); // Call Dash Function
}
void letterU(){
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
}
void letterV(){
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
}
void letterW(){
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
}
void letterX(){
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
}
void letterY(){
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
}
void letterZ(){
dashPulse(); // Call Dash Function
dashPulse(); // Call Dash Function
dotPulse(); // Call Dot Function
dotPulse(); // Call Dot Function
}
void sendWord(){
IE2 &= ~UCA0RXIE; // Disable USCI_A0 RX interrupt
n=0; // Set n to 0
while (n<10){ // Initiate while loop
if (wordArray[n] == 'a') // Recognizes a input
letterA(); // Call A function
if (wordArray[n] == 'b') // Recognizes b input
letterB(); // Call B function
if (wordArray[n] == 'c') // Recognizes c input
letterC(); // Call C function
if (wordArray[n] == 'd') // Recognizes d input
letterD(); // Call D function
if (wordArray[n] == 'e') // Recognizes e input
letterE(); // Call E function
if (wordArray[n] == 'f') // Recognizes f input
letterF(); // Call F function
if (wordArray[n] == 'g') // Recognizes g input
letterG(); // Call G function
if (wordArray[n] == 'h') // Recognizes h input
letterH(); // Call H function
if (wordArray[n] == 'i') // Recognizes i input
letterI(); // Call I function
if (wordArray[n] == 'j') // Recognizes j input
letterJ(); // Call J function
if (wordArray[n] == 'k') // Recognizes k input
letterK(); // Call K function
if (wordArray[n] == 'l') // Recognizes l input
letterL(); // Call L function
if (wordArray[n] == 'm') // Recognizes m input
letterM(); // Call M function
if (wordArray[n] == 'n') // Recognizes n input
letterN(); // Call N function
if (wordArray[n] == 'o') // Recognizes o input
letterO(); // Call O function
if (wordArray[n] == 'p') // Recognizes p input
letterP(); // Call P function
if (wordArray[n] == 'q') // Recognizes q input
letterQ(); // Call Q function
if (wordArray[n] == 'r') // Recognizes r input
letterR(); // Call R function
if (wordArray[n] == 's') // Recognizes s input
letterS(); // Call S function
if (wordArray[n] == 't') // Recognizes t input
letterT(); // Call T function
if (wordArray[n] == 'u') // Recognizes u input
letterU(); // Call U function
if (wordArray[n] == 'v') // Recognizes v input
letterV(); // Call V function
if (wordArray[n] == 'w') // Recognizes w input
letterW(); // Call W function
if (wordArray[n] == 'x') // Recognizes x input
letterX(); // Call X function
if (wordArray[n] == 'y') // Recognizes y input
letterY(); // Call Y Function
if (wordArray[n] == 'z') // Recognizes z input
letterZ(); // Call Z Function
n++; // Add 1 to n each loop
}
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
wordArray[n] = UCA0RXBUF; // Set Word Array value
n++; // Add 1 to n
if (UCA0RXBUF == ' '){
sendWord(); // Call Send Word Function
wordArray[0] = 0; // Set all Word Array values to 0
wordArray[1] = 0;
wordArray[2] = 0;
wordArray[3] = 0;
wordArray[4] = 0;
wordArray[5] = 0;
wordArray[6] = 0;
wordArray[7] = 0;
wordArray[8] = 0;
wordArray[9] = 0;
n=0; // Set n back to 0
}
}
Comments