short rpmcount;
long rpm;
int button, p_menu, p_menos, p_mas, pos_menu;
long int tmp1;
long int rpmtime;
long int rpmshift,rpmcorte,rpmlargada;
long int rpmshifttime,rpmcortetime,rpmlargadatime,rpmmaxtime;
short int s_rpmshift,s_largada;
int const disp[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67};
void put_display(long num_out)
{
int uni,dec,cen,umil;
uni=0;
dec=0;
cen=0;
umil=0;
while(num_out>=1000)
{
num_out-=1000;
umil++;
}
while(num_out>=100)
{
num_out-=100;
cen++;
}
while(num_out>=10)
{
num_out-=10;
dec++;
}
while(num_out>=1)
{
num_out-=1;
uni++;
}
delay_ms(1);
DISP0= disp[umil];
delay_ms(1);
output_high(DISP1);
delay_ms(5);
output_low(DISP1);
delay_ms(1);
DISP0= disp[cen];
delay_ms(1);
output_high(DISP2);
delay_ms(5);
output_low(DISP2);
delay_ms(1);
DISP0= disp[dec];
delay_ms(1);
output_high(DISP3);
delay_ms(5);
output_low(DISP3);
delay_ms(1);
DISP0= disp[uni];
output_high(DISP4);
delay_ms(5);
output_low(DISP4);
delay_ms(1);
}
void leer_teclado()
{
button=0;
if((!input(T_MENU)) && !p_menu){ button=1; p_menu=1;};if(input(T_MENU)){p_menu=0;}
if((!input(T_MENOS)) && !p_menos){ button=2; p_menos=1;};if(input(T_MENOS)){p_menos=0;}
if((!input(T_MAS)) && !p_mas){ button=3; p_mas=1;};if(input(T_MAS)){p_mas=0;}
}
void proc_teclado()
{
if(button == 1)
{
pos_menu++;
}
if(pos_menu)
{
switch(pos_menu){
case 1:
if(button == 2){rpmcorte=rpmcorte-100;};if(rpmcorte <= 1500){rpmcorte=1500;}
if(button == 3){rpmcorte=rpmcorte+100;};if(rpmcorte >= 14000){rpmcorte=14000;}
output_high(L_CORTE);
output_low(L_SHIFT);
output_low(L_LARGADA);
put_display(rpmcorte);
break;
case 2:
if(button == 2){rpmshift=rpmshift-100;};if(rpmshift <= 1500){rpmshift=1500;}
if(button == 3){rpmshift=rpmshift+100;};if(rpmshift >= rpmcorte){rpmshift=rpmcorte;}
output_low(L_CORTE);
output_high(L_SHIFT);
output_low(L_LARGADA);
put_display(rpmshift);
break;
case 3:
[B]
if(button == 2){rpmlargada=rpmlargada-100;};if(rpmlargada <= 1500){rpmlargada=1500;}
if(button == 3){rpmlargada=rpmlargada+100;};if(rpmlargada >= 15000){rpmlargada=15000;}
output_low(L_CORTE);
output_low(L_SHIFT);
output_high(L_LARGADA);
put_display(rpmlargada);
break;
case 4:
pos_menu=0;
tmp1 = rpmcorte/100; write_eeprom(1,tmp1);
tmp1 = rpmshift/100; write_eeprom(2,tmp1);
tmp1 = rpmlargada/100; write_eeprom(3,tmp1);
output_low(L_CORTE);
output_low(L_SHIFT);
output_low(L_LARGADA);
put_status();
leer_eeprom();
break;
}
}
else if(button == 2)
{
if(!s_rpmshift)
{
s_rpmshift=1;
}
else
{
s_rpmshift=0;
}
put_status();
}
}
void Sample_isr(void)
{
rpmcount++;
if(rpmcount==0)
{
rpmtime=get_timer1();
set_timer1(0);
proc_shift();
proc_corte();
}
}
void main(void)
{
setup_timer_1(T1_INTERNAL | T1_DIV_BY_2);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
set_tris_a(0x3c);
set_tris_b(0x01);
set_tris_c(0x00);
rpm=0;
rpmtime=0;
rpmcount=0;
output_low(BOBINA);
output_low(DISP1);
output_low(DISP2);
output_low(DISP3);
output_low(DISP4);
put_status();
leer_eeprom();
while(TRUE)
{
if(!pos_menu)
{
rpm=60*(1000000/rpmtime);
put_display(rpm);
}
leer_teclado();
proc_teclado();
delay_ms(1);
}
}