Documentos de Académico
Documentos de Profesional
Documentos de Cultura
// Cursores
char cursor10;
// opciones
char opcion10;
//menu
char submenu;
// ciclo trabajo
float ciclo1, ciclo2,ciclo3,ciclo4;
// valor de voltaje
float voltaje;
// valor de Apertura
float apertura;
// valor rpm
float rpm,rntc;
char txt[20];
int temp;
float frecuenciaabs;
float frecuenciamaf;
int timer0;
int velocidad;
float T;
char contador;
// FUNCION INTERRUPCION
void Interrupt(){
if ((TMR0IF_bit)&&(opcion3==4)) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
LATB.F0=~LATB.F0;
if ((TMR0IF_bit)&&(opcion3==5)) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
LATB.F1=~LATB.F1;
}
// Interrupcion timer0 para sensor KS
if ((TMR0IF_bit)&&(opcion2==10)) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
LATD.F2=~LATD.F2;
delay_us(2);
LATD.F2=~LATD.F2;
if ((TMR0IF_bit)&&(opcion2==9)) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
LATD.F2=~LATD.F2;
}
// interrupcion timer0 para ckp hall 40-1 (700 rpm min 5000 rpm max)
if ((TMR0IF_bit)&&(opcion9==1)) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
contador++;
LATD.F2=~LATD.F2;
if (contador==79){
LATD.F2=0X00; }
if (contador==80){
LATD.F2=0X00;
contador=0;
// interrupcion timer0 para ckp hall 36-1 800 RPM MIN MAX 5000 RPM
if ((TMR0IF_bit)&&(opcion9==2) ) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
contador++;
LATD.F2=~LATD.F2;
if (contador==71){
LATD.F2=0X00; }
if (contador==72){
LATD.F2=0X00;
contador=0;
if ((TMR0IF_bit)&&(opcion9==3 ) ) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
contador++;
LATD.F2=~LATD.F2;
if (contador==117){
LATD.F2=0X00; }
if (contador==118){
LATD.F2=0X00;
if (contador==119){
LATD.F2=0X00; }
if (contador==120){
LATD.F2=0X00;
contador=0;
if ((TMR0IF_bit)&&(opcion10==1)){
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
contador++;
LATD.F3=~LATD.F3;
if (contador==79){
LATD.F3=0X00; }
if (contador==80){
LATD.F3=0X00;
contador=0;
if ((TMR0IF_bit)&&(opcion10==2)) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
contador++;
LATD.F3=~LATD.F3;
if (contador==71){
LATD.F3=0X00; }
if (contador==72){
LATD.F3=0X00;
contador=0;
if ((TMR0IF_bit)&&(opcion10==3) ) {
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
contador++;
LATD.F3=~LATD.F3;
if (contador==117){
LATD.F3=0X00; }
if (contador==118){
LATD.F3=0X00;
if (contador==119){
LATD.F3=0X00; }
if (contador==120){
LATD.F3=0X00;
contador=0;
if ((TMR0IF_bit)&&(opcion7==1)){
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
LATD.F2=~LATD.F2;
if ((TMR0IF_bit)&&(opcion2==3)){
TMR0IF_bit = 0;
TMR0H = (timer0)>> 8;
TMR0L = (timer0);
LATD.F2=~LATD.F2;
if ((TMR0IF_bit)&&(opcion6==1)){
TMR0IF_bit = 0;
TMR0H = (62533)>> 8;
TMR0L = (62533);
LATE.F1=~LATE.F1;
}
}
void main()
// CONFIGURACION PUERTOS
// puertos no utilizados
TRISB.F0=0;
LATB.F0=0;
TRISB.F1=0;
LATB.F1=0;
LATE.F1=0;
TRISC=0b11111001;
LATC=0b00000000;
LATD.F2=0X00;
TRISD.F3=0X00;
TRISE.F0=0X00;
LATE.F0=0X00;
ADCON1.PCFG2=1;
ADCON1.PCFG1=0;
ADCON1.PCFG0=0;
// DECLARACION DE VARIABLES
cursor = 1;
submenu = 0;
cursor2 = 1;
cursor3=1;
cursor4=1;
opcion=0;
opcion2=0;
opcion3=0;
opcion4=0;
opcion5=0;
opcion7=0;
cursor5=1;
cursor6=1;
cursor7=1;
cursor8=1;
cursor9=1;
cursor10=1;
opcion6=0;
opcion7=0;
opcion8=0;
opcion9=0;
opcion10=0;
ciclo1=0;
ciclo2=180;
ciclo3=0;
ciclo4=0;
timer0=0; // variable usado para timer0 sim abs y maf digital
contador=0;
// PANTALLA PRINCIPAL
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"SIMULADOR-PRUEBA DE");
Lcd_Out(2,1,"SENSORES AUTOMOTRIZ");
Lcd_Out(3,3,"OPCION SIMULACION");
// CICLO WHILE
while (1)
switch(cursor)
case 1:
Lcd_Chr(3,1,'>');
Lcd_Chr(4,1,' ');
cursor = 2;
opcion = 1;
break;
case 2:
Lcd_Chr(3,1,' ');
cursor = 1;
opcion = 2;
Lcd_Chr(4,1,'>');
break;
if (Button(&PORTC,6,50,1))
case 1:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 2,"TPS");
Lcd_Out(2,2,"ECT");
Lcd_Out(3,2,"ABS");
Lcd_Out(1,7,"MAF");
Lcd_Out(2,7,"CKP");
Lcd_Out(3,7,"OXI");
Lcd_Out(1,12,"MAP");
Lcd_Out(2,12,"CMP");
Lcd_Out(3,12,"KS");
Lcd_Out(1,17,"IAT");
Lcd_Out(2,17,"VSS");
submenu = 1;
break;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,"INYECT");
Lcd_Out(2,2,"RELE");
Lcd_Out(3,2,"TPS");
Lcd_Out(4,2,"BOBINA");
Lcd_Out(1,10,"BOBINA IGT");
Lcd_Out(2,10,"VOLTIMET DC");
Lcd_Out(3,10,"SELENOIDE");
Lcd_out(4,10,"POTENCIOMET");
submenu = 2;
break;
{
switch(cursor2)
case 1: //TPS
Lcd_Chr(1,1,'>');
cursor2=2;
opcion2=1;
break;
case 2:
Lcd_Chr(2,1,'>');
cursor2=3;
opcion2=2;
break;
case 3:
Lcd_Chr(3,1,'>');
cursor2=4;
opcion2=3;
break;
case 4:
Lcd_Chr(4,1,'>');
opcion2=4;
cursor2=5;
break;
case 5:
Lcd_Chr(1,6,'>');
opcion2=5;
cursor2=6;
break;
case 6:
Lcd_Chr(2,6,'>');
opcion2=6;
cursor2=7;
break;
case 7:
Lcd_Chr(3,6,'>');
cursor2 = 8;
opcion2=7;
break;
case 8:
Lcd_Chr(1,11,'>');
opcion2=8;
cursor2=9;
break;
case 9:
Lcd_Chr(2,11,'>');
opcion2=9;
cursor2=10;
break;
case 10:
Lcd_Chr(2,11,' '); // KS
Lcd_Chr(3,11,'>');
opcion2=10;
cursor2=11;
break;
case 11:
Lcd_Chr(1,16,'>');
opcion2=2;
cursor2=12;
break;
case 12:
Lcd_Chr(2,16,'>');
opcion2=3;
cursor2=1;
break;
}
if (Button(&PORTC,6,50,1))
switch (opcion2)
case 1:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,6,"% APERTURA");
Lcd_Out(3,6,"V VOLTAJE");
Lcd_Out(4,6,"RPM APROX");
PWM1_init(4000);
PWM1_Start();
PWM1_Set_Duty(ciclo1);
while(1) {
if(Button(&PORTC,7,50,1)){
break; }
if(Button(&PORTC,4,10,1)&& (opcion2==1)){
ciclo1=ciclo1+1;
if (ciclo1==255){
ciclo1=255;}
if(Button(&PORTC,0,50,1)&& (opcion2==1)){
ciclo1=ciclo1-1;
if (ciclo1<0){
ciclo1=0;}
PWM1_Set_Duty(ciclo1);
delay_ms(10);
// voltaje
voltaje= (ciclo1)*0.0196;
FloatToStr_FixLen(voltaje,txt,4);
Lcd_out(3,1,Txt);
// apertura
apertura=(ciclo1)*100 / 255;
FloatToStr_FixLen(apertura,txt,4);
Lcd_out(2,1,Txt);
// RPM
rpm=23.5294*(ciclo1);
FloatToStr_FixLen(rpm,txt,4);
Lcd_out(4,1,Txt);
}
break;
case 2:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3,6,"V VOLTAJE");
PWM1_init(4000);
PWM1_Start();
PWM1_Set_Duty(ciclo2);
while(1) {
if(Button(&PORTC,7,50,1)){
break; }
if(Button(&PORTC,4,50,1)&& (opcion2==2)){
ciclo2=ciclo2+1;
if (ciclo2>180){
ciclo2=180;}
if(Button(&PORTC,0,50,1)&& (opcion2==2)){
ciclo2=ciclo2-1;
if (ciclo2<30){
ciclo2=30;}
PWM1_Set_Duty(ciclo2);
delay_ms(10);
// voltaje
// 255*0.0196=5 voltios
voltaje= ((ciclo2)*0.0196);
FloatToStr_FixLen(voltaje,txt,4);
Lcd_out(3,1,Txt);
// calculo de rnt
rntc=(31300/(5/voltaje)-1);
// TEMPERATURA
temp= ((3795.5*293.15)/(3795.5+293.15*log(rntc/39200)));
temp=temp-273.15;
FloatToStr_FixLen(temp,txt,4);
Lcd_out(4,1,Txt);
break;
case 3:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,6,"");
Lcd_Out(3,7,"K/M VELOCIDAD");
Lcd_Out(4,7,"HZ FRECUENCIA");
T0CON = 0x85;
TMR0H = (56100)>> 8;
TMR0L = 56100;
GIE_bit = 1;
TMR0IE_bit = 1;
timer0=56100;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,50,1)&&(opcion2==3)){
timer0+=100;
delay_ms(1);
if (timer0>64700){
timer0=64700;}
delay_ms(1);
if(Button(&PORTC,0,50,1)&& ( opcion2==3)){
timer0-=100;
delay_ms(1);
if (timer0<56100){
timer0=56100;
delay_ms(1);
T=(((65535-timer0)*5.331)/1000000);
// T=T/1000000;
frecuenciaabs=(1/(T*2));
// frecuencia
ByteToStr(frecuenciaabs, txt);
Lcd_out(4,1,Txt);
// velocidad
ByteToStr(frecuenciaabs, txt);
Lcd_out(3,1,Txt);
break;
case 4:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(4,3,"CKP INDUCTIVO");
submenu=3;
break;
case 5:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3,3,"MAF DIGITAL");
Lcd_Out(4,3,"MAF ANALOGICO");
submenu=7;
break;
case 6 :
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3,3,"EFECTO HALL");
Lcd_Out(4,3,"INDUCTIVO");
submenu=4;
break;
case 7 :
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3,3,"SEÑAL DIGITAL");
Lcd_Out(4,3,"SEÑAL ANALOGA");
submenu=5;
break;
case 8:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,6,"V VOLTAJE");
Lcd_Out(3,6,"Kpa Aprox");
PWM1_init(4000);
PWM1_Start();
ciclo2=25;
PWM1_Set_Duty(ciclo2);
while(1) {
if(Button(&PORTC,7,50,1)){
break; }
if(Button(&PORTC,4,50,1)&& (opcion2==8)){
ciclo2=ciclo2+1;
if (ciclo2>250){
ciclo2=250;}
if(Button(&PORTC,0,50,1)&& (opcion2==8)){
ciclo2=ciclo2-1;
if (ciclo2<25){
ciclo2=25;}
PWM1_Set_Duty(ciclo2);
delay_ms(10);
// voltaje
// 255*0.0196=5 voltios
voltaje= ((ciclo2)*0.0196);
FloatToStr_FixLen(voltaje,txt,4);
Lcd_out(2,1,Txt);
// calculo kpa
kpa=(Voltaje/0.024);
FloatToStr_FixLen(kpa,txt,4);
Lcd_out(3,1,Txt);
}
break;
case 9:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"HZ");
T0CON = 0x80;
TMR0H = (61780)>> 8;
TMR0L = 61780;
GIE_bit = 1;
TMR0IE_bit = 1;
timer0=61780;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion2==9)){
timer0+=10;
if (timer0>64330){
timer0=64330;}
if(Button(&PORTC,0,1,1)&& ( opcion2==9)){
timer0-=10;
if (timer0<61780){
timer0=61780;
T=(((65535-timer0)*0.16600)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
FloatToStr_FixLen(frecuenciamaf,txt,6);
//IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
break;
case 10:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,7,"HZ FRECUENCIA");
TMR0H = (61783)>> 8;
TMR0L = 61783;
GIE_bit = 1;
TMR0IE_bit = 1;
contador=0;
LATD.F2=0X00;
timer0=61783;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion2==10)){
timer0++;
delay_ms(1);
if (timer0>64934){
timer0=64934;}
delay_ms(1);
if(Button(&PORTC,0,1,1)&& ( opcion2==10)){
timer0--;
delay_ms(1);
if (timer0<61783){
timer0=61783;
delay_ms(1);
T=(((65535-timer0)*0.166)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
break;
case 11:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,6,"C TEMPERATURA");
Lcd_Out(3,6,"V VOLTAJE");
break;
case 12:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,6,"K/H VELOCIDAD");
Lcd_Out(3,6,"HZ FRECUENCIA");
break;
if (Button(&PORTC,5,50,1)&& ( submenu==2))
switch (cursor3){
case 1:
Lcd_Chr(1,1,'>'); //INYECT
Lcd_Chr(4,9,' ');
opcion3=1;
cursor3=2;
break;
case 2:
opcion3=2;
cursor3=3;
break;
case 3:
Lcd_Chr(3,1,'>');
opcion3=3;
cursor3=4;
break;
case 4:
Lcd_Chr(4,1,'>');
opcion3=4;
cursor3=5;
break;
case 5:
Lcd_Chr(1,9,'>');
cursor3=6;
opcion3=5;
break;
case 6:
Lcd_Chr(2,9,'>');
opcion3=6;
cursor3=7;
break;
case 7:
Lcd_Chr(3,9,'>');
opcion3=7;
cursor3=8;
break;
case 8:
Lcd_Chr(4,9,'>');
cursor3=1;
opcion3=8;
break;
switch ( cursor4){
case 1:
Lcd_Chr(4,2,' ');
opcion4=1;
cursor4=2;
break;
case 2:
Lcd_Chr(3,2,' ');
opcion4=2;
cursor4=1;
break;
if (Button(&PORTC,5,50,1)&&(submenu==4))
switch ( cursor8){
case 1:
Lcd_Chr(4,2,' ');
opcion8=1;
cursor8=2;
break;
case 2:
Lcd_Chr(4,2,'>');
opcion8=2;
cursor8=1;
break;
if (Button(&PORTC,5,50,1)&& (submenu==5))
switch ( cursor6){
case 1:
Lcd_Chr(4,2,' ');
opcion6=1;
cursor6=2;
break;
case 2:
Lcd_Chr(4,2,'>');
opcion6=2;
cursor6=1;
break;
if (Button(&PORTC,5,50,1)&& (submenu==7))
switch ( cursor7){
case 1:
Lcd_Chr(4,2,' ');
opcion7=1;
cursor7=2;
break;
case 2:
Lcd_Chr(4,2,'>');
opcion7=2;
cursor7=1;
break;
}
// SI PULSO RC5 MUEVO EL CURSOR EN EL SUB MENU(2) CKP INDUCTIVO
if (Button(&PORTC,5,50,1)&& (submenu==9))
switch ( cursor10){
case 1:
Lcd_Chr(2,1,'>'); // 40-1
Lcd_Chr(4,1,' ');
opcion10=1;
cursor10=2;
break;
case 2:
Lcd_Chr(3,1,'>'); // 36-1
Lcd_Chr(2,1,' ');
opcion10=2;
cursor10=3;
break;
case 3:
Lcd_Chr(4,1,'>');
opcion10=3;
cursor10=1;
break;
}
if (Button(&PORTC,5,50,1)&& (submenu==8))
switch ( cursor9){
case 1:
Lcd_Chr(2,1,'>'); // 40-1
Lcd_Chr(4,1,' ');
opcion9=1;
cursor9=2;
break;
case 2:
Lcd_Chr(3,1,'>'); // 36-1
Lcd_Chr(2,1,' ');
opcion9=2;
cursor9=3;
break;
case 3:
Lcd_Chr(4,1,'>');
opcion9=3;
cursor9=1;
break;
if (Button(&PORTC,6,50,1))
switch (opcion6)
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3,7,"0-1 V VOLTAJE");
TMR0H = (62533)>> 8;
TMR0L = 62533;
GIE_bit = 1;
TMR0IE_bit = 1;
break;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3,1," ");
Lcd_Out(4,6," ");
PWM1_init(4000);
PWM1_Start();
PWM1_Set_Duty(ciclo3);
while(1) {
if(Button(&PORTC,7,50,1)){
break; }
if(Button(&PORTC,4,50,1)&& (opcion6==2)){
ciclo3=ciclo3+1;
if (ciclo3>51){
ciclo3=51;}
if(Button(&PORTC,0,50,1)&& (opcion6==2)){
ciclo3=ciclo3-1;
if (ciclo3<0){
ciclo3=0;}
PWM1_Set_Duty(ciclo3);
delay_ms(10);
// voltaje
// 255*0.0196=5 voltios
voltaje= ((ciclo3)*0.0196);
//ByteToStr(voltaje, txt);
//Lcd_out(4,1,Txt);
FloatToStr_FixLen(voltaje,txt,4);
Lcd_out(2,2,Txt);
break;
}
if (Button(&PORTC,6,50,1))
switch (opcion7)
case 1:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,7,"HZ FRECUENCIA");
Lcd_Out(3,1," ");
Lcd_Out(4,6," ");
T0CON = 0x83;
TMR0H = (28019)>> 8;
TMR0L = 28019;
GIE_bit = 1;
TMR0IE_bit = 1;
timer0=28020;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion7==1)){
timer0+=10;
if (timer0>65460){
timer0=65460;}
if(Button(&PORTC,0,1,1)&& ( opcion7==1)){
timer0-=10;
if (timer0<28020){
timer0=28020;
T=(((65535-timer0)*1.328)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
break;
case 2:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3,1," ");
Lcd_Out(4,6," ");
PWM1_init(4000);
PWM1_Start();
PWM1_Set_Duty(ciclo3);
while(1) {
if(Button(&PORTC,7,50,1)){
break; }
if(Button(&PORTC,4,50,1)&& (opcion7==2)){
ciclo3=ciclo3+1;
if (ciclo3>230){
ciclo3=230;}
if(Button(&PORTC,0,50,1)&& (opcion7==2)){
ciclo3=ciclo3-1;
if (ciclo3<0){
ciclo3=0;}
PWM1_Set_Duty(ciclo3);
delay_ms(10);
// voltaje
// 255*0.0196=5 voltios
voltaje= ((ciclo3)*0.0196);
//ByteToStr(voltaje, txt);
//Lcd_out(4,1,Txt);
FloatToStr_FixLen(voltaje,txt,4);
Lcd_out(2,2,Txt);
break;
if (Button(&PORTC,6,50,1))
{
switch (opcion8)
case 1:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,2,"40-1");
Lcd_Out(3,2,"36-1");
Lcd_Out(4,2,"60-2");
submenu=8;
break;
case 2:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,2,"40-1");
Lcd_Out(3,2,"36-1");
Lcd_Out(4,2,"60-2");
submenu=9;
break;
switch (opcion9)
case 1:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"RPM");
Lcd_Out(3,8,"HZ FRECUENCIA");
opcion9=1;
T0CON = 0x80;
TMR0H = (61783)>> 8;
TMR0L = 61783;
GIE_bit = 1;
TMR0IE_bit = 1;
contador=0;
LATD.F2=0X00;
timer0=61783;
while(1) {
// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de
Frecuencia
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion9==1)){
timer0++;
delay_ms(1);
if (timer0>64934){
timer0=64934;}
delay_ms(1);
if(Button(&PORTC,0,1,1)&& ( opcion9==1)){
timer0--;
delay_ms(1);
if (timer0<61783){
timer0=61783;
delay_ms(1);
}
T=(((65535-timer0)*0.166)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
lcd_out(3,1,txt);
break;
case 2:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"RPM");
Lcd_Out(3,8,"HZ FRECUENCIA");
T0CON = 0x80;
TMR0H = (61783)>> 8;
TMR0L = 61783;
GIE_bit = 1;
TMR0IE_bit = 1;
contador=0;
LATD.F2=0X00;
timer0=61783;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion9==2)){
timer0++;
delay_ms(1);
if (timer0>64934){
timer0=64934;}
delay_ms(1);
}
if(Button(&PORTC,0,1,1)&& ( opcion9==2)){
timer0--;
delay_ms(1);
if (timer0<61783){
timer0=61783;
delay_ms(1);
T=(((65535-timer0)*0.166)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
lcd_out(3,1,txt);
break;
case 3:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"CKP EFECTO HALL 60-2"); //PANTALLA FINAL CKP HALL 36-1
Lcd_Out(2,8,"RPM");
Lcd_Out(3,8,"HZ FRECUENCIA");
T0CON = 0x80;
TMR0H = (61783)>> 8;
TMR0L = 61783;
GIE_bit = 1;
TMR0IE_bit = 1;
contador=0;
LATD.F2=0X00;
timer0=61783;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion9==3)){
timer0++;
delay_ms(1);
if (timer0>64934){
timer0=64934;}
delay_ms(1);
if(Button(&PORTC,0,1,1)&& ( opcion9==3)){
timer0--;
delay_ms(1);
if (timer0<61783){
timer0=61783;
delay_ms(1);
T=(((65535-timer0)*0.166)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
lcd_out(3,1,txt);
}
break;
if (Button(&PORTC,6,50,1))
switch (opcion10)
case 1:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"RPM");
Lcd_Out(3,8,"HZ FRECUENCIA");
TMR0H = (61783)>> 8;
TMR0L = 61783;
GIE_bit = 1;
TMR0IE_bit = 1;
contador=0;
LATD.F3=0X00;
timer0=61783;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion10==1)){
timer0++;
delay_ms(1);
if (timer0>64934){
timer0=64934;}
delay_ms(1);
if(Button(&PORTC,0,1,1)&& ( opcion10==1)){
timer0--;
delay_ms(1);
if (timer0<61783){
timer0=61783;
delay_ms(1);
T=(((65535-timer0)*0.166)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
lcd_out(3,1,txt);
break;
case 2:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"RPM");
Lcd_Out(3,8,"HZ FRECUENCIA");
T0CON = 0x80;
TMR0H = (61783)>> 8;
TMR0L = 61783;
GIE_bit = 1;
TMR0IE_bit = 1;
contador=0;
LATD.F3=0X00;
timer0=61783;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion10==2)){
timer0++;
delay_ms(1);
if (timer0>64934){
timer0=64934;}
delay_ms(1);
if(Button(&PORTC,0,1,1)&& ( opcion10==2)){
timer0--;
delay_ms(1);
if (timer0<61783){
timer0=61783;
delay_ms(1);
T=(((65535-timer0)*0.166)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
lcd_out(3,1,txt);
break;
case 3:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"RPM");
Lcd_Out(3,8,"HZ FRECUENCIA");
T0CON = 0x80;
TMR0H = (61783)>> 8;
TMR0L = 61783;
GIE_bit = 1;
TMR0IE_bit = 1;
contador=0;
LATD.F3=0X00;
timer0=61783;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,1,1)&&(opcion10==3)){
timer0++;
delay_ms(1);
if (timer0>64934){
timer0=64934;}
delay_ms(1);
if(Button(&PORTC,0,1,1)&& ( opcion10==3)){
timer0--;
delay_ms(1);
if (timer0<61783){
timer0=61783;
delay_ms(1);
}
T=(((65535-timer0)*0.166)/1000000);
// T=T/1000000;
frecuenciamaf=(1/(T*2));
// frecuencia
IntToStr(frecuenciamaf, txt);
Lcd_out(2,1,Txt);
lcd_out(3,1,txt);
break;
if (Button(&PORTC,6,50,1))
{
switch (opcion3)
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,"TEST INYECTOR");
Lcd_Out(3,8,"ms PULSO");
TRISB.F0=0;
LATB.F0=0;
LATB.F0=0X00;
while(1) {
Vdelay_ms(frecuenciaabs);
// LATB.F0=~LATB.F0;
LATB.F0=0XFF;
Vdelay_ms(temp);
//LATB.F0=~LATB.F0;
LATB.F0=0X00;
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,200,1)&&(opcion3==1)){
temp++;
delay_ms(200);
if (temp>12){
temp =12;}
delay_ms(10);
if(Button(&PORTC,0,200,1)&& ( opcion3==1)){
temp--;
delay_ms(200);
if (temp<1){
temp=1;
delay_ms(1);
frecuenciaabs=(temp-25);
IntToStr(temp, txt);
Lcd_out(3,1,Txt);
break;
case 2:
Lcd_Cmd(_LCD_CLEAR);
TRISB.F0=0X00;
while(1){
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,6,100,1)&& (opcion3==2)){
contador=1; }
LATB.F0 = ~LATB.F0;
contador=0; }
break;
case 3:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,10,"V VOLTAJE");
Lcd_Out(3,10,"% APERTURA");
while(1){
voltaje= (ADC_Read(1)*0.0048875);
apertura=((voltaje*100)/5);
FloatToStr_FixLen(voltaje, txt,4);
Lcd_out(2,1,Txt);
FloatToStr_FixLen(apertura,txt,4);
Lcd_out(3,1,Txt);
delay_ms(100);
if (ADC_read(1)==0,0)
Lcd_out(3,1,"FALLA TPS");
else
lcd_out(3,1," ");
if (Button(&PORTC,7,50,1)) {
break; }
break;
case 4:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"HZ APROX");
TMR0H = (28000)>> 8;
TMR0L = 28000;
GIE_bit = 1;
TMR0IE_bit = 1;
timer0=28000;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,10,1)&&(opcion3==4)){
timer0+=100;
delay_ms(1);
if (timer0>60800){
timer0=60800;}
delay_ms(1);
if(Button(&PORTC,0,10,1)&& ( opcion3==4)){
timer0-=100;
delay_ms(1);
if (timer0<28000){
timer0=28000;
delay_ms(1);
T=(((65535-timer0)*1.3280)/1000000);
// T=T/1000000;
frecuenciaabs=(1/(T*2));
// frecuencia
FloatToStr_FixLen(frecuenciaabs, txt,4);
Lcd_out(2,1,Txt);
case 5:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"HZ APROX");
TMR0L = 28000;
GIE_bit = 1;
TMR0IE_bit = 1;
timer0=28000;
while(1) {
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,4,10,1)&&(opcion3==5)){
timer0+=100;
delay_ms(1);
if (timer0>60800){
timer0=60800;}
delay_ms(1);
if(Button(&PORTC,0,10,1)&& ( opcion3==5)){
timer0-=100;
delay_ms(1);
if (timer0<28000){
timer0=28000;
delay_ms(1);
T=(((65535-timer0)*1.3280)/1000000);
// T=T/1000000;
frecuenciaabs=(1/(T*2));
// frecuencia
FloatToStr_FixLen(frecuenciaabs, txt,4);
Lcd_out(2,1,Txt);
break;
case 6:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3,10,"V VOLTAJE");
while(1){
voltaje= (ADC_Read(1)*0.19550342);
FloatToStr_FixLen(voltaje, txt,6);
delay_ms(5);
Lcd_out(3,1,Txt);
if (Button(&PORTC,7,50,1)) {
break; }
break;
Lcd_Cmd(_LCD_CLEAR);
TRISB.F0=0X00;
while(1){
if (Button(&PORTC,7,50,1)) {
break; }
if (Button(&PORTC,6,100,1)&& (opcion3==7)){
contador=1; }
LATB.F0 = ~LATB.F0;
contador=0; }
}
break;
case 8:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,8,"V VOLTAJE");
Lcd_Out(3,8,"% PORCENTAJE");
ciclo3=0;
PWM2_init(4000);
PWM2_Start();
PWM2_Set_Duty(ciclo4);
while(1) {
if(Button(&PORTC,7,50,1)){
break; }
if(Button(&PORTC,4,10,1)&& (opcion3==8)){
ciclo4=ciclo4+1;
if (ciclo3==255){
ciclo4=255;}
}
if(Button(&PORTC,0,10,1)&& (opcion3==8)){
ciclo4=ciclo4-1;
if (ciclo4<0){
ciclo4=0;}
PWM2_Set_Duty(ciclo4);
voltaje= ((ciclo4)*0.0196);
apertura=((voltaje*100)/12);
FloatToStr_FixLen(voltaje,txt,4);
Lcd_out(2,1,Txt);
FloatToStr_FixLen(apertura,txt,4);
Lcd_out(3,1,Txt); }
break;
if (Button(&PORTC,7,50,1)) {
Lcd_Out(2,1,"SENSORES AUTOMOTRIZ");
Lcd_Out(3,3,"OPCION SIMULACION");
submenu = 0;
cursor = 1;
cursor2 = 1;
cursor3=1;
cursor4=1;
cursor5=1;
opcion=0;
opcion2=0;
opcion3=0;
opcion4=0;
opcion5=0;
opcion6=0;
cursor6=1;
cursor7=1;
cursor8=1;
cursor9=1;
cursor10=1;
opcion7=0;
opcion8=0;
opcion9=0;
opcion10=0;
ciclo1=0;
ciclo2=180;
ciclo3=0;
ciclo4=0;
T0CON.TMR0ON=0;
CCP1CON.CCP1M3=0;
CCP1CON.CCP1M2=0;
CCP1CON.CCP1M1=0;
CCP1CON.CCP1M0=0;
CCP2CON.CCP2M3=0;
CCP2CON.CCP2M2=0;
CCP2CON.CCP2M1=0;
CCP2CON.CCP2M0=0;
LATC.F2=0X00;
LATD.F2=0X00;
timer0=0;
contador=0;