/**
* Homemade Yamaha FZR-150 Portable 8051 Tachometer Signal Generator
* CopyRight By
http://3wa.tw (Feather Mountain)
* License: GPL & MIT
* Free free and free. Feel free and feedback let me know :))
* Version: 1.0 (2015-01-16 01:50AM)
*/
#include<AT89x51.h>
#define CNT 100
long i=0;
void delay_us(unsigned int us_count)
{
while(us_count!=0)
{
i++;
us_count--;
}
}
void delay_1ms(int msec)
{
int i;
while(msec--) {
i = CNT;
while(i--);
}
}
int loops[27+15] = {
12000,12000,12000,12000,12000,7000,5000,3000,2000,1500,1200,1000,857,750,666,599,545,500,461,428,380,340,330,330,330,330,330,
330, //14000
360, //13000
395, //12000
435, //11000
480, //10000
540, //9000
610, //8000
700, //7000
830, //6000
1020, //5000
1300, //4000
1750, //3000
2700, //2000
5500, //1000
12000 //0
};
void main(void)
{
int j = 0;
int next = 1;
int step = 0;
int ls = sizeof(loops) / sizeof(int) -1;
long thelimit = 6000;
int after27 = 10;
//Wait 3 seconds then start
delay_1ms(3000);
step = 0;
i = 0;
while (1) {
if( i >= thelimit )
{
i=0;
if(step >= 27)
{
j++;
}
if( step < 27 || j >= after27 )
{
j = 0;
step += next;
}
}
if( step >= ls )
{
next = -1;
}
if( step <= 0 )
{
next = 1;
}
if( loops[step] == 12000 )
{
// Do nothing when 12000 ( 0rpm )
P0 = 0xFF;
P1 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
delay_us(loops[step]/4);
P0 = 0xFF;
P1 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
delay_us(loops[step]/4);
}
else
{
// Half High and half Low
P0 = 0xFF;
P1 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
delay_us(loops[step]/4);
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
delay_us(loops[step]/4);
}
}
}