

#define LE_VAL    1
#define DATA_VAL  2
#define CLK_VAL   4

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <stdlib.h>



int le,data,clock;





void ausgabe()
{

	int wert;

	wert = LE_VAL * le + DATA_VAL * data + CLK_VAL * clock;

	printf("%d-",wert);

	outportb(888,wert);

}


void bitfolge(char *folge)
{

	int t;

	for( t=0 ; t<strlen(folge) ; t++ )
	{

		data=folge[t]-48; /* Ascii-> Integer */
		ausgabe();

		clock=1;
		ausgabe();

		clock=0;
		ausgabe();

		printf(".");

		data=0;

	}

}


int wertholen()
{

	int x;

	gotoxy(5,22);
	printf("New Value: ");
	scanf("%d",&x);

	return x;

}




void main(void)
{

	int A,P,R,fq,N;
	char eingabe;

	int h, hr, hv;

	char bitstring[25];

	float f_cmp, f_out;

	char outstr[50];
	char ref_string[50];
	char prg_string[50];



	le=0;
	data=0;
	clock=0;
	ausgabe();


	N=5;
	A=0;
	fq=10;
	R=5;
	P=32;


	do
	{

		clrscr();


		printf("  Fujitshu MB15E07\n\n\n");

		printf("Actual Parameters:\n\n");

		printf("n) Preset divide ratio of 11 bit programmable counter: (5..2047)... %d\n",N);
		printf("a) Preset divide ratio of 7 bit swallow counter: (0..127).......... %d\n",A);
		printf("f) Frequency of referenz oszillator in MHz (3..40)................. %d\n",fq);
		printf("r) Preset divide ratio of 14 bit reference counter (5..16383)...... %d\n",R);
		printf("p) Preset divide ratio of modules prescaler (32 or 64)............. %d\n",P);

		printf("\nESC) Quit");

		printf("\n\n");


		f_cmp=fq*1000.0/R;

		printf("   Comparison frequency: %0.3f kHz\n\n",f_cmp);

		f_out=(((float)P*(float)N)+A)*f_cmp;

		printf("   Output frequency: %0.3f kHz\n\n",f_out);


		strcpy(outstr,"11");

		if(P==32) strcat(outstr,"1");
		else strcat(outstr,"0");

		hr=R;
		hv=16384;

		do
		{
			hv=hv/2;
			if(hr>=hv) { strcat(outstr,"1"); hr=hr-hv; }
			else       { strcat(outstr,"0"); }
		}
		while(hv>1);

		strcat(outstr,"1");

		printf(" Reference-String: %s\n",outstr);

		strcpy(ref_string, outstr);

		strcpy(outstr,"");

		hr=N;
		hv=2048;

		do
		{
			hv=hv/2;
			if(hr>=hv) { strcat(outstr,"1"); hr=hr-hv; }
			else       { strcat(outstr,"0"); }
		}
		while(hv>1);

		hr=A;
		hv=128;

		do
		{
			hv=hv/2;
			if(hr>=hv) { strcat(outstr,"1"); hr=hr-hv; }
			else       { strcat(outstr,"0"); }
		}
		while(hv>1);

		strcat(outstr,"0");

		printf(" Programmable Counter-String: %s\n",outstr);

		strcpy(prg_string, outstr);



		le=1;
		ausgabe();

		bitfolge(ref_string);

		le=0;
		ausgabe();




		eingabe=getch();

		if(eingabe=='n')
		{
			h=wertholen();
			if(h>=5 && h<=2047) N=h;
		}

		if(eingabe=='a')
		{
			h=wertholen();
			if(h>=0 && h<=127) A=h;
		}

		if(eingabe=='f')
		{
			h=wertholen();
			if(h>=3 && h<=40) fq=h;
		}

		if(eingabe=='r')
		{
			h=wertholen();
			if(h>=5 && h<=16383) R=h;
		}

		if(eingabe=='p')
		{
			h=wertholen();
			if(h==32 || h==64) P=h;
		}


	}while(eingabe!=27);


}

