////////////////////////////////////////////////////////////////////////////////
//
// pretends to be a PC parallel port for printing !
//	2003.01.21 - works!
////////////////////////////////////////////////////////////////////////////////

#define N_STROBE PEB0R
#define DATA_PORT PADR 
#define DATA_PORT_SHADOW PADRShadow

static void init_ports() {
	//set PA0:PA7 as outputs (Data0:Data7), disable slave port
	WrPortI(SPCR, & SPCRShadow, 0x84);
	//set PE0 for output (~Strobe)
	WrPortI(PEDDR, & PEDDRShadow, 0x01 | PEDDRShadow);
	WrPortI(PEFR, & PEFRShadow, 0x00);
	//set PC1 (~Acknowledge) and PC3 (Busy) for input
	//WrPortI(PCFR, & PCFRShadow, ~((1<<3)|(1<<1)) & PCFRShadow);
}

static void print_char(char c){
	int i;
	//put the data on the lines
	WrPortI(DATA_PORT, & DATA_PORT_SHADOW, c);
	//toggle ~Strobe (delay must be > 5us)
	WrPortI(N_STROBE, NULL, 0x00);
	WrPortI(N_STROBE, NULL, 0xFF);
}

static void print_str(char* str){
	int i;
	for(i=0;i<strlen(str);i++){
		print_char(str[i]);
	}
}

// C programs require a main() function
main() {
	int i;	// define an integer j to serve as a loop counter
	char capital_u;
	byte c;
	char* my_word;

	init_ports();
	c=0;

	my_word = "testing, testing, 1... 2... 3...\n";

	printf("running...");
	while(1){
		if (BitRdPortI(PBDR, 3)==0){
			while(BitRdPortI(PBDR, 3)==0);	//debounce
			printf(" - sending... ");
			/*put_char('a');put_char('b');put_char('c');
			put_char('d');put_char('e');put_char('f');
			put_char('\n');
			*/
			print_str(my_word);
			printf(" done \n");
		}
	}
  
} // end program
