/********************************************************************
* FileName:        debugging.c
* Processor:       PIC18F4520
* Compiler:        MPLAB C18 v.3.06 
*
* This file shows some debugging features of MPLAB
*                                                                     
*
* Author               Date        Comment
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// David Fisher		12/12/07

/** Header Files ****************************************/     
#include <p18f4520.h> 
#include <stdio.h>

/** Define Constants Here ******************************************/
#define SAMPLE 100

/** Local Function Prototypes **************************************/
void sampleFunction(void);

// ============================================================
// Configuration Bits 
// ============================================================
#pragma config OSC = INTIO67
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOREN = OFF
#pragma config XINST = OFF

/** Global Variables *********************************************/
	int sampleVariable;
	int x=1;
	
/*****************************************************************
* Function:        void main(void)
******************************************************************/
#pragma code
void main (void)
{
	ADCON1 = 0x0F;
	TRISA = 0x00;
	TRISB = 0x00;
	TRISC = 0x00;
	TRISD = 0x00;
	TRISEbits.TRISE2 = 0;
	TRISEbits.TRISE1 = 0;
	TRISEbits.TRISE0 = 0;
	
	
	// Part A: Basic Debugging Control
	while(1)
	{
		PORTA = 0xFF;
		PORTB = 0xFF;
		PORTC = 0xFF;
		PORTD = 0xFF;
		PORTEbits.RE2 = 1;
		PORTEbits.RE1 = 1;
		PORTEbits.RE0 = 1;
		
		PORTA = 0x00;
		PORTB = 0x00;
		PORTC = 0x00;
		PORTD = 0x00;
		PORTEbits.RE2 = 0;
		PORTEbits.RE1 = 0;
		PORTEbits.RE0 = 0;
	}
	
	// Part B: Instruction Cycle Stopwatch
//	while(1)
//	{
//		Nop();
//		Nop();
//		Nop();
//		Delay10TCYx(3);
//		Nop();
//		
//		Delay10KTCYx(100);
//		Nop();
//			
//		Nop();
//		printf("C commands can generate MANY assembly instructions \n");
//		Nop();
//	}
	
	// Part C: Stimulus Inputs
//	TRISAbits.TRISA4 = 1;
//	while (1)
//    {
//		if(PORTAbits.RA4 == 0)
//			PORTBbits.RB1 = 1;
//		else
//			PORTBbits.RB1 = 0;
//    }
	
	
	// Part D: Logic Analyzer
//	TRISAbits.TRISA4 = 1;
//	PORTB=0;
//  	while (1)
//    {
//		switch (x)
//		{
//			case 0:
//				PORTB = 0;
//				break;
//			case 1:
//				PORTBbits.RB2 = 0;
//				PORTBbits.RB1 = 0;
//				PORTBbits.RB0 = 1;
//				break;
//			case 2:
//				PORTB = 0x02;
//				break;			
//			case 3:
//				PORTB = 0b0011;
//				break;		
//			case 4:
//				PORTB = 4;
//				break;		
//			default:
//				PORTB = 0;
//				x=0;
//				break;
//		}
//		Nop();
//		Nop();
//		Nop();
//		Nop();
//		x++;
//	}

}

/*****************************************************************
* Additional Helper functions
******************************************************************/

/*****************************************************************
* Function:			void sample(void)
* Input Variables:	
* Output return:	
* Overview:			You change this template of a function if needed
******************************************************************/
void sampleFunction(){
	// Some function that does a specific task
}