Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Creating Library in MSP430 IAR Workbench

Status
Not open for further replies.

orhanli1

Junior Member level 1
Joined
Apr 18, 2011
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,531
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.

Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// 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
    }
}


Thanks.

Best regards.
 

Hi

You don't need to create a library - just place the code in a separate C and H files - the code will be accessed via the function prototype in the H file

All the best

Bobi
 

Hello!

You want a step by step guide? Here it is. Let's do a test program that uses
a function defined in another file.
1. Open IAR, create a new workspace in a new folder. Create a new project.
2. Write a main program (call it main.c or whatever), save it and add it to the project.
(to add a file, right click in the project manager pane, and select add->file).

3. Write a LCDUtils.h file. For instance like this:

Code C - [expand]
1
2
3
4
5
6
#ifndef _LCD_UTILS_H_
#define _LCD_UTILS_H_
 
void WriteValue(uint8 value);
 
#endif


4. Write the .c file corresponding to your LCDUtils.h

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "MSP......h" // This one is for the processor you are using.
// You might include other files if necessary.
#include "LCDUtils.h"
 
//  Place your definitions in the .c, not in the .h except if you want them to be known
//  outside. But the purpose of this file is to provide an easy way to use the LCD, therefore
//  in the .h file, you probably want only the function prototypes.
//------- This was in your code -------
// 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
//------- etc... write also your other definitions.  -------
 
void WriteValue(uint8 value) {
    // Your implementaton goes here.
}



Add the above 2 files to the project.
Note that you don't HAVE TO add the .h to the project, but it is easier to have
all the involved files listed in the project manager. So my advice is that you
should add it.

5. Now in your main program:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "LCDUtils.h"
 
main() {
    uint8 value = 0;
    // Disable watch dog timer (I don't remember the exact syntax).
    // Now the LCD check loop. I assume you will use a single 7-segment digit
    while(1) {
         WriteValue(value);
         value++;
         value %= 10;
         delay();
    }
}
 
void delay(void) {
    uint8 i;
    // Write some kind of loop that just consumes clock cycles
    for(i = 0 ; i < 100 ; ++i) {
        __delay_cycles(50000); // Specific to IAR, I think. Check the real function name, I'm not sure. Maybe __delay_clocks...
    }
}



That's about it.
Note that I assumed all the files will be in the same folder, which is not necessarily the case.
If the files are in different folder, you have to add paths in the project properties.

Dora.
 

Thanks Dora i use this way and i solved my problem.
Thanks for your helps...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top