Пример #1
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{	
	unsigned short int analogval;
	unsigned char *analoghi, *analoglow;
	float VREF = 3; //Voltage reference
	float result; // ADC voltage result
	short int result_high = 0;
	short int result_low = 4095;
	char samples = 0;
	short int accum[16] = {0}; // Still compute the average
	char i;
	unsigned long int sum = 0;
	unsigned int avg;
	float result_dec1; // Need 2 variables to hold the decimal value to prevent overflow
	float result_dec2;
	analoglow = (char *) &analogval;
	analoghi = analoglow + 1;

	WDTCN = 0xDE; // Disable the watchdog timer
	WDTCN = 0xAD;
	
	PORT_INIT(); // Initialize the Crossbar and GPIO
	SYSCLK_INIT(); // Initialize the oscillator
	UART0_INIT(); // Initialize UART0
	ADC_INIT(); // Initialize ADC0
	INTERRUPT_INIT();
	DAC_INIT();

	
	
	while(1)
	{
		//dig_val = dig_val + 50; // Generate the sawtooth
		SFRPAGE = ADC0_PAGE;
		AD0INT = 0; // Clear the "conversion done" flag
		AD0BUSY = 1; // Start A/D Conversion
		while (AD0INT == 0); // Wait for the conversion to finish
		*analoglow = ADC0L; // Read the low byte
		*analoghi = ADC0H; // Read the high byte
		
		SFRPAGE = DAC0_PAGE; // Output the digital value through the DAC
		DAC0L = analogval << 0; //digval;
		DAC0H = analogval >> 8; //digval >> 8;
		
		SFRPAGE = UART0_PAGE;
		//result = analogval*2.4/(float)4095;
	
		// Compute the average
		
		//result_dec1 = (1000*result-1000*(int)result);
		//result_dec2 = (1000*(result_dec1-(int)result_dec1));
		// Erase screen and move cursor to home position
		//printf("Voltage reading: %d.%03d%03d\n\r", (int)result, (int)result_dec1, (int)result_dec2);
	}
}
Пример #2
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{
	char high=0;
	char low = 0;
	WDTCN = 0xDE;						// Disable the watchdog timer
	WDTCN = 0xAD;						// Note: = "DEAD"!
	
	SYSCLK_INIT();						// Initialize the oscillator
	PORT_INIT();						// Initialize the Crossbar and GPIO
	UART0_INIT();						// Initialize UART0
	ADC_Init();							// Initialize ADC0
	DAC_Init();

	SFRPAGE = UART0_PAGE;				// Direct output to UART0

	//initialize ADC converter

	//select 00 on AD0CM mux
	ADC0CN &= ~0x0C;
	//clear AD0INT
	AD0INT = 0;
	//AD0BUSY = 1 to start conversion
	AD0BUSY = 1;

	//while AD0INT != 0
	while(AD0INT != 0);


	printf("\033[2J");					//clear screen
	printf("Fire and blood. \n\r");		//running

	while(1)
	{
		//clear AD0INT
		AD0INT = 0;

		//AD0BUSY = 1 to start conversion
		AD0BUSY = 1;

		//while AD0INT != 0
		while(AD0INT == 0);
		AD0BUSY = 0;

		//read A/D conversion value from ADC0H/L

		high = ADC0H;
		low = ADC0L;

		DAC0L = low;
		DAC0H = high;

		//printf("ADCH: %x  ADCL: %x  DACH: %x  DACL: %x\n\r", high, low, DAC0H, DAC0L);
	}

}
Пример #3
0
//FIRST DIES AT 5000 Hz
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{
	char high=0;
	char low = 0;
	WDTCN = 0xDE;						// Disable the watchdog timer
	WDTCN = 0xAD;						// Note: = "DEAD"!
	
	SYSCLK_INIT();						// Initialize the oscillator
	PORT_INIT();						// Initialize the Crossbar and GPIO
	UART0_INIT();						// Initialize UART0
	ADC_Init();							// Initialize ADC0
	DAC_Init();							// Initialize DAC0
	MAC_Init();							// Initialize MAC0

	SFRPAGE = UART0_PAGE;				// Direct output to UART0

	//initialize ADC converter

	//select 00 on AD0CM mux
	ADC0CN &= ~0x0C;
	//clear AD0INT
	AD0INT = 0;
	//AD0BUSY = 1 to start conversion
	AD0BUSY = 1;

	//while AD0INT != 0
	while(AD0INT != 0);


	printf("\033[2J");					//clear screen
	printf("We will not sow. \n\r");		//running

	while(1)
	{
		//printf("Still running. \n\r");
		olderIn = oldIn;
		oldIn = input;
		input = do_ADC();

		oldOut = output;
		output = do_MAC();

		do_DAC();

	//	printf("I: %d  I1: %d  I2: %d  O: %d  O2: %d \n\r", input, oldIn, olderIn, output, oldOut); 
	}

}
Пример #4
0
//-------------------------------------------------------------------------------------------
// MAIN Routine
//-------------------------------------------------------------------------------------------
void main (void)
{
	bit restart = 0;
	unsigned int randnum = 0;
	
	WDTCN = 0xDE;					// Disable the watchdog timer
	WDTCN = 0xAD;					// Note: = "DEAD"!

	SYSCLK_INIT();					// Initialize the oscillator.
	PORT_INIT();					// Configure the Crossbar and GPIO.
	UART0_INIT();					// Initialize UART0.
	INTERRUPT_INIT();				// Initialize Interrupts
	TIMER_INIT();

	SFRPAGE = LEGACY_PAGE;
	IT0		= 1;					// /INT0 is edge triggered, falling-edge.

	SFRPAGE = UART0_PAGE;			// Direct output to UART0
	
	printf("\033[2J");				// Erase screen and move cursor to the home posiiton.
	printf("MPS Interrupt Switch Test\n\n\r");
	printf("Ground /INT0 on P0.2 to generate an interrupt.\n\n\r");
	SFRPAGE = CONFIG_PAGE;

	EX0		= 1;					// Enable Ext Int 0 only after everything is settled.
	SFRPAGE = UART0_PAGE; 
	while (1)
	{
		if (count > 340) {
			count = 0;
			sec_elapsed++;
			printf("Seconds Elapsed: %d\r\n", sec_elapsed);
		} 
		if(pbFlag){
			// If interrupt flag is set to 1
			printf("PB Pressed!\r\n");
			pbFlag = 0;
		}
	}
}
Пример #5
0
//-------------------------------------------------------------------------------------------
// MAIN Routine
//-------------------------------------------------------------------------------------------
void main (void)
{
	bit restart = 0;
	unsigned int randnum = 0;
	
	WDTCN = 0xDE;					// Disable the watchdog timer
	WDTCN = 0xAD;					// Note: = "DEAD"!

	SYSCLK_INIT();					// Initialize the oscillator.
	PORT_INIT();					// Configure the Crossbar and GPIO.
	UART0_INIT();					// Initialize UART0.

	SFRPAGE = LEGACY_PAGE;
	IT0		= 1;					// /INT0 is edge triggered, falling-edge.

	SFRPAGE = CONFIG_PAGE;
	EX0		= 1;					// Enable Ext Int 0 only after everything is settled.

	SFRPAGE = UART0_PAGE;			// Direct output to UART0
	
	printf("\033[2J");				// Erase screen and move cursor to the home posiiton.

	Timer2_Init();					
	TR2 = 1;						//enable timer2

	printf("I am running :D \n\r");

	while (1)
	{ 
		if (printTime)	//if 1  second, print.
		{
			printf("Time = %d\n\r", time);
			printTime = 0;
		}
	}
}
Пример #6
0
//-------------------------------------------------------------------------------------------
// MAIN Routine
//-------------------------------------------------------------------------------------------
void main (void)
{
	bit restart = 0;
	unsigned int randnum = 0;
	
	WDTCN = 0xDE;					// Disable the watchdog timer
	WDTCN = 0xAD;					// Note: = "DEAD"!

	SYSCLK_INIT();					// Initialize the oscillator.
	PORT_INIT();					// Configure the Crossbar and GPIO.
	UART0_INIT();					// Initialize UART0.

	SFRPAGE = LEGACY_PAGE;
	IT0		= 1;					// /INT0 is edge triggered, falling-edge.
	IT1		= 1;					// INT1 falling-edge-triggered

	SFRPAGE = CONFIG_PAGE;
	EX0		= 1;					// Enable Ext Int 0 only after everything is settled.
	EX1 	= 1;					// Enable External Interrupt 2

	SFRPAGE = UART0_PAGE;			// Direct output to UART0
	
	printf("\033[2J");				// Erase screen and move cursor to the home posiiton.

	Timer0_Init();					//enable timer0
	TR0 = 1;

	Timer2_Init();					
	TR2 = 1;						//enable timer2

//	printf("I am running :D \n\r");

	while (1)
		playGame();
	
}
Пример #7
0
//-------------------------------------------------------------------------------------------
// MAIN Routine
//-------------------------------------------------------------------------------------------
void main (void)
{
	__bit restart = 0;
	char character;
	unsigned int delay1, delay2 = 0;
	unsigned int randnum = 0;
	unsigned int ones, tenths = 0;

	unsigned char tenths_seconds = 0;
	unsigned int seconds = 0;
	unsigned int delay;
	unsigned int times[5];
	unsigned int time;
	unsigned char started = 0;
	unsigned int avg;
	char i;
	char grace;

	
	SFRPAGE = CONFIG_PAGE;

	PORT_INIT();				// Configure the Crossbar and GPIO.
	SYSCLK_INIT();				// Initialize the oscillator.
	UART0_INIT();				// Initialize UART0.

	SFRPAGE = LEGACY_PAGE;
	IT0	= 1;					// /INT0 is edge triggered, falling-edge.

	SFRPAGE = CONFIG_PAGE;
	EX0		= 1;				// Enable Ext Int 0 only after everything is settled

	SFRPAGE = UART0_PAGE;		// Direct output to UART0
	
	printf("\033[2J");			// Erase screen and move cursor to the home posiiton.
	printf("MPS Timer Game\n\n\r");
	printf("Press button 8 ASAP on GO.\n\n\r");


	SFRPAGE = UART0_PAGE;

	delay = rand() % 50 + 10;

	while (1)
	{
		if (interrupt_count == 404) { // Count each .1 seconds
			tenths_seconds = tenths_seconds + 1;
			interrupt_count = 0;
			if (tenths_seconds % 10 == 0 && tenths_seconds != 0) {
				tenths_seconds = 0;
				seconds = seconds + 1;
				if(seconds < 1 && !started) // Don't count quick double presses before the start of the next trial
					grace = 1;
				else
					grace = 0;
			}
		}
		
		if(seconds >= delay/10 && tenths_seconds >= delay-delay/10*10 && !started) // Flash GO and restart the timer
		{
			seconds = 0;
			tenths_seconds = 0;

			started = 1;
			printf("\033[16;26HGO");
			printf("\033[5;0H");
		}

		if(press > 0 && !grace) // The user has pressed the button
		{
			printf("\033[16;26H  ");
			delay = rand() % 50 + 10; // Gererate a new random delay between 1 and 5 seconds.
			press = 0; // Reset interrupt variable
			if(started == 1)
			{
				time = seconds*10 + tenths_seconds; // Reaction time for this trial
			}
			else
			{
				time = 50; // False button press (GO not flashed on screen). Penalize 5 seconds
			}
			seconds = 0;
			tenths_seconds = 0;
			started = 0;

			// Shift 5 most recent times
			times[0] = times[1];
			times[1] = times[2];
			times[2] = times[3];
			times[3] = times[4];
			times[4] = time;

			avg = (times[0] + times[1] + times[2] + times[3] + times[4])/5; // Calculate running average of 5
			printf("\033[6;0H"); //Move cursor position
			for (i = 0; i <= 4; i++) {
				printf("Trial %d: %d.%d seconds\r\n", (5-i), times[i]/10, times[i]-times[i]/10*10);
			}
			printf("Avg: %d.%d seconds", avg/10, avg-avg/10*10);
		}

			
	}
}
Пример #8
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{
	char input;
	char SFRPAGE_SAVE = SFRPAGE; 

	WDTCN = 0xDE;						// Disable the watchdog timer
	WDTCN = 0xAD;						// Note: = "DEAD"!
	
	SYSCLK_INIT();						// Initialize the oscillator
	Timer_Init();						// Initialize timer
	UART_INIT();						// Initialize UARTs
	PORT_INIT();						// Initialize the Crossbar and GPIO
	SPI_Init();

	SFRPAGE = UART0_PAGE;				// Direct output to UART0

	printf("\033[2J");					//clear screen
	printf("\033[2J");					//clear screen
	printf("\033[13;0H");				//print divider
	printf("--------------------------------------------------------------------------------");
	//printf("\033[1;12r");				//define scrollable area
	//printf("\033[14;25r");

	while(1)
	{
		if (RI0 == 1)
		{	
			RI0 = 0;
			input = SBUF0;					// If input from UART0, read SBUF0

			if (input == 0x7F){
				sendChars();
			}
			else{
				if (input == 'a')			//228
				{
					printf("i am a\n\r");
					SPI0CKR += 5;
					printf("clock: %d\n\r", SPI0CKR);
				}
				else if (input == 'z')
				{
					SPI0CKR -= 5;
					printf("clock: %d\n\r", SPI0CKR);
				}

				//SFRPAGE_SAVE = SFRPAGE;
				//SFRPAGE = SPI0_PAGE;
				NSSMD0 = 0;						//slave select

				SPIF = 0;						//clear SPIF

				SPI0DAT = input;				//send input
				while (!SPIF);					//wait until sent

				NSSMD0 = 1;						//release slave

				writeTop(input);				//write to UART0
				RI0 = 0;						//Clear input flag

				overflows = 0;					//wait
				while(overflows < 30000);

				NSSMD0 = 0;						//slave select
				while (!SPIF);					//wait until not busy
				SPIF = 0;						//busy
			
				SPI0DAT = input;				//write dummy character

				while (!SPIF);					//wait until transfer is over

				NSSMD0 = 1;						//release slave

				input = SPI0DAT;				//read SPI0DAT

				writeBot(input);
			
				//SFRPAGE = SFRPAGE_SAVE;
			}
		}
	}
}
Пример #9
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{
	unsigned char adcValH[3];
	unsigned char adcValL[3];
	unsigned int result;
	unsigned short int analogval;
	unsigned char analoghi, analoglow;
	float VREF = 3;

	WDTCN = 0xDE; // Disable the watchdog timer
	WDTCN = 0xAD;
	
	PORT_INIT(); // Initialize the Crossbar and GPIO
	SYSCLK_INIT(); // Initialize the oscillator
	ADC_INIT(); // Initialize ADC0
	DAC_INIT();
	MAC_INIT();

	adcValH[2] = adcValH[1] = adcValL[2] = adcValL[1] = 0;
	result = 0;
	
	while(1)
	{
		SFRPAGE = ADC0_PAGE;
		AD0INT = 0; // Clear the "conversion done" flag
		AD0BUSY = 1; // Start A/D Conversion
		while (AD0INT == 0); // Wait for the conversion to finish
		analoglow = ADC0L; // Read the low byte
		analoghi = ADC0H; // Read the high byte
		analogval = analoghi<<8 | analoglow;

		// Update the variables in the filter equation
		adcValH[2] = adcValH[1]; // x(k-2) high byte
		adcValH[1] = adcValH[0]; // x(k-1) high byte
		adcValL[2] = adcValL[1]; // x(k-2) low byte
		adcValL[1] = adcValL[0]; // x(k-1) low byte

		adcValH[0] = analoghi; // x(k) high and low bytes
		adcValL[0] = analoglow;

		SFRPAGE = MAC0_PAGE;
		MAC0CF |= 0x08; // Clear MAC

		// Load the MAC with the correct values and compute the filter equation
		MAC0AH = 0x28;
		MAC0AL = 0x00;
		MAC0BH = adcValH[0];
		MAC0BL = adcValL[0];

		MAC0BH = adcValH[2];
		MAC0BL = adcValL[2];

		MAC0AH = 0x1E;
		MAC0AL = 0xC4;
		MAC0BH = adcValH[1];
		MAC0BL = adcValL[1];

		MAC0AH = 0x26;
		MAC0AL = 0x00;

		SFRPAGE = MAC0_PAGE; // Delay with any dummy command

		result = (int)MAC0RNDH<<8 | MAC0RNDL; // Read the result from the rounding engine

		SFRPAGE = DAC0_PAGE; // Output the result through the DAC
		DAC0L = result;
		DAC0H = result>>8;
	}
}
Пример #10
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{
	char choice;
	char choice2;
	int printOnThisLine = 11;
	WDTCN = 0xDE;						// Disable the watchdog timer
	WDTCN = 0xAD;						// Note: = "DEAD"!
	
	SYSCLK_INIT();						// Initialize the oscillator
	PORT_INIT();						// Initialize the Crossbar and GPIO
	UART0_INIT();						// Initialize UART0

	SFRPAGE = UART0_PAGE;				// Direct output to UART0

	printf("\033[2J");					// Erase ANSI terminal & move cursor to home position
	printf("\033[33m\033[1B\033[21C");			// makes text yellow, pushes cursor down a line
	//print the program info
	printf("Returns input char. To exit hit ESC.\n\n\r");

	//define scrollable area
	printf("\033[12;24r");
	while(1)
	{
		choice=getchar();
		if (choice >= 32 && choice <= 126)
		{	//reset attributes
			printf("\033[0m");
			//reapply attributes
			printf("\033[44;33m");
			//put cursor over line 6
			printf("\033[6;0H");
			//print
			printf("\n\rThe keyboard character is \033[37m%c\033[33m.\n\r", choice);
		}
		else
		{	
			if(choice ==27){
				//exitprogram
				printf("\033[m");
				printf("\033[24;0H");
				printf("\033[44;33m");
				printf("Program exit \n\r");
				return;
			}
			//check which line we want to print to
			if(printOnThisLine == 24)
			{
				//scroll up
				printf("\033[m");
				//setbackground color
				printf("\033[44;33m");
			}
			else
			{
				printOnThisLine++;
			}
			//go to scrollable area
			printf("\033[%d;0H", printOnThisLine);
			//enable blinking text
			printf("\033[5m");
			//print
			printf("The character $%X is '\033[4mnot printable'\033[0m\033[5;44;33m.\n\r", choice);
			//beep
			putchar(7);
		}

	}
}
Пример #11
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{
	unsigned int i;
	volatile __xdata unsigned char *ext_ram;
	volatile __xdata unsigned char *ext_ram2;
	unsigned static int __xdata failure[512];
	unsigned int count;
	ext_ram = (__xdata unsigned char *)(0x1FF0);
	ext_ram2 = (__xdata unsigned char *)(0x2800);

    SYSCLK_INIT();          // Initialize the oscillator
    PORT_INIT();            // Initialize the Crossbar and GPIO
    UART0_INIT();           // Initialize UART0

    SFRPAGE = UART0_PAGE;   // Direct output to UART0

    printf("\033[2J");     // Erase ANSI terminal & move cursor to home position
    printf("Memory test\n\n\r");

	count = 0;
	for(i=0; i<2064; i++)
	{
		ext_ram[i] = 0xAA;
	}
	for(i=0; i<2064; i++)
	{
		printf("%2X", ext_ram[i]);
		if(ext_ram[i] != 0xAA)
		{
			failure[count] = i+8176;
			count++;
			if(count == 512)
			{
				for(count=0; count<512; count++)
				{
					if(failure[count] != 0)
						printf("%4X\r\n", failure[count]);
				}
				count = 0;
			}
		}
	}
	
	for(i=0; i<2048; i++)
	{
		ext_ram2[i] = 0xAA;
	}
	for(i=0; i<2048; i++)
	{
		printf("%2X", ext_ram2[i]);
		if(ext_ram2[i] != 0xAA)
		{
			failure[count] = i+10240;
			count++;
			if(count == 512)
			{
				for(count=0; count<512; count++)
				{
					if(failure[count] != 0)
						printf("%4X\r\n", failure[count]);
				}
				count = 0;
			}
		}
	}
	for(i=0; i<2048; i++)
	{
		ext_ram2[i] = 0x55;
	}
	for(i=0; i<2048; i++)
	{
		printf("%2X", ext_ram2[i]);
		if(ext_ram2[i] != 0x55)
		{
			failure[count] = i+10240;
			count++;
			if(count == 512)
			{
				for(count=0; count<512; count++)
				{
					if(failure[count] != 0)
						printf("%4X\r\n", failure[count]);
				}
				count = 0;
			}
		}
	}

	for(count=0; count<512; count++)
	{
		if(failure[count] != 0)
			printf("%4X\r\n", failure[count]);
	}
	printf("Memory Test Completed");
    while(1);
}
Пример #12
0
void main(void)
{

	WDTCN = 0XDE;		//Kill the Watchdog 
	WDTCN = 0XAD;

	SYSCLK_INIT();		//Initialize the SYSCLK to 22.1184MHz
	Init_Device();

	SFRPAGE = UART0_PAGE;
	printf("\033[2J");	//Clear ANSI terminal

	aa = (short int *)a;//Set *aa & *bb to be the combined hi & low bytes of
	bb = (short int *)b;//a[1], a[0] & b[1], b[0]
	cc = (long int *)c;	//*cc is c[3], c[2], c[1], c[0]
	dd = (short int *)c;//*dd is the low 16 bits of *cc (low short int)

	while (1)
	{

		SFRPAGE = UART0_PAGE;
		printf("\n\rEnter inputs A & B (4 hex digits each):");
// Read in each hex character and echo it back to terminal
// Convert character to numerical value by subtracting offset
// Handle both upper and lower case A-F or a-f accordingly
		d = getchar(); putchar(d); 
		if(d>'`')a3 = d-0x57;
		else if(d>'@')a3 = d-0x37;
		else  a3 = d-0x30;
		d = getchar(); putchar(d); 
		if(d>'`')a2 = d-0x57;
		else if(d>'@')a2 = d-0x37;
		else  a2 = d-0x30;
		d = getchar(); putchar(d);
		if(d>'`')a1 = d-0x57;
		else if(d>'@')a1 = d-0x37;
		else  a1 = d-0x30;
		d = getchar(); putchar(d);
		if(d>'`')a0 = d-0x57;
		else if(d>'@')a0 = d-0x37;
		else  a0 = d-0x30;
		putchar(' '); putchar(' ');

		d = getchar(); putchar(d); 
		if(d>'`')b3 = d-0x57;
		else if(d>'@')b3 = d-0x37;
		else  b3 = d-0x30;
		d = getchar(); putchar(d); 
		if(d>'`')b2 = d-0x57;
		else if(d>'@')b2 = d-0x37;
		else  b2 = d-0x30;
		d = getchar(); putchar(d);
		if(d>'`')b1 = d-0x57;
		else if(d>'@')b1 = d-0x37;
		else  b1 = d-0x30;
		d = getchar(); putchar(d);
		if(d>'`')b0 = d-0x57;
		else if(d>'@')b0 = d-0x37;
		else  b0 = d-0x30;

// Print out hex digits as a check on correctness
		printf("\r\nA: (HEX DIGITS) %01X, %01X, %01X, %01X", a3, a2, a1, a0);
		printf("\r\nB: (HEX DIGITS) %01X, %01X, %01X, %01X", b3, b2, b1, b0);
//		*aa = a0+a1*16+a2*256+a3*4096;	//Combine 4 hex digits into *aa
//		*bb = b0+b1*16+b2*256+b3*4096;	//Combine 4 hex digits into *bb
// A more efficient way is to use shifts instead of multiplies:
		*aa = a0+(a1<<4)+((short int)a2<<8)+((short int)a3<<12);
		*bb = b0+(b1<<4)+((short int)b2<<8)+((short int)b3<<12);
// Now a[1] is the hi byte of *aa and a[0] is the lo byte
// and b[1] is the hi byte of *bb and b[0] is the lo byte

		SFRPAGE = MAC0_PAGE;
		MAC0CF = 0x09;	//Clear MAC and set to multiply only

		MAC0AH = a[1];	//Load the hi byte of *aa
		MAC0AL = a[0];	//Load the lo byte of *aa
		MAC0BH = b[1];	//Load the hi byte of *bb
		MAC0BL = b[0];	//Load the lo byte of *bb & start multiplier

// Need a very short delay before getting result
		SFRPAGE = MAC0_PAGE;//Any dummy statement will work
		c[0] = MAC0ACC0;	//Get the lo 0th byte of product
		c[1] = MAC0ACC1;	//Get the mid 1st byte of product
		c[2] = MAC0ACC2;	//Get the mid 2nd byte of product
		c[3] = MAC0ACC3;	//Get the hi 3rd byte of product
		ans = *cc;			//*cc is the complete product
// Overlaying *cc and c[] avoids the calculation:
// ans = c[0] + (long int)256*c[1] + (long int)65536*c[2] + (long int)16777216*c[3];

		SFRPAGE = UART0_PAGE;
		printf("\r\nA: (HEX) %04X, %d,  B: (HEX) %04X, %d", *aa, *aa, *bb, *bb);
		printf("\r\nA x B Product: (HEX BYTES) %02X%02X%02X%02X", c[3],c[2],c[1],c[0]);	
		printf("\r\nA x B Product: (HEX LONG INT) %08lX, %ld", ans, ans);
		
		SFRPAGE = MAC0_PAGE;
		for(i=0; i<4; i++)	//Use the accumulator shift operation to 
							//shift the value left 4 bits (= multiply by 4)
							//This operation ignores bit overflows
		{
			MAC0CF = 0x20;	//Set shift direction left and do 1 bit shift
		}

		c[0] = MAC0ACC0;	//Get the lo 0th byte of product
		c[1] = MAC0ACC1;	//Get the mid 1st byte of product
		c[2] = MAC0ACC2;	//Get the mid 2nd byte of product
		c[3] = MAC0ACC3;	//Get the hi 3rd byte of product

		SFRPAGE = UART0_PAGE;
// *cc is the 32-bit answer and *dd is the low 16 bits of *cc
		printf("\r\nProduct<<4: (HEX LONG INT) %08lX, (DEC LO 16 BITS) %d\n", *cc, *dd);
		
	}

}