Hi, everybody
I am working with MSP430FG461H Board.I have a code that author John Davies used in his book.I want to use this code in my different projects like
#include <LCDutils.h> or in a different way.
what should i do.i don't know creating library.I am beginner please help me explicitly and step by step.
This is the code:
// LCDutils.c - functions for on SBLCDA4 on TI Experimenter's Board
// J H Davies, 2007-06-03
// IAR Kickstart version 3.42A
//----------------------------------------------------------------------
#include <io430xG46x.h> // Specific device
#include <stdint.h> // Integers of defined sizes
#include "LCDutils.h" // SBLCDA4 utility functions
//----------------------------------------------------------------------
#define LCDDIGITS 7 // Number of digits in display
#define LCDMEMS 11 // LCD memories used (3-13)
// Pointer to LCD memory used: allows use of array LCDMem[]
uint8_t * const LCDMem = (uint8_t *) &LCDM3;
// LCD segment definitions (SoftBaugh SBLCDA4)
#define SEG_A BIT0 // AAAA
#define SEG_B BIT1 // F B
#define SEG_C BIT2 // F B
#define SEG_D BIT3 // GGGG
#define SEG_E BIT6 // E C
#define SEG_F BIT4 // E C
#define SEG_G BIT5 // DDDD
#define SEG_H BIT7 // colon, point etc
// Patterns for hexadecimal characters
const uint8_t LCDHexChar[] = {
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // "0"
SEG_B | SEG_C, // "1"
SEG_A | SEG_B | SEG_D | SEG_E | SEG_G, // "2"
SEG_A | SEG_B | SEG_C | SEG_D | SEG_G, // "3"
SEG_B | SEG_C | SEG_F | SEG_G, // "4"
SEG_A | SEG_C | SEG_D | SEG_F | SEG_G, // "5"
SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, // "6"
SEG_A | SEG_B | SEG_C, // "7"
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, // "8"
SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, // "9"
SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, // "A"
SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, // "b"
SEG_A | SEG_D | SEG_E | SEG_F, // "C"
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // "d"
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, // "E"
SEG_A | SEG_E | SEG_F | SEG_G, // "F"
};
// More useful patterns
const uint8_t LCDhexChar = SEG_C | SEG_E | SEG_F | SEG_G;
const uint8_t LCDAMChar = SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G;
const uint8_t LCDPMChar = SEG_A | SEG_B | SEG_E | SEG_F | SEG_G;
const uint8_t LCDMinusChar = SEG_G;
const uint8_t LCDEChar = SEG_A | SEG_D | SEG_E | SEG_F | SEG_G;
const uint8_t LCDHChar = SEG_B | SEG_C | SEG_E | SEG_F | SEG_G;
const uint8_t LCDhChar = SEG_C | SEG_E | SEG_F | SEG_G;
const uint8_t LCDLChar = SEG_D | SEG_E | SEG_F;
const uint8_t LCDOChar = SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F;
const uint8_t LCDoChar = SEG_C | SEG_D | SEG_E | SEG_G;
const uint8_t LCDrChar = SEG_E | SEG_G;
const uint8_t LCDBlankChar = 0;
// Segments of "digit 10", half-digit on right plus special symbols
#define ONESEG BIT3 // '1' (only one logical segment)
#define DOLLARSEG BIT4 // '$'
#define ERRORSEG BIT5 // 'E' marker
#define MINUSSEG BIT6 // '-' marker
#define MEMSEG BIT7 // 'M' marker
//----------------------------------------------------------------------
// Initialize SBLCDA4
//----------------------------------------------------------------------
void LCDInit (void)
{
int i;
for(i = 0; i < LCDMEMS; ++i) { // Clear LCD memory used
LCDMem[i] = 0;
}
P5SEL = BIT4|BIT3|BIT2; // Select COM[3:1] function
LCDAPCTL0 = LCDS4|LCDS8|LCDS12|LCDS16|LCDS20|LCDS24;
// Enable LCD segs 4-27 (4-25 used)
LCDAVCTL0 = 0; // No charge pump, everything internal
LCDACTL = LCDFREQ_128 | LCD4MUX | LCDSON | LCDON;
// ACLK/128, 4mux, segments on, LCD_A on
}
//----------------------------------------------------------------------
// Display word in hexadecimal, 4 digits followed by 'h' (or 'H')
//----------------------------------------------------------------------
#define LCDDIGITS 7 // Number of digits in display
void DisplayHex (uint16_t HexValue)
{
uint8_t i; // Index for LCD array
LCDMem[0] = LCDhChar; // 'h' for hexadecimal on right
for (i = 1; i <= 4; ++i) { // Display 4 hex digits
LCDMem[i] = LCDHexChar[HexValue & 0x000F];
HexValue >>= 4; // Move next nibble into position
}
while (i < LCDDIGITS) { // Clear more significant digits
LCDMem[i++] = LCDBlankChar; // of numerical display
}
}
//----------------------------------------------------------------------
// Display unsigned, 16-bit integer (uint16_t)
// Convert to BCD and display
// Leading zeros suppressed; BCD value does not exceed 5 digits
//----------------------------------------------------------------------
void DisplayUint (uint16_t UintValue)
{
uint8_t i; // Index for LCD array
uint32_t BCDValue; // Value converted bin to BCD
BCDValue = UintToBCD (UintValue); // Convert binary to BCD
i = 0; // Index for LCD memories
do { // Store pattern for next digit
LCDMem[i++] = LCDHexChar[BCDValue & 0x000F];
BCDValue >>= 4; // Move next nibble down
} while (BCDValue > 0); // (Always display first digit)
while (i < LCDDIGITS) { // Clear more significant digits
LCDMem[i++] = LCDBlankChar; // of numerical display
}
}
//----------------------------------------------------------------------
// Display unsigned, 32-bit integer (uint32_t) up to 19,999,999
// Convert to BCD if it fits and display with leading zeros suppressed
//----------------------------------------------------------------------
void DisplayUlint (uint32_t UlintValue)
{
uint8_t i; // Index for LCD array
uint32_t BCDValue; // Value converted bin to BCD
if (UlintValue <= 9999999) {
BCDValue = UlintToBCD (UlintValue); // Convert binary to BCD
i = 0; // Index for LCD memories
do { // Store pattern for next digit
LCDMem[i++] = LCDHexChar[BCDValue & 0x000F];
BCDValue >>= 4; // Move next nibble down
} while (BCDValue > 0); // (Always display first digit)
while (i < LCDDIGITS) { // Clear more significant digits
LCDMem[i++] = LCDBlankChar; // of numerical display
}
LCDMem[10] = LCDBlankChar; // Special segment for "1"
} else if (UlintValue <= 19999999) { // Needs special treatment
BCDValue = UlintToBCD (UlintValue); // Convert binary to BCD
for (i = 0; i < LCDDIGITS; ++i) {
LCDMem[i] = LCDHexChar[BCDValue & 0x000F];
BCDValue >>= 4; // Move next nibble down
}
LCDMem[10] = ONESEG; // Special segment for "1"
} else {
DisplayErr(); // Indicate overflow
LCDMem[10] = LCDBlankChar; // Special segment for "1"
}
}
//----------------------------------------------------------------------
// Display signed, 16-bit integer (int16_t)
// Strip sign, convert unsigned value to BCD and display
// Leading zeros suppressed; BCD value does not exceed 5 digits
//----------------------------------------------------------------------
void DisplayInt (int16_t IntValue)
{
uint8_t i; // Index for LCD array
uint32_t BCDValue; // Value converted bin to BCD
enum {plus, minus} sign;
if (IntValue >= 0) { // Keep track of sign
sign = plus;
} else {
sign = minus;
IntValue = -IntValue; // Conversion needs IntValue>=0
}
BCDValue = UintToBCD (IntValue); // Convert binary to BCD
i = 0; // Index for LCD memories
do { // Store pattern for next digit
LCDMem[i++] = LCDHexChar[BCDValue & 0x000F];
BCDValue >>= 4; // Move next nibble down
} while (BCDValue > 0); // (Always display first digit)
if (sign == minus) {
LCDMem[i++] = LCDMinusChar; // Prepend minus sign
}
while (i < LCDDIGITS) { // Clear more significant digits
LCDMem[i++] = LCDBlankChar; // of numerical display
}
}
//----------------------------------------------------------------------
// Display line of hyphens ----- across LCD to show that it is alive
//----------------------------------------------------------------------
void DisplayLine (void)
{
uint8_t i; // Index for LCD array
for (i = 0; i < LCDDIGITS; ++i) { // Step through digits
LCDMem[i] = LCDMinusChar; // of numerical display
}
}
//----------------------------------------------------------------------
// Display "Error" on LCD
//----------------------------------------------------------------------
void DisplayErr (void)
{
uint8_t i; // Index for LCD array
LCDMem[0] = LCDrChar;
LCDMem[1] = LCDoChar;
LCDMem[2] = LCDrChar;
LCDMem[3] = LCDrChar;
LCDMem[4] = LCDEChar;
for (i = 5; i < LCDDIGITS; ++i) { // Step through digits
LCDMem[i] = LCDBlankChar; // of numerical display
}
}
//----------------------------------------------------------------------
// Display "HELLO" on LCD (need a less clumsy routine?)
//----------------------------------------------------------------------
void DisplayHello (void)
{
uint8_t i; // Index for LCD array
LCDMem[0] = LCDOChar;
LCDMem[1] = LCDLChar;
LCDMem[2] = LCDLChar;
LCDMem[3] = LCDEChar;
LCDMem[4] = LCDHChar;
for (i = 5; i < LCDDIGITS; ++i) { // Step through digits
LCDMem[i] = LCDBlankChar; // of numerical display
}
}