#include<mc9S12dp256.h>
#include<stdio.h>

void main(void)
{

   int t;
   long int time;
   
   init_pwm();
   
   while(1)
   {
      t++;
	  if (t>15)
	     t=0;
      		 
      ob_led(t);
	  for (time=0; time<50000; time++);
	  
   }
}


// Display value passed to function on on board 7-seg LED of MiniDragon Board
void ob_led(int t)               
{

  int out[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
    0x39,0x5e,0x79,0x71};
  
  DDRH=0xff;
  
  PTH=out[t];

  
}

void init_pwm()
{
  PWMTST = 0x00; 		   			  // turn off all PWM special Modes
  PWMCTL = 0x00;					  // PWM left aligned output mode 
  
  PWMSCLA = 0x7;					  // Clock SA = Clock A /(2 * 7)
  
  
  PWMPRCLK = 0x77;					  // E/128 for A and B	   
  
  PWMCLK = 0x03;					  // PW Chan 0, 1, clock SA
  		   							  // PW chan 4, 5 clock A 
  		  							  // PW chan 2, 3, 6, 7 clock B
									  
  PWMPOL= 0xff;					  	  // High Polarity for all channels
  DDRP= 0xff;						  // Set Port P to output 
  PWME= 0x0ff;						  // Enable ALL PWM Channels

  PWMPER0 = 255;
  PWMDTY0 = 171;
  
  PWMPER1 = 255;
  PWMDTY1 = 171;
}
 
