#include <REG52.H>

// We used an fixpoint byte format: [x],[x][x][x][x][x][x][x]
// It means, that Nfix = Ndec * 2^7

#define byte unsigned char
#define word unsigned int


byte FixMul(byte a, b)	// Fixpoint mul
{	
	return ((a * b) << 1) >> 8;
}

byte F(byte x)	   // calcs E = 1 - x + x^2 - x^3 ...
{
	byte An = 128;	 // 128 = 1 in our format
	byte Res = 0;	 // Accumulating result
	byte fl = 1;	 // flag +/-

	while (An > 0)	 // An = x^n which means that sometime we 
	                 // will get zerro -> stop the iteration process
	{
		if (fl) Res += An;
		else  Res -= An;

		An = FixMul(An, x);		
		fl =! fl;
	}

	return Res;
}


void Main()
{
	byte i = 0;
	byte xdata lol[128];

	P1=0;

	for (;;) for (i=1; i<127; i++)
	{
		lol[i] = F(i) << 1;
		P1 = lol[i];
	}
				   
	

}
Соседние файлы в папке c51fixpoint
  • #
    09.05.2014204 б11Lab3.plg
  • #
    09.05.201456.41 Кб11Lab3.uvopt
  • #
    09.05.201413.21 Кб11Lab3.uvproj
  • #
    09.05.201456.83 Кб12Lab3_uvopt.bak
  • #
    09.05.201413.21 Кб11Lab3_uvproj.bak
  • #
    09.05.2014832 б12Main.c
  • #
    09.05.20148.08 Кб11Main.LST
  • #
    09.05.20142.69 Кб11Main.OBJ