úterý 15. března 2011

MAM Generátor průběhů


#include <reg51.h>
#define PortDA P1 
// 0 obdélník, 1 trojúhelník, 2 pila, 3 sinus
unsigned char sinus_pole[] = {127, 152, 176, 198, 217, 233, 244, 252, 254, 252, 244
,233, 217, 198, 176, 152, 127, 102, 79, 57, 37, 22, 10, 2, 0, 2, 10, 21, 37, 56, 78, 102} ;



void main()
{
unsigned char rezim = 1;
unsigned char roste = 1;
unsigned char cas = 0;
PortDA = 0;
while(1)
{
switch (rezim)
{
case 0: // obdelnik
PortDA = ~PortDA;
break;
case 1: // trojúhelník
if (roste == 1)
{
if (PortDA>=254) roste = 0;
PortDA++;
}
else
{
if (PortDA <=1) roste = 1;
PortDA--;
}
break;
case 2: // pila
PortDA++;
break;
case 3: // sinusovka
cas++;
if (cas >= 32) cas = 0;
PortDA = *(sinus_pole+cas);
break;
}
}
}

Žádné komentáře:

Okomentovat