30
Building New Libraries
Building new libraries is simple. All we need to do is to follow a few set of rules:
• For each module, there should be a separate header file and source file.
• Header file should contain definitions, variables, constants and function prototypes only.
• Header files should begin with the inclusion of MSP430 header file.
• Source files should include their respective header files and addition header files (if any).
• Source files should contain actual function codes only.
• Be aware of reserved keywords and constants.
• Global variables with same names should never be declared more than once.
• Empty functions and functions without prototypes must be avoided.
• Functions should have small and meaningful names.
• Be careful about case-senstivity, function type assignment and argument type of functions.
• Hierarchical order of library inclusion must be followed.
delay.h
#include <msp430.h>
#define F_CPU 8
void delay_us(unsigned int value);
void delay_ms(unsigned int value);
delay.c
#include "delay.h"
void delay_us(unsigned int value)
{
register unsigned int loops = ((F_CPU * value) >> 2);
while(loops)
{
_delay_cycles(1);
loops--;
};
}
void delay_ms(unsigned int value)
{
while(value)
{
delay_us(1000);
value--;
};
}