// EC533: Programmable Logic System Design
// Fall 2000
// Doering (Ed.Doering@Rose-Hulman.Edu)
//

/* -----------------------------------------------------------------------------
	C program to go with 8031template.v

	Demonstrates reading and writing to FPGA registers mapped in external
	data memory.

	Compile using Keil uVision2 demo version.
----------------------------------------------------------------------------- */

#include <absacc.h>		// Library of macros to read/write absolute addresses
#include <intrins.h>	// Intrinsic functions (faster execution); need _crol_


void main(void) {

	char rval;					// Value to read from FPGA readable register
	unsigned char LEDPattern;	// LED pattern for FPGA writable register 
	unsigned long j;			// Index variable for delay loop
	
	// Initalize LED pattern
	LEDPattern = 3;

	while (1) {
		// Read from external data memory
		rval = XBYTE [0x8CFE];

		// Write LED pattern to external data memory
		XBYTE [0x9000] = LEDPattern;

		// Rotate the LED pattern bits to the left
		LEDPattern = _crol_(LEDPattern,1);

		// Delay
		for (j = 0; j<30000L; j++)
			;

	}
}