You are here: Home DOCUMENTATION Adapt9S12D CodeWarrior Function Library for EVALH1

Technological Arts Inc.

Your Shopping Cart

Your Cart is currently empty.

CodeWarrior Function Library for EVALH1

An Object Code Function Library for CodeWarrior has been created for use with the Adapt9S12DG128+EVALH1 hardware combination.  Once you have added the library to your CW project, you can call the functions from your program.  The library is freely downloadable from http://support.technologicalarts.ca/docs/ApplicationBoards/EVALH1/Code/Adapt9S12DG128/CWFunctionLibrary/.  The source code is retained by the author, David Elmo Ross, and is not included in this free distribution.  Below is a list of the available functions.  These functions are provided "as-is" and free of charge.  If you do not find them useful for your purposes, then don't use them.

/*
This function will return the POT value
*/
volatile unsigned char pot_read(void);

/*
This function will return the TEMP sensor value
*/
volatile unsigned char temp_read(void);

/*
This function will return the LIGHT sensor value
*/
volatile unsigned char light_read(void);

/*
This function initializes the switches
*/
void switch_init(void);

/*
This function initializes the leds
*/
void led_init(void);

/*
This function will return the current value of the
switches as an unsigned char.
*/
volatile unsigned char switch_read(void);

/*
This function will send a value to the bargraph leds
*/
void led_write(volatile unsigned char led_value);

/*
This function sends the  LCD command codes to initialize  it to have:
4 bit interface, CURSOR OFF, BLINK OFF, INCREMENT with NO SHIFT
and DISPLAY ON.    */
void lcd_init(void);

/*
This function initializes the PWM channels as follows:

  • set polarity to high at beginning
  • CLOCK B for PWM2 CLOCK A for PWM1,PWM0
  • BUS Clk/8 for both clocks
  • LEFT ALIGN PWM2-0.
  • All act as seperate channels
  • set period for all 3 PWM's 0% duty cycle for all 3
  • enable PWM2-0
*/
void pwm_init(void);

/*
This function assumes that you have invoked pll_on() to turn on the PHASE LOCK LOOP. This then guarantees that the CLOCK frequency used for TIMING will be a constant 24MHz both when the SERIAL MONITOR is active as well as when in STAND ALONE mode.
*/
void delay_milli(volatile unsigned long milli);

/*
This code is used to set E HIGH then LOW with RS held LOW for processing LCD instructions. Other LCD functions such as lcd_print(), use this function so you don't need to.
*/                     
void code_toggle(void);

/*
This code is used to set E HIGH then LOW with RS held HIGH for processing LCD characters. Other LCD functions such as lcd_setcursor(), use this function so you don't need to.
*/
void char_toggle(void);

/*
This function will clear the LCD and put the cursor in the HOME position - top left corner.
*/
void lcd_clear(void);

/*
This function positions the cursor in the top left position without clearing the LCD screen.
*/
void lcd_home(void);

/*
This code positions the cursor to a given ROW, COLUMN. The ROWS are 0-3 for a 4 line display, and COLUMNS are 0-15 for a 16 character display and 0-19 for a 20 character display. If the ROW value is out of range it will position the cursor on ROW 1. If the COL value is out of range it will position the cursor on column 0.

ROW 0, COL 0
--------------------------------------
|                                              |
|                                              |
|                                              |
|                                              |
--------------------------------------  ROW 3, COL 15 or 19

Before you start using the LCD you should set the following GLOBAL LCD VARIABLES:

LCD_COLS =16;            // set number of LCD columns to 16 / 20
LCD_ROWS= 4;            // set number of LCD rows to 1,2, or 4

*/
void lcd_setcursor(unsigned char row,unsigned char col);

/*
This function will enable you to send text to the LCD sreen.

example:
lcd_print("Hello World!");
*/
void lcd_print(signed char input[20]);

/*
This function will turn on the LCD CURSOR as an UNDERLINE at current LCD cursor location.
*/
void lcd_cursor(void);

/*
This function will make the LCD cursor invisible
*/
void lcd_nocursor(void);

/*
This function will make the LCD cursor BLINK.
*/
void lcd_blink(void);

/*
This function will turn OFF cursor BLINKING.
*/
void lcd_noblink(void);

/*
This function will turn ON the display of the LCD. The display can be updated with the display OFF, but will only be visible when the display is turned back ON.
*/
void lcd_display(void);

