/*
Matt Hobson
Spring 2006
ELEN 599
Filename: Port_Init.c
Purpose: Initializes the general purpose I/O Ports used with the robot:
           - Port M = motor direction and brake for all motors
		              0 = Direction for Left Drive motors
					  1 = Direction for Right Drive motors
					  2 = Direction for Elbow motor
					  3 = Direction for Elevator motor
					  4 = Direction for Gripper motor
					  5 = Brake for Left/Right Drive motors(brakes both together)
					  6 = Brake for Elbow motor
					  7 = Brake for Elevator/Gripper motors(brakes both together)

***NOTE: To brake motor, PWM line must equal "1"

		   - Port A = Inputs from line-tracking system
		              0 = Far right sensor input 
					  1 = Right sensor input
					  2 = Middle sensor input
					  3 = Left sensor input
					  4 = Far left sensor input
					  5 = free
					  6 = free
					  7 = free
		   - Port H = MCU board 7-segment display
		              0 = Segment a
					  1 = Segment b
					  2 = Segment c
					  3 = Segment d
					  4 = Segment e
					  5 = Segment f
					  6 = Segment g
					  7 = free
		   - Port K = Pushbutton, optical slot sensors, barcode power switch
		              0 = Pushbutton (main start button)
					  1 = Slot sensor (originally for elevator top position)
					  2 = Barcode scanner power switch (switching transistor)
					  3 = Blue LED
					  4 = free
					  5 = free
	
********************************** INCLUDE ************************************/

#include <mc9s12dp256.h>
#include <stdio.h>

//******************************** DEFINES *************************************

#define brake_all_motors 0xE0  //See pin description above

//*************************** PORT_INIT FUNCTION *******************************

void Port_Init (void)
{
   DDRM = 0xFF;  //Port M as Outputs - motor direction and brake control lines
   PTM = 0xFF;   //Brake all motor drivers
   DDRA = 0x00;  //Port A as Inputs - line-tracking system
   DDRH = 0xFF;  //Port H as outputs (7-segment display on MiniDragon+)
   PTH = 0x00;   //Blank the display
   DDRK = 0x0C;  //Port K as inputs - various sensors, output for BC switch
   PORTK = 0x04; //Turn off barcode scanner (active-low signal to turn on)
}

//******************************************************************************
