// Example 12b: Servo demo with pot
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg256.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"

#include "main_asm.h" /* interface to the assembly module */

void main(void) {
  int val;
  int width;
  
  PLL_init();		// set system clock frequency to 24 MHz 
  ad0_enable();         		// enable a/d converter 0
  lcd_init();           		// enable lcd
  servo76_init();          	// enable pwm7 for servo
  while(1) {
    val = ad0conv(7);    		// 0 - 1023
    width = (val << 1) + 3477;	// width: 3477 - 5523
    set_lcd_addr(0x40);		// line 2 of lcd display
    write_int_lcd(width);		// display width on lcd
    set_servo76(width);    	// move servo to pos width 
  }
}