/*
This will turn the LCD display OFF. Anything that was displayed on the LCD will still be there when the display is turned back ON.
*/
void lcd_nodisplay(void);

/*
Description: This subroutine will waste a given number of Microseconds. The frequency of the timer is 24Mhz/8 = 3Mhz. This means that 1/3 Microsecond per count, therefore num_per_micro=3 Timer Counts to give one microsecond. Since the maximum number of timer counts is 65535, the maximum number of microseconds that can be wasted is 65535/3=  21,845 using this function.
*/
void delay_micro(volatile unsigned int microseconds);

/*
This function will turn on the Phase Lock Loop. This will take the 8 MHz, clock frequency and boost it to 24MHz. When you use the SERIAL monitor to download your code, the SERIAL monitor turns on the PLL and your code runs at 24 MHz. However, when you run it stand alone the PLL is off and your code will run at 8 MHz unless you turn on the PLL. You should always start your code with:
pll_on();       // make clock 24MHz
timer_init();       // set TIMER for delay() and delay_micro()
*/
void pll_on(void);

/*
This function will initialize the timer so that delay_milli() and delay_micro() will work properly.
*/
void timer_init(void);

/*
This code is for the speaker to work properly
*/
void speaker_init(void);

/*
This function sets SCI1 for ZIGBEE to send and receive at 9600 baud.
*/
void zigbee_init(void);

/*
This function initializes the A2D converter:
set to NORMAL ATD mode - no power down
4 conversion sequences
8 bit conv with 4 a/d clock periods
24 MHz divided by 12
Right justified, unsigned, continuous conversion several channels
enable all 8 A/D
*/
void a2d_init(void);

/*
This function will take a two digit hex value, and display it on the LCD screen. It does this by converting each of the hex digits to its ASCII equivalent value
example:
.  char abc=0x4A;
lcd_write(abc);     // sends 4A to LCD
*/
void lcd_write(volatile unsigned char data);


/*
Sends a single ASCII character to the LCD

examples:
lcd_writech(0xdf);   // sends degree symbol to LCD
lcd_writech('C');    // sends character C to LCD
*/
void lcd_writech(volatile unsigned char character);

/*
initializes PLL,Timer,Switches,Leds,LCD, and PWM interface registers
*/
void devices_init(void);

/*
This is the IRQ interrupt that is used to get keypresses from the KEYPAD. It requires that you have GLOBAL variable keyinput declared (see GLOBAL VARIABLES section below). This Interrupt service routine will put the 4 digit hex value representing one of the possible 16 keys into variable "keyinput" and set the MSB to 1 to indicate that there has been a keypress. The main() code must get the value from variable "keyinput" then set this variable back to 0x00.
keypress=keyinput;        // check to see if key press
if((keypress & 0x80)==0x80)      // if msb=1 then key press
.  .  .            // process keypress
keyinput=0x00;        // reset keyinput to 00

*/
__interrupt 6 void irq(void);

/*
Takes the keypad value (MSB=1), strips off the MSB and then returns the equivalent ASCII character representing the character entered.

For the default keypad layout:

1  2   3   A
4  5   6   B
7  8   9   C
*  0   #   D

the following is the code required. For other keypads, simply change the text in the string to the one for your keypad.

char keypad(void) {
char input;
volatile unsigned  char keys[]={  // these are the keys on the keypad
"147*2580369#ABCD"          // as ascii characters
};

input=keyinput&0x7f;        // strip off msb (indicates a keypress)
return(keys[input]);    
// return equivalent ascii char of keypress
}

*/
char keypad(void);

/*
This function takes in the RAW hex value from the TEMPERATURE sensor then it converts it to a temperature in the range of 0-99 celsius. This function was designed based on the data sheets for the temperature transducer on the board.
*/
char temp_conv(volatile unsigned char a2d_temp);

void tone(volatile unsigned long frequency, volatile unsigned short duration);
void no_tone(void);
void alarm(volatile unsigned short second_duration);

// GLOBAL VARIABLES
volatile unsigned char  keyinput;      // used for passing keypress
// from IRQ service routine to main()
volatile unsigned char  LCD_ROWS;       // used to describe the LCD on the board
// valid values are 1,2, or 4
volatile unsigned char  LCD_COLS;       // valid values are 16 or 20