Skip to content

Instantly share code, notes, and snippets.

@kizzlebot
Created April 11, 2014 17:13
Show Gist options
  • Save kizzlebot/10485146 to your computer and use it in GitHub Desktop.
Save kizzlebot/10485146 to your computer and use it in GitHub Desktop.
#include "msp430fg4618.h"
#include "stdio.h"
//---------------------------------------------------------------
// CONTAINS C-PROGRAMMING PARTS 2-5
//---------------------------------------------------------------
void Init_UART(void);
void OUTA_UART(unsigned char A);
unsigned char INCHAR_UART(void);
int add(void);
int sub(void);
int mult(void);
unsigned char wow;
void Init_LCD(void);
unsigned char *LCDSeg = (unsigned char *) &LCDM3;
int LCD_SIZE = 11;
int numbers[16] = {0x5f, 0x06, 0x6b, 0x2f, 0x36, 0x3d, 0x7d, 0x07, 0x7f, 0x3f, 0x77,
0x7c, 0x59, 0x6e, 0x79, 0x71};
int main(void){
Init_UART();
Init_LCD();
for(;;){
wow = INCHAR_UART();
if (wow == 0x2B)
add();
else
if (wow == 0x2D)
sub();
else
if (wow == 0x2A)
mult();
}
}
add()
{
volatile unsigned int a;
volatile unsigned int b;
volatile unsigned int c;
volatile unsigned int d;
volatile unsigned int x;
volatile unsigned int y;
volatile unsigned int m;
volatile unsigned int n;
volatile unsigned int s;
volatile unsigned int t;
volatile unsigned int j;
volatile unsigned int k;
volatile unsigned int results;
volatile unsigned int q;
volatile unsigned int w;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// Initialize the UART and LCD
Init_UART();
Init_LCD();
//----------------------------------------------------------------------------------------------------------------------------------------
// First Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
a=INCHAR_UART();
if(a <= 0x39) // if b is a deciaml
{
b = a - 0x30;
}
else
if (a >0x39)
{
b = a - 0x37;
}
OUTA_UART(a); // Output First characeter
a = b*16;
// Second Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
d =INCHAR_UART();
if(d <= 0x39) // if b is a deciaml
{
b = d - 0x30;
}
else
if (d >0x39)
{
b = d - 0x37;
}
OUTA_UART(d); // Output second character
OUTA_UART(0x20); //space
OUTA_UART(0x2b); // + (plus symbol)
OUTA_UART(0x20); //space
d = b; // save value decimal values to d (lower bits)
//----------------------------------------------------------------------------------------------------------------------------------------
// a = m ; d = n ; s = b ; t = c
// Third Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
m=INCHAR_UART();
if(m <= 0x39) // if b is a deciaml
{
b = m - 0x30;
}
else
if (m >0x39)
{
b = m - 0x37;
}
OUTA_UART(m); // Output First characeter
m = b*16;
// fourth Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
n =INCHAR_UART();
if(n <= 0x39) // if b is a deciaml
{
b = n - 0x30;
}
else
if (n >0x39)
{
b = n - 0x37;
}
OUTA_UART(n); // Output second character
OUTA_UART(0x20); //space
n = b;
//----------------------------------------------------------------------------------------------------------------------------------------
//Results in hex 0x0000 = 0x0000+0x0000
j = a + d;
k = m + n;
results = j+k;
// First Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
q =(results & 0xF00)/256;
a =(results & 0x0F0)/16; // AND with 11110000 to get upper bits of input
d =(results & 0x00F); // AND with 00001111 to get lower bits of input
if(a <= 0x09) // if b is a deciaml
{
a = a + 0x30;
}
else // if b is a letter
if(a>=0x0a)
{
a = a + 0x37;
}
if(d <= 0x09) // if c is a deciaml
{
d = d + 0x30;
}
else // if c is a letter
if(d>=0x0a)
{
d = d + 0x37;
}
if(q <= 0x09) // if q is a deciaml
{
q = q + 0x30;
}
else // if q is a letter
if(q>=0x0a)
{
q = q + 0x37;
}
OUTA_UART(0x3D); // equal
OUTA_UART(q);
OUTA_UART(a); // results
OUTA_UART(d);
OUTA_UART(0x0D); // new line
OUTA_UART(0x0A); // line feed
//----------------------------------------------------------------------------------------------------------------------------------------
// Display the values on the LCD screen
// Need to convert Hex values to LCD display values (a to x)
if (a == 0x30)
x = 0x5f;
else
if (a == 0x31)
x = 0x06;
else
if (a == 0x32)
x = 0x6b;
else
if (a == 0x33)
x = 0x2f;
else
if (a == 0x34)
x = 0x36;
else
if (a == 0x35)
x = 0x3d;
else
if (a == 0x36)
x = 0x7d;
else
if (a == 0x37)
x = 0x07;
else
if (a == 0x38)
x = 0x7f;
else
if (a == 0x39)
x = 0x37;
else
if (a == 0x41)
x = 0x77;
else
if (a == 0x42)
x = 0x7c;
else
if (a == 0x43)
x = 0x59;
else
if (a == 0x44)
x = 0x6e;
else
if (a == 0x45)
x = 0x79;
else
if (a == 0x46)
x = 0x71;
// Need to convert Hex values to LCD display values (d to y)
if (d == 0x30)
y = 0x5f;
else
if (d == 0x31)
y = 0x06;
else
if (d == 0x32)
y = 0x6b;
else
if (d == 0x33)
y = 0x2f;
else
if (d == 0x34)
y = 0x36;
else
if (d == 0x35)
y = 0x3d;
else
if (d == 0x36)
y = 0x7d;
else
if (d == 0x37)
y = 0x07;
else
if (d == 0x38)
y = 0x7f;
else
if (d == 0x39)
y = 0x37;
else
if (d == 0x41)
y = 0x77;
else
if (d == 0x42)
y = 0x7c;
else
if (d == 0x43)
y = 0x59;
else
if (d == 0x44)
y = 0x6e;
else
if (d == 0x45)
y = 0x79;
else
if (d == 0x46)
y = 0x71;
// Need to convert Hex values to LCD display values (q to w)
if (q == 0x30)
w = 0x5f;
else
if (q == 0x31)
w = 0x06;
else
if (q == 0x32)
w = 0x6b;
else
if (q == 0x33)
w = 0x2f;
else
if (q == 0x34)
w = 0x36;
else
if (q == 0x35)
w = 0x3d;
else
if (q == 0x36)
w = 0x7d;
else
if (q == 0x37)
w = 0x07;
else
if (q == 0x38)
w = 0x7f;
else
if (q == 0x39)
w = 0x37;
else
if (q == 0x41)
w = 0x77;
else
if (q == 0x42)
w = 0x7c;
else
if (q == 0x43)
w = 0x59;
else
if (q == 0x44)
w = 0x6e;
else
if (q == 0x45)
w = 0x79;
else
if (q == 0x46)
w = 0x71;
LCDSeg[0] = y; // y = d
LCDSeg[1] = x; // x = a
LCDSeg[2] = w; // q = w
}
//--------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------
sub()
{
volatile unsigned int a;
volatile unsigned int b;
volatile unsigned int c;
volatile unsigned int d;
volatile unsigned int x;
volatile unsigned int y;
volatile unsigned int m;
volatile unsigned int n;
volatile unsigned int s;
volatile unsigned int t;
volatile unsigned int j;
volatile unsigned int k;
volatile unsigned int results;
volatile unsigned int q;
volatile unsigned int w;
volatile unsigned int r;
volatile unsigned int neg;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// Initialize the UART and LCD
Init_UART();
Init_LCD();
//----------------------------------------------------------------------------------------------------------------------------------------
// First Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
a=INCHAR_UART();
if(a <= 0x39) // if b is a deciaml
{
b = a - 0x30;
}
else
if (a >0x39)
{
b = a - 0x37;
}
OUTA_UART(a); // Output First characeter
a = b*16;
// Second Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
d =INCHAR_UART();
if(d <= 0x39) // if b is a deciaml
{
b = d - 0x30;
}
else
if (d >0x39)
{
b = d - 0x37;
}
OUTA_UART(d); // Output second character
OUTA_UART(0x20); //space
OUTA_UART(0x2D); // - (subtraction symbol)
OUTA_UART(0x20); //space
d = b; // save value decimal values to d (lower bits)
//----------------------------------------------------------------------------------------------------------------------------------------
// a = m ; d = n ; s = b ; t = c
// Third Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
m=INCHAR_UART();
if(m <= 0x39) // if b is a deciaml
{
b = m - 0x30;
}
else
if (m >0x39)
{
b = m - 0x37;
}
OUTA_UART(m); // Output First characeter
m = b*16;
// fourth Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
n =INCHAR_UART();
if(n <= 0x39) // if b is a deciaml
{
b = n - 0x30;
}
else
if (n >0x39)
{
b = n - 0x37;
}
OUTA_UART(n); // Output second character
OUTA_UART(0x20); //space
n = b;
neg = 0; // Resets the negative sign bit for LCD to 0
//----------------------------------------------------------------------------------------------------------------------------------------
//Results in hex 0x0000 = 0x0000+0x0000
j = a + d;
k = m + n;
if(j<k)
{
m = j;
j = k;
k = m;
neg = 1;
}
results = j-k;
// First Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
r =(results & 0xF000)/4096;
q =(results & 0xF00)/256;
a =(results & 0x0F0)/16; // AND with 11110000 to get upper bits of input
d =(results & 0x00F); // AND with 00001111 to get lower bits of input
if(a <= 0x09) // if b is a deciaml
{
a = a + 0x30;
}
else // if b is a letter
if(a>=0x0a)
{
a = a + 0x37;
}
if(d <= 0x09) // if c is a deciaml
{
d = d + 0x30;
}
else // if c is a letter
if(d>=0x0a)
{
d = d + 0x37;
}
if(q <= 0x09) // if q is a deciaml
{
q = q + 0x30;
}
else // if q is a letter
if(q>=0x0a)
{
q = q + 0x37;
}
if(r <= 0x09) // if q is a deciaml
{
r = r + 0x30;
}
else // if q is a letter
if(r>=0x0a)
{
r = r + 0x37;
}
OUTA_UART(0x3D); // equal
if (neg == 1)
r = 0x2D;
else
r = 0x30;
OUTA_UART(r);
OUTA_UART(q);
OUTA_UART(a); // results
OUTA_UART(d);
OUTA_UART(0x0D); // new line
OUTA_UART(0x0A); // line feed
//----------------------------------------------------------------------------------------------------------------------------------------
// Display the values on the LCD screen
// Need to convert Hex values to LCD display values (a to x)
if (a == 0x30)
x = 0x5f;
else
if (a == 0x31)
x = 0x06;
else
if (a == 0x32)
x = 0x6b;
else
if (a == 0x33)
x = 0x2f;
else
if (a == 0x34)
x = 0x36;
else
if (a == 0x35)
x = 0x3d;
else
if (a == 0x36)
x = 0x7d;
else
if (a == 0x37)
x = 0x07;
else
if (a == 0x38)
x = 0x7f;
else
if (a == 0x39)
x = 0x37;
else
if (a == 0x41)
x = 0x77;
else
if (a == 0x42)
x = 0x7c;
else
if (a == 0x43)
x = 0x59;
else
if (a == 0x44)
x = 0x6e;
else
if (a == 0x45)
x = 0x79;
else
if (a == 0x46)
x = 0x71;
// Need to convert Hex values to LCD display values (d to y)
if (d == 0x30)
y = 0x5f;
else
if (d == 0x31)
y = 0x06;
else
if (d == 0x32)
y = 0x6b;
else
if (d == 0x33)
y = 0x2f;
else
if (d == 0x34)
y = 0x36;
else
if (d == 0x35)
y = 0x3d;
else
if (d == 0x36)
y = 0x7d;
else
if (d == 0x37)
y = 0x07;
else
if (d == 0x38)
y = 0x7f;
else
if (d == 0x39)
y = 0x37;
else
if (d == 0x41)
y = 0x77;
else
if (d == 0x42)
y = 0x7c;
else
if (d == 0x43)
y = 0x59;
else
if (d == 0x44)
y = 0x6e;
else
if (d == 0x45)
y = 0x79;
else
if (d == 0x46)
y = 0x71;
// Need to convert Hex values to LCD display values (q to w)
if (neg == 1)
w = 0x20;
else
w = 0x5f;
LCDSeg[0] = y; // y = d
LCDSeg[1] = x; // x = a
LCDSeg[2] = w; // q = w
}
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
mult()
{
volatile unsigned int a;
volatile unsigned int b;
volatile unsigned int c;
volatile unsigned int d;
volatile unsigned int x;
volatile unsigned int y;
volatile unsigned int m;
volatile unsigned int n;
volatile unsigned int s;
volatile unsigned int t;
volatile unsigned int j;
volatile unsigned int k;
volatile unsigned int results;
volatile unsigned int q;
volatile unsigned int w;
volatile unsigned int r;
volatile unsigned int z;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// Initialize the UART and LCD
Init_UART();
Init_LCD();
//----------------------------------------------------------------------------------------------------------------------------------------
// First Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
a=INCHAR_UART();
if(a <= 0x39) // if b is a deciaml
{
b = a - 0x30;
}
else
if (a >0x39)
{
b = a - 0x37;
}
OUTA_UART(a); // Output First characeter
a = b*16;
// Second Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
d =INCHAR_UART();
if(d <= 0x39) // if b is a deciaml
{
b = d - 0x30;
}
else
if (d >0x39){
b = d - 0x37;
}
OUTA_UART(d); // Output second character
OUTA_UART(0x20); //space
OUTA_UART(0x2A); // * (plus symbol)
OUTA_UART(0x20); //space
d = b; // save value decimal values to d (lower bits)
//----------------------------------------------------------------------------------------------------------------------------------------
// a = m ; d = n ; s = b ; t = c
// Third Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
m=INCHAR_UART();
if(m <= 0x39) // if b is a deciaml
{
b = m - 0x30;
}
else
if (m >0x39)
{
b = m - 0x37;
}
OUTA_UART(m); // Output First characeter
m = b*16;
// fourth Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
n =INCHAR_UART();
if(n <= 0x39) // if b is a deciaml
{
b = n - 0x30;
}
else if (n >0x39){
b = n - 0x37;
}
OUTA_UART(n); // Output second character
OUTA_UART(0x20); //space
n = b;
//----------------------------------------------------------------------------------------------------------------------------------------
//Results in hex 0x0000 = 0x0000+0x0000
j = a + d;
k = m + n;
results = j*k;
// First Hex (Ascii) Input. This also includes the number and letter conversion to hex.
// Hex conversion not shown in output
r =(results & 0xF000)/4096;
q =(results & 0xF00)/256;
a =(results & 0x0F0)/16; // AND with 11110000 to get upper bits of input
d =(results & 0x00F); // AND with 00001111 to get lower bits of input
if(a <= 0x09) // if b is a deciaml
{
a = a + 0x30;
}
else // if b is a letter
if(a>=0x0a)
{
a = a + 0x37;
}
if(d <= 0x09) // if c is a deciaml
{
d = d + 0x30;
}
else // if c is a letter
if(d>=0x0a)
{
d = d + 0x37;
}
if(q <= 0x09) // if q is a deciaml
{
q = q + 0x30;
}
else // if q is a letter
if(q>=0x0a)
{
q = q + 0x37;
}
if(r <= 0x09) // if q is a deciaml
{
r = r + 0x30;
}
else // if q is a letter
if(r>=0x0a)
{
r = r + 0x37;
}
OUTA_UART(0x3D); // equal
OUTA_UART(r);
OUTA_UART(q);
OUTA_UART(a); // results
OUTA_UART(d);
OUTA_UART(0x0D); // new line
OUTA_UART(0x0A); // line feed
//----------------------------------------------------------------------------------------------------------------------------------------
// Display the values on the LCD screen
// Need to convert Hex values to LCD display values (a to x)
if (a == 0x30)
x = 0x5f;
else
if (a == 0x31)
x = 0x06;
else
if (a == 0x32)
x = 0x6b;
else
if (a == 0x33)
x = 0x2f;
else
if (a == 0x34)
x = 0x36;
else
if (a == 0x35)
x = 0x3d;
else
if (a == 0x36)
x = 0x7d;
else
if (a == 0x37)
x = 0x07;
else
if (a == 0x38)
x = 0x7f;
else
if (a == 0x39)
x = 0x37;
else
if (a == 0x41)
x = 0x77;
else
if (a == 0x42)
x = 0x7c;
else
if (a == 0x43)
x = 0x59;
else
if (a == 0x44)
x = 0x6e;
else
if (a == 0x45)
x = 0x79;
else
if (a == 0x46)
x = 0x71;
// Need to convert Hex values to LCD display values (d to y)
if (d == 0x30)
y = 0x5f;
else
if (d == 0x31)
y = 0x06;
else
if (d == 0x32)
y = 0x6b;
else
if (d == 0x33)
y = 0x2f;
else
if (d == 0x34)
y = 0x36;
else
if (d == 0x35)
y = 0x3d;
else
if (d == 0x36)
y = 0x7d;
else
if (d == 0x37)
y = 0x07;
else
if (d == 0x38)
y = 0x7f;
else
if (d == 0x39)
y = 0x37;
else
if (d == 0x41)
y = 0x77;
else
if (d == 0x42)
y = 0x7c;
else
if (d == 0x43)
y = 0x59;
else
if (d == 0x44)
y = 0x6e;
else
if (d == 0x45)
y = 0x79;
else
if (d == 0x46)
y = 0x71;
// Need to convert Hex values to LCD display values (q to w)
if (q == 0x30)
w = 0x5f;
else
if (q == 0x31)
w = 0x06;
else
if (q == 0x32)
w = 0x6b;
else
if (q == 0x33)
w = 0x2f;
else
if (q == 0x34)
w = 0x36;
else
if (q == 0x35)
w = 0x3d;
else
if (q == 0x36)
w = 0x7d;
else
if (q == 0x37)
w = 0x07;
else
if (q == 0x38)
w = 0x7f;
else
if (q == 0x39)
w = 0x37;
else
if (q == 0x41)
w = 0x77;
else
if (q == 0x42)
w = 0x7c;
else
if (q == 0x43)
w = 0x59;
else
if (q == 0x44)
w = 0x6e;
else
if (q == 0x45)
w = 0x79;
else
if (q == 0x46)
w = 0x71;
// Need to convert Hex values to LCD display values (r to z)
if (r == 0x30)
z = 0x5f;
else
if (r == 0x31)
z = 0x06;
else
if (r == 0x32)
z = 0x6b;
else
if (r == 0x33)
z = 0x2f;
else
if (r == 0x34)
z = 0x36;
else
if (r == 0x35)
z = 0x3d;
else
if (r == 0x36)
z = 0x7d;
else
if (r == 0x37)
z = 0x07;
else
if (r == 0x38)
z = 0x7f;
else
if (r == 0x39)
z = 0x37;
else
if (r == 0x41)
z = 0x77;
else
if (r == 0x42)
z = 0x7c;
else
if (r == 0x43)
z = 0x59;
else
if (r == 0x44)
z = 0x6e;
else
if (r == 0x45)
z = 0x79;
else
if (r == 0x46)
z = 0x71;
LCDSeg[0] = y; // y = d
LCDSeg[1] = x; // x = a
LCDSeg[2] = w; // q = w
LCDSeg[3] = z; // q = w
}
void OUTA_UART(unsigned char A)
{
//---------------------------------------------------------------
//***************************************************************
//---------------------------------------------------------------
// IFG2 register (1) = 1 transmit buffer is empty,
// UCA0TXBUF 8 bit transmit buffer
// wait for the transmit buffer to be empty before sending the
// data out
do{
}while ((IFG2&0x02)==0);
// send the data to the transmit buffer
UCA0TXBUF = A;
}
unsigned char INCHAR_UART(void)
{
//---------------------------------------------------------------
//***************************************************************
//---------------------------------------------------------------
// IFG2 register (0) = 1 receive buffer is full,
// UCA0RXBUF 8 bit receive buffer
// wait for the receive buffer is full before getting the data
do{
}while ((IFG2&0x01)==0);
// go get the char from the receive buffer
return (UCA0RXBUF);
}
void Init_UART(void){
//---------------------------------------------------------------
// Initialization code to set up the uart on the experimenter
// board to 8 data,
// 1 stop, no parity, and 9600 baud, polling operation
//---------------------------------------------------------------
P2SEL=0x30; // transmit and receive to port 2 b its 4 and 5
// Bits p2.4 transmit and p2.5 receive
UCA0CTL0=0; // 8 data, no parity 1 stop, uart, async
// (7)=1 (parity), (6)=1 Even, (5)= 0 lsb first,
// (4)= 0 8 data / 1 7 data,
// (3) 0 1 stop 1 / 2 stop, (2-1) -- UART mode,
// (0) 0 = async
UCA0CTL1= 0x41;
// select ALK 32768 and put in
// software reset the UART
// (7-6) 00 UCLK, 01 ACLK (32768 hz), 10 SMCLK,
// 11 SMCLK
// (0) = 1 reset
UCA0BR1=0; // upper byte of divider clock word
UCA0BR0=3; // clock divide from a clock to bit clock 32768/9600
// = 3.413
// UCA0BR1:UCA0BR0 two 8 bit reg to from 16 bit
// clock divider
// for the baud rate
UCA0MCTL=0x06;
// low frequency mode module 3 modulation pater
// used for the bit clock
UCA0STAT=0; // do not loop the transmitter back to the
// receiver for echoing
// (7) = 1 echo back trans to rec
// (6) = 1 framing, (5) = 1 overrun, (4) =1 Parity,
// (3) = 1 break
// (0) = 2 transmitting or receiving data
UCA0CTL1=0x40;
// take UART out of reset
IE2=0; // turn transmit interrupts off
//---------------------------------------------------------------
//***************************************************************
//---------------------------------------------------------------
// IFG2 register (0) = 1 receiver buffer is full,
// UCA0RXIFG
// IFG2 register (1) = 1 transmit buffer is empty,
// UCA0RXIFG
// UCA0RXBUF 8 bit receiver buffer
// UCA0TXBUF 8 bit transmit buffer
}
//---------------------------------------------------------------------
// Initialize the LCD system
//---------------------------------------------------------------------
void Init_LCD(void) {
// Using the LCD A controller for the MSP430fg4618
// the pins of the LCD are memory mapped onto the mp430F4xxx
// memory bus and
// are accessed via LCDSeg[i] array
// See page 260 of Davie's text
// LCD_SIZE-4 only gives the 7 segment displays plus DP, and
// (colons are the same bit setting)
// LCD_SIZE-4 only gives the 7 segment displays plus DP, and
// colons (colons / dp)
// Right most seven segment display is at LCDSeg[0];
// Display format
// AAA
// F B
// X F B
// GGG
// X E C
// E C
// DP DDD
// bit order
// dp, E, G, F, D, C, B, A or
// :, E, G, F, D, C, B, A
int n;
for (n = 0; n < LCD_SIZE; n++) {
// initialize the segment memory to zero to clear the LCD
// writing a zero in the LCD memory location clears turns
// off the LCD segment
// Including all of the special characters
// This way or
*(LCDSeg + n) = 0;
// LCDSeg[n]=0;
}
// Port 5 ports 5.2-5.4 are connected to com1, com2, com3 of LCD and
// com0 is fixed and already assigned
// Need to assign com1 - com3 to port5
P5SEL = 0x1C; // BIT4 | BIT3 |BIT2 = 1 P5.4, P.3, P5.2 = 1
// Used the internal voltage for the LCD bit 4 = 0 (VLCDEXT=0)
// internal bias voltage set to 1/3 of Vcc, charge pump disabled,
// page 26-25 of MSP430x4xx user manual
LCDAVCTL0 = 0x00;
// LCDS28-LCDS0 pins LCDS0 = lsb and LCDS28 = MSB need
// LCDS4 through LCDS24
// from the experimenter board schematic the LCD uses S4-S24,
// S0-S3 are not used here
// Only use up to S24 on the LCD 28-31 not needed.
// Also LCDACTL1 not required since not using S32 - S39
// Davie's book page 260
// page 26-23 of MSP430x4xx user manual
LCDAPCTL0 = 0x7E;
// The LCD uses the ACLK as the master clock as the scan rate for
// the display segments
// The ACLK has been set to 32768 Hz with the external
// 327768 Hz crystal
// Let's use scan frequency of 256 Hz (This is fast enough not
// to see the display flicker)
// or a divisor of 128
// LCDFREQ division(3 bits), LCDMUX (2 bits), LCDSON segments on,
// Not used, LCDON LCD module on
// 011 = freq /128, 11 = 4 mux's needed since the display uses for
// common inputs com0-com3
// need to turn the LCD on LCDON = 1
// LCDSON allows the segments to be blanked good for blinking but
// needs to be on to
// display the LCD segments LCDSON = 1
// Bit pattern required = 0111 1101 = 0x7d
// page 26-22 of MSP430x4xx user manual
LCDACTL = 0x7d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment