#include <p18f452.h> //We're using the PIC18F452
#include <delays.h>  //We'll need the delays library

void main(void)
{

TRISA = 0x00;	//Initialize these Ports as Outputs
TRISC = 0x00;	//This one too
TRISD = 0x00;	//This one toooo

PORTA = 0x00;	//Initialize PORTA...so the LED is off

/*
The PIC is connected to the Motor Controller via 6 pins

PIN #1
PORTD Bit 0 - Used For Brake
PORTDbits.RC0

PIN#2
PORTD Bit 1 - User For Direction
PORTDbits.RC1

PINS#3-6
PORTC Bit 0 - Used For M1
PORTCbits.RC0
PORTC Bit 1 - Used For M2
PORTCbits.RC1
PORTC Bit 2 - Used For M3
PORTCbits.RC2
PORTCBit 3 - Used For M4
PORTCbits.RC3

*/

PORTCbits.RD0 = 0; //Brake Off
PORTCbits.RD1 = 1; //Direction Forward

	while(1)
	{
	
	Delay10KTCYx(250);
	Delay10KTCYx(250);
	Delay10KTCYx(250);
	Delay10KTCYx(250);	//4 * 0.5 seconds = 2 Second Pause
	PORTA = 0x01;		//Turn LED On
	PORTC = 0b00001111; // 0x0F Full Speed

	Delay10KTCYx(250);
	Delay10KTCYx(250);
	Delay10KTCYx(250);
	Delay10KTCYx(250);	//4 * 0.5 seconds = 2 Second Pause
	PORTA = 0x00;		//Turn LED Off
	PORTC = 0b00001011; //0X0B 3/4 Full Speed

	Delay10KTCYx(250);
	Delay10KTCYx(250);
	Delay10KTCYx(250);
	Delay10KTCYx(250);	//4 * 0.5 seconds = 2 Second Pause
	PORTA = 0x01;		//Turn LED On
	PORTC = 0b00000101;	//0x07 1/2 Full Speed

	Delay10KTCYx(250);
	Delay10KTCYx(250);
	Delay10KTCYx(250);
	Delay10KTCYx(250);	//4 * 0.5 seconds = 2 Second Pause
	PORTA = 0x00;		//Turn LED Off
	PORTC = 0b00000011;	//0x03 1/4 Full Speed

	PORTDbits.RD0 = 1;	//Turn Brake On
	Delay10KTCYx(250);	//Pause 0.5 Seconds
	PORTDbits.RD0 = 0;	//Turn Brake Off

	}



}

