Code:
#include <sincos.h>
#include <avr/pgmspace.h>
static const short sinusdaten[92] PROGMEM =
{0,2,4,7,9,11,13,16,18,20,22,24,27,29,31
,33,35,37,40,42,44,46,48,50,52,54,56,58
,60,62,64,66,68,70,72,73,75,77,79,81,82
,84,86,87,89,91,92,94,95,97,98,99,101
,102,104,105,106,107,109,110,111,112,113
,114,115,116,117,118,119,119,120,121,122
,122,123,124,124,125,125,126,126,126,127
,127,127,128,128,128,128,128,128};
short sinus(short winkel)
{
short result=0;
if (winkel>360) winkel=winkel-360;
if (winkel<360) winkel=winkel+360;
if (winkel<=90) result = (short)(pgm_read_word(&sinusdaten[winkel]));
if ((winkel>90)&&(winkel<=180)) result = (short)(pgm_read_word(&sinusdaten[180-winkel]));
if ((winkel>180)&&(winkel<=270)) result = -(short)(pgm_read_word(&sinusdaten[winkel-180]));
if (winkel>270) result = -(short)(pgm_read_word(&sinusdaten[360-winkel]));
return (result);
short cosinus(short winkel)
{
short result=0;
if (winkel>360) winkel=360;
if (winkel<=90) result = (short)(pgm_read_word(&sinusdaten[90-winkel]));
if ((winkel>90)&&(winkel<=180)) result = -(short)(pgm_read_word(&sinusdaten[winkel-90]));
if ((winkel>180)&&(winkel<=270)) result = -(short)(pgm_read_word(&sinusdaten[270-winkel]));
if (winkel>270) result = (short)(pgm_read_word(&sinusdaten[winkel-270]));
return (result);
}
sin_x soll also immer den Sinuswert*128 entsprechen.
Lesezeichen