Skip to content

Instantly share code, notes, and snippets.

@astro-gokart
Created July 23, 2015 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astro-gokart/dce064f20c59b970de36 to your computer and use it in GitHub Desktop.
Save astro-gokart/dce064f20c59b970de36 to your computer and use it in GitHub Desktop.
#include "msp430fg4618.h"
#include "stdio.h"
void Init_UART(void);
void OUTA_UART(unsigned char A);
unsigned char INCHAR_UART(void);
void Init_LCD(void);
unsigned char *LCDSeg = (unsigned char *) &LCDM3;
unsigned char LCDSegments[17] = {0x5F,0x06,0x6B,0x2F,0x36,0x3D,0x7D,0x07,0x7F,0x37,0x77,0x7C,0x59,0x6E,0x79,0x71,0x20};
const int LCD_SIZE = 11;
const short TRUE = 1;
const short FALSE = 1;
int main(void){
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P2DIR |= 0x02; // Set P1.0 to output direction
Init_LCD();
Init_UART();
while (TRUE){
unsigned char lhs_firstVal = INCHAR_UART();
OUTA_UART(lhs_firstVal);
unsigned char rhs_firstVal = INCHAR_UART();
OUTA_UART(rhs_firstVal);
OUTA_UART(0x0D);
OUTA_UART(0x0A);
unsigned char lhs_secVal = INCHAR_UART();
OUTA_UART(lhs_secVal);
unsigned char rhs_secVal = INCHAR_UART();
OUTA_UART(rhs_secVal);
OUTA_UART(0x0D);
OUTA_UART(0x0A);
unsigned char modifier = INCHAR_UART();
OUTA_UART(modifier);
OUTA_UART(0x0D);
OUTA_UART(0x0A);
}
}
//---------------------------------------------------------------------
// Initialize the LCD system
//---------------------------------------------------------------------
void Init_LCD(void){
int n;
for (n=0;n<LCD_SIZE;n++){
*(LCDSeg+n) = 0;
}
P5SEL = 0x1C; // BIT4 | BIT3 |BIT2 = 1 P5.4, P.3, P5.2 = 1
LCDAVCTL0 = 0x00;
LCDAPCTL0 = 0x7E;
LCDACTL = 0x7d;
LCDSeg[0] = LCDSegments[0];
LCDSeg[1] = LCDSegments[0];
LCDSeg[2] = LCDSegments[0];
LCDSeg[3] = LCDSegments[0];
}
//---------------------------------------------------------------------
// Initialize the UART system
//---------------------------------------------------------------------
void OUTA_UART(unsigned char A){
do{
}while ((IFG2&0x02)==0);
UCA0TXBUF =A;
}
unsigned char INCHAR_UART(void){
do{
}while ((IFG2&0x01)==0);
return (UCA0RXBUF);
}
void Init_UART(void){
P2SEL=0x30; // transmit and receive to port 2 b its 4 and 5
UCA0CTL0=0; // 8 data, no parity 1 stop, uart, async
UCA0CTL1= 0x41;
UCA0BR1=0; // upper byte of divider clock word
UCA0BR0=3; // clock divide from a clock to bit clock 32768/9600
UCA0MCTL=0x06;
UCA0STAT=0; // do not loop the transmitter back to the
UCA0CTL1=0x40;
IE2=0; // turn transmit interrupts off
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment