Está en la página 1de 78

// DECLARACION CONSTANTES LCD 4X20

//Pines de salida para el LCD

sbit LCD_RS at RD1_bit;

sbit LCD_EN at RD0_bit;

sbit LCD_D7 at RD7_bit;

sbit LCD_D6 at RD6_bit;

sbit LCD_D5 at RD5_bit;

sbit LCD_D4 at RD4_bit;

sbit LCD_RS_Direction at TRISD1_bit;

sbit LCD_EN_Direction at TRISD0_bit;

sbit LCD_D7_Direction at TRISD7_bit;

sbit LCD_D6_Direction at TRISD6_bit;

sbit LCD_D5_Direction at TRISD5_bit;

sbit LCD_D4_Direction at TRISD4_bit;

// DECLARACION DE VARIABLES GLOBALES

// Cursores

char cursor, cursor2, cursor3, cursor4,cursor5,cursor6,cursor7,cursor8,cursor9;

char cursor10;

// opciones

char opcion,opcion2,opcion3 ,opcion4,opcion5 , opcion6,opcion7,opcion8,opcion9;

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;

// texto voltaje /apertura/ rpm simulacion

char txt[20];

// variable temperatura ECT y ms (ancho de pulso inyector)

int temp;

// variable para calcular tiemnpo en TMRO

float frecuenciaabs;

float frecuenciamaf;

int timer0;

int velocidad;

float T;

// variable contador para conteo pulsos de ckp cmp

char contador;

// variable calcular kpa sensor map


char kpa;

// FUNCION INTERRUPCION

void Interrupt(){

// Interrupcion timer0 para prueba de bobina

if ((TMR0IF_bit)&&(opcion3==4)) {

TMR0IF_bit = 0;

TMR0H = (timer0)>> 8;

TMR0L = (timer0);

LATB.F0=~LATB.F0;

// Interrupcion timer0 para prueba de bobina COP

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;

// interrupcion timer0 para cmp (800 hz a 2500 hz )

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;

// interrupcion timer0 para ckp hall 60-2

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;

// interrupcion timer0 CKP INDUCTIVO 40-1

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;

// interrupcion timer0 CKP INDUCTIVO 36-1

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;

// interrupcion timer0 CKP INDUCTIVO 60-2

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;

// interrupcion timer0 para maf digital

if ((TMR0IF_bit)&&(opcion7==1)){

TMR0IF_bit = 0;

TMR0H = (timer0)>> 8;

TMR0L = (timer0);

//Enter your code here

LATD.F2=~LATD.F2;

// interrupcion timer0 para ABS

if ((TMR0IF_bit)&&(opcion2==3)){
TMR0IF_bit = 0;

TMR0H = (timer0)>> 8;

TMR0L = (timer0);

//Enter your code here

LATD.F2=~LATD.F2;

// interrupcion timer0 para oxigeno digital 1khz

if ((TMR0IF_bit)&&(opcion6==1)){

TMR0IF_bit = 0;

TMR0H = (62533)>> 8;

TMR0L = (62533);

//Enter your code here

LATE.F1=~LATE.F1;

}
}

void main()

Lcd_Init(); //INICIALIZA LCD

Lcd_Cmd(_LCD_CLEAR); //LIMPIAR LCD

Lcd_Cmd(_LCD_CURSOR_OFF); //APAGAR CURSOR

// CONFIGURACION PUERTOS

// puertos no utilizados

// CONFIGURACION PUERTOS inyectores, bobinas

TRISB.F0=0;

LATB.F0=0;

TRISB.F1=0;

LATB.F1=0;

// CONFIGURACION PUERTOS OXIGENO DIGITAL


TRISE.F1=0;

LATE.F1=0;

// CONFIGURACION PUERTOS PULSADORES Y CCP1 CCP2

TRISC=0b11111001;

LATC=0b00000000;

// confuguracion de salida timer0

TRISD.F2=0X00; // SALIDAS CKP HALL , ABS , MAF ,CMP

LATD.F2=0X00;

TRISD.F3=0X00; // SALIDAS CKP INDUC

TRISD.F3=0X00;

// configuracion salida prueba inyector

TRISE.F0=0X00;

LATE.F0=0X00;

// configuracion de entradas analogicas

ADCON1.PCFG3=1; // an0,an1,an2 como pines de entrada analogicas , resto digit

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");

Lcd_Out(4,3,"OPCION TEST PRUEBA");

// CICLO WHILE

while (1)

// SI PULSO RC5 MUEVO CURSOR EN SUBMENU==0 (PANTALLA PRINCIPAL)

if (Button(&PORTC,5,50,1) && (submenu == 0))

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;

// SI PULSO RC6 (ENTER) ACCEDO A SUBMENUS DE PANTALLA PRINCIPAL

if (Button(&PORTC,6,50,1))

switch(opcion) // OPCION SIMULACION (SUBMENU=1)

case 1:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1, 2,"TPS");

Lcd_Out(2,2,"ECT");

Lcd_Out(3,2,"ABS");

Lcd_Out(4,2,"CKP CMP SINCRO");

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;

case 2: // SUBMENU PRUEBA (SUBMENU=2)

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;

// SI PULSO RC5 MUEVO CURSOR EN SUB MENU =1 ( SUBMENU SIMULACION)

if (Button(&PORTC,5,50,1) && (submenu == 1))

{
switch(cursor2)

case 1: //TPS

Lcd_Chr(1,1,'>');

Lcd_Chr (2,16,' ');

cursor2=2;

opcion2=1;

break;

case 2:

Lcd_Chr(1,1,' '); // ECT

Lcd_Chr(2,1,'>');

cursor2=3;

opcion2=2;

break;

case 3:

Lcd_Chr(2,1,' '); // ABS

Lcd_Chr(3,1,'>');

cursor2=4;

opcion2=3;

break;

case 4:

Lcd_Chr(3,1,' '); // CKP-CMP SINCRONIZADO

Lcd_Chr(4,1,'>');

opcion2=4;

cursor2=5;

break;
case 5:

Lcd_Chr(4,1,' '); // MAF

Lcd_Chr(1,6,'>');

opcion2=5;

cursor2=6;

break;

case 6:

Lcd_Chr(1,6,' '); // CKP

Lcd_Chr(2,6,'>');

opcion2=6;

cursor2=7;

break;

case 7:

Lcd_Chr(2,6,' '); // OXIGENO

Lcd_Chr(3,6,'>');

cursor2 = 8;

opcion2=7;

break;

case 8:

Lcd_Chr(3,6,' '); // MAP

Lcd_Chr(1,11,'>');

opcion2=8;

cursor2=9;

break;
case 9:

Lcd_Chr(1,11,' '); // CMP

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(3,11,' '); // IAT

Lcd_Chr(1,16,'>');

opcion2=2;

cursor2=12;

break;

case 12:

Lcd_Chr(1,16,' '); // VSS

Lcd_Chr(2,16,'>');

opcion2=3;

cursor2=1;

break;
}

// SI PULSO RC6 (ENTER) ACCEDO AL SUB MENU SIMULACION (SUBMENU=1)

if (Button(&PORTC,6,50,1))

switch (opcion2)

case 1:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIMULACION TPS"); // PANTALLA FINAL SIMULACION TPS

Lcd_Out(2,6,"% APERTURA");

Lcd_Out(3,6,"V VOLTAJE");

Lcd_Out(4,6,"RPM APROX");

// CODIGO EJECUCION DE SIMULACION TPS

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(1,1,"SIM IAT/ECT(NTC)"); // PANTALLA FINAL SIMULACION ECT

Lcd_Out(2,1,"39200 Ohms a 20C");

Lcd_Out(3,6,"V VOLTAJE");

Lcd_Out(4,6,"C TEMP APROX");

// CODIGO EJECUCION ECT

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

// 0.0196 = 5 voltios / 255 bits

// 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(1,1,"SIM ABS/VSS"); // PANTALLA FINAL SIMULACION ABS

Lcd_Out(2,6,"");

Lcd_Out(3,7,"K/M VELOCIDAD");

Lcd_Out(4,7,"HZ FRECUENCIA");

// CODIGO EJECUCION ABS

T0CON = 0x85;

TMR0H = (56100)>> 8;

TMR0L = 56100;

GIE_bit = 1;

TMR0IE_bit = 1;

timer0=56100;

while(1) {

// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de


Frecuencia

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(2,1,"SIMULACION CKP-CMP"); // PANTALLA FINAL SIMULACION ckp-cmp

Lcd_Out(3,3,"CKP EFECTO HALL");

Lcd_Out(4,3,"CKP INDUCTIVO");

submenu=3;

break;

case 5:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIMULACION MAF"); // PANTALLA OPCIONES SIMULACION MAF

Lcd_Out(3,3,"MAF DIGITAL");

Lcd_Out(4,3,"MAF ANALOGICO");

submenu=7;

break;

case 6 :

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIMULACION CKP"); // PANTALLA FINAL SIMULACION CKP

Lcd_Out(3,3,"EFECTO HALL");

Lcd_Out(4,3,"INDUCTIVO");
submenu=4;

break;

case 7 :

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIMULACION OXIGENO"); // PANTALLA FINAL SIMULACION OXIGEN

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(1,1,"SIMULACION S. MAP"); // PANTALLA FINAL SIMULACION MAP

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

// 0.0196 = 5 voltios / 255 bits

// 255*0.0196=5 voltios

voltaje= ((ciclo2)*0.0196);

FloatToStr_FixLen(voltaje,txt,4);

Lcd_out(2,1,Txt);

// calculo kpa

// 1 kpa= 0.024 voltios

kpa=(Voltaje/0.024);

FloatToStr_FixLen(kpa,txt,4);

Lcd_out(3,1,Txt);
}

break;

case 9:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIMULACION CMP"); // PANTALLA FINAL SIMULACION CMP

Lcd_Out(2,8,"HZ");

// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ

// CODIGO EJECUCION CMP DIGITAL ( frecuencia de 800hz a 2500hz )

T0CON = 0x80;

TMR0H = (61780)>> 8;

TMR0L = 61780;

GIE_bit = 1;

TMR0IE_bit = 1;

timer0=61780;

while(1) {

// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de


Frecuencia
// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(1,1,"SIMULACION KS"); // PANTALLA FINAL SIMULACION KS

Lcd_Out(2,7,"HZ FRECUENCIA");

// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ

// ( frecuencia de 800hz a 5khz )


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

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(1,1,"SIMULACION IAT"); // PANTALLA FINAL SIMULACION IAT

Lcd_Out(2,6,"C TEMPERATURA");

Lcd_Out(3,6,"V VOLTAJE");

break;

case 12:
Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIMULACION VSS"); // PANTALLA FINAL SIMULACION IAT

Lcd_Out(2,6,"K/H VELOCIDAD");

Lcd_Out(3,6,"HZ FRECUENCIA");

break;

// SI PULSRO RC5 MUEVO CURSOR EN SUB MENU=2 ( PRUEBA)

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:

Lcd_Chr(1,1,' '); // RELE


Lcd_Chr(2,1,'>');

opcion3=2;

cursor3=3;

break;

case 3:

Lcd_Chr(2,1,' '); // TPS

Lcd_Chr(3,1,'>');

opcion3=3;

cursor3=4;

break;

case 4:

Lcd_Chr(3,1,' '); // BOBINA

Lcd_Chr(4,1,'>');

opcion3=4;

cursor3=5;

break;

case 5:

Lcd_Chr(4,1,' '); // BOBINA IGT

Lcd_Chr(1,9,'>');

cursor3=6;

opcion3=5;

break;

case 6:

Lcd_Chr(1,9,' '); // VOLTIMETRO DC

Lcd_Chr(2,9,'>');
opcion3=6;

cursor3=7;

break;

case 7:

Lcd_Chr(2,9,' '); // SELENOIDE

Lcd_Chr(3,9,'>');

opcion3=7;

cursor3=8;

break;

case 8:

Lcd_Chr(3,9,' '); // POTENCIOMETRO

Lcd_Chr(4,9,'>');

cursor3=1;

opcion3=8;

break;

// SI PULSO RC5 MUEVO CURSOR EN SUBMENU DE SIMULACION CKP-CMP

if (Button (&PORTC,5,50,1)&& ( submenu==3))

switch ( cursor4){
case 1:

Lcd_Chr(3,2,'>'); // EFECTO HALL

Lcd_Chr(4,2,' ');

opcion4=1;

cursor4=2;

break;

case 2:

Lcd_Chr(3,2,' ');

Lcd_Chr(4,2,'>'); // EFECTO INDUCTIVO

opcion4=2;

cursor4=1;

break;

// SI PULSO RC5 MUEVO CURSOR EN SUB MENU DE CKP

if (Button(&PORTC,5,50,1)&&(submenu==4))

switch ( cursor8){

case 1:

Lcd_Chr(3,2,'>'); // EFECTO HALL

Lcd_Chr(4,2,' ');

opcion8=1;

cursor8=2;

break;
case 2:

Lcd_Chr(3,2,' '); // EFECTO INDUCTIVO

Lcd_Chr(4,2,'>');

opcion8=2;

cursor8=1;

break;

// SI PULSO RC5 MUEVO CURSOR EN SUB MENU DE OXIGENO

if (Button(&PORTC,5,50,1)&& (submenu==5))

switch ( cursor6){

case 1:

Lcd_Chr(3,2,'>'); // SEÑAL DIGITAL

Lcd_Chr(4,2,' ');

opcion6=1;

cursor6=2;

break;

case 2:

Lcd_Chr(3,2,' '); // SEÑAL ANALOGA

Lcd_Chr(4,2,'>');

opcion6=2;
cursor6=1;

break;

// SI PULSRO RC5 MUEVO CURSOR EN SUB MENU MAF

if (Button(&PORTC,5,50,1)&& (submenu==7))

switch ( cursor7){

case 1:

Lcd_Chr(3,2,'>'); // MAF DIGITAL

Lcd_Chr(4,2,' ');

opcion7=1;

cursor7=2;

break;

case 2:

Lcd_Chr(3,2,' '); // MAF ANALOGICO

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(3,1,' '); // 60-2

Lcd_Chr(4,1,'>');

opcion10=3;

cursor10=1;

break;
}

// SI PULSO RC5 MUEVO EL CURSOR EN EL SUB MENU(2) CKP HALL

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(3,1,' '); // 60-2

Lcd_Chr(4,1,'>');

opcion9=3;
cursor9=1;

break;

// SI PULSOR RC6 (ENTER) ACCEDO AL SUBMENU==5 ( SIM OXIGENO)

if (Button(&PORTC,6,50,1))

switch (opcion6)

case 1: //PANTALLA FINAL SIM OXIGENO DIGITAL

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIM OXIGENO DIG");

Lcd_Out(2,1,"1 kHZ FRECUENCIA");

Lcd_Out(3,7,"0-1 V VOLTAJE");

// CODIGO EJECUCION OXIGENO DIGITAL


T0CON = 0x80;

TMR0H = (62533)>> 8;

TMR0L = 62533;

GIE_bit = 1;

TMR0IE_bit = 1;

break;

case 2: // PANTALLA FINAL SIM OXIGENO ANALOGA

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIM OXIG ANALOGICO"); // PANTALLA FINAL OXIGENO ANALOGICO

Lcd_Out(2,7,"V VOLTAJE ");

Lcd_Out(3,1," ");

Lcd_Out(4,6," ");

// CODIGO EJECUCION OXIGENO ANALOGICO

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

// 0.0196 = 5 voltios / 255 bits

// 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;
}

// SI PULSO RC6 ( ENTER ) ACCEDO AL SUBMENU==7 ( MAF-DIGITAL-ANALOGICO)

if (Button(&PORTC,6,50,1))

switch (opcion7)

case 1:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"SIM MAF DIGITAL"); // PANTALLA FINAL SIMULACION MAF DIG

Lcd_Out(2,7,"HZ FRECUENCIA");

Lcd_Out(3,1," ");

Lcd_Out(4,6," ");

// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ


// CODIGO EJECUCION MAF DIGITAL ( frecuencia de 10hz a 5khz )

T0CON = 0x83;

TMR0H = (28019)>> 8;

TMR0L = 28019;

GIE_bit = 1;

TMR0IE_bit = 1;

timer0=28020;

while(1) {

// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de


Frecuencia

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(1,1,"SIM MAF ANALOGICO"); // PANTALLA FINAL SIMULACION MAF ANALOGICO

Lcd_Out(2,7,"V VOLTAJE ");

Lcd_Out(3,1," ");

Lcd_Out(4,6," ");

// CODIGO EJECUCION MAF ANALOGICO

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

// 0.0196 = 5 voltios / 255 bits

// 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;

// SI PULSO RC6 (ENTER) ACCEDO AL SUBMENU==4 ( SIM CKP )

if (Button(&PORTC,6,50,1))

{
switch (opcion8)

case 1:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"CKP EFECTO HALL "); // PANTALLA SELECCION OPCIONES SIM CKP

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(1,1,"CKP INDUCTIVO"); // PANTALLA SELECCION OPCIONES SIM CKP

Lcd_Out(2,2,"40-1");

Lcd_Out(3,2,"36-1");

Lcd_Out(4,2,"60-2");

submenu=9;

break;

// SI PULSO RC6 (ENTER) ACCEDO AL SUBMENU==8 (SIM CKP HALL)


if (Button(&PORTC,6,50,1))

switch (opcion9)

case 1:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"CKP EFECTO HALL 40-1"); // PANTALLA FINAL CKP HALL 40-1

Lcd_Out(2,8,"RPM");

Lcd_Out(3,8,"HZ FRECUENCIA");

opcion9=1;

// CODIGO EJECUCION CKP HALL 40-1

// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ

// ( frecuencia de 800hz a 5khz )

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

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(1,1,"CKP EFECTO HALL 36-1"); // PANTALLA FINAL CKP HALL 36-1

Lcd_Out(2,8,"RPM");

Lcd_Out(3,8,"HZ FRECUENCIA");

// CODIGO EJECUCION CKP HALL 36-1


// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ

// ( frecuencia de 800hz a 5khz )

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

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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");

// CODIGO EJECUCION CKP HALL 60-2

// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ

// ( frecuencia de 800hz a 5khz )

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

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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;

// SI PULSOR RC6 (ENTER) SUBMENU==9 ACCEDO AL SIM CKP INDUCTIVO

if (Button(&PORTC,6,50,1))

switch (opcion10)

case 1:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"CKP INDUCTIVO 40-1");// PANTALLA FINAL CKP HALL 40-1

Lcd_Out(2,8,"RPM");

Lcd_Out(3,8,"HZ FRECUENCIA");

// CODIGO EJECUCION CKP INDUCTIVO 40-1

// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ

// ( frecuencia de 800hz a 5khz )


T0CON = 0x80;

TMR0H = (61783)>> 8;

TMR0L = 61783;

GIE_bit = 1;

TMR0IE_bit = 1;

contador=0;

LATD.F3=0X00;

timer0=61783;

while(1) {

// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de


Frecuencia

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(1,1,"CKP INDUCTIVO 36-1"); // PANTALLA FINAL CKP INDU 36-1

Lcd_Out(2,8,"RPM");

Lcd_Out(3,8,"HZ FRECUENCIA");

// CODIGO EJECUCION INDUCTIVO 36-1

// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ

// ( frecuencia de 800hz a 5khz )

T0CON = 0x80;

TMR0H = (61783)>> 8;

TMR0L = 61783;

GIE_bit = 1;

TMR0IE_bit = 1;

contador=0;

LATD.F3=0X00;

timer0=61783;

while(1) {

// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de


Frecuencia
// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(1,1,"CKP INDUCTIVO 60-2"); //PANTALLA FINAL CKP INDU 36-1

Lcd_Out(2,8,"RPM");

Lcd_Out(3,8,"HZ FRECUENCIA");

// CODIGO EJECUCION CKP INDUCTIVO 60-2

// PREESCALE 2 FRECUENCIA RELOJ INTERNO 48MHZ

// ( frecuencia de 800hz a 5khz )

T0CON = 0x80;

TMR0H = (61783)>> 8;

TMR0L = 61783;

GIE_bit = 1;

TMR0IE_bit = 1;

contador=0;

LATD.F3=0X00;

timer0=61783;
while(1) {

// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de


Frecuencia

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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;

// SI PULSOR RC6 (ENTER) ACCESO AL SUBMENU PRUEBA

if (Button(&PORTC,6,50,1))
{

switch (opcion3)

case 1: // PANTALLA FINAL PRUEBA INYECTOR

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,2,"TEST INYECTOR");

Lcd_Out(2,2,"40HZ 4000 RPM APROX");

Lcd_Out(3,8,"ms PULSO");

TRISB.F0=0;

LATB.F0=0;

// CODIGO EJECUCION PRUEBA DE INYECTORES

temp=1; // ancho de pulso

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);

Lcd_Out(1,2,"TEST RELE"); // PANTALLA FINAL PRUEBA RELE

Lcd_Out(2,2,"PULSE TECLA ENTER");

TRISB.F0=0X00;

// codigo ejecucion prueba rele

while(1){

if (Button(&PORTC,7,50,1)) {

break; }

if (Button(&PORTC,6,100,1)&& (opcion3==2)){

contador=1; }

if ( contador && Button(&PORTC,6,100,0)) {

LATB.F0 = ~LATB.F0;

contador=0; }

break;

case 3:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,2,"TEST TPS"); // PANTALLA FINAL PRUEBA TPS

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(1,2,"TEST BOBINA"); // PANTALLA FINAL PRUEBA BOBINA

Lcd_Out(2,8,"HZ APROX");

// CODIGO EJECUCION BOBINA


T0CON = 0x83; // preescale 1:16

TMR0H = (28000)>> 8;

TMR0L = 28000;

GIE_bit = 1;

TMR0IE_bit = 1;

timer0=28000;

while(1) {

// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de


Frecuencia

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(1,2,"TEST BOBINA COP"); // PANTALLA FINAL PRUEBA BOBINA COP

Lcd_Out(2,8,"HZ APROX");

// CODIGO EJECUCION BOBINA

T0CON = 0x83; // preescale 1:16


TMR0H = (28000)>> 8;

TMR0L = 28000;

GIE_bit = 1;

TMR0IE_bit = 1;

timer0=28000;

while(1) {

// temporizacion = Temporización = Ciclo de instrucción * (65535-TMR0) * Divisor de


Frecuencia

// 65535-TMR0 = Temporización(en microsegundos)/(1 ciclo/us * Div. de Frec.)

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(1,2,"VOLTIMETRO"); // PANTALLA FINAL voltimetro dc 150 v

Lcd_Out(2,2,"MAXIMO 150V DC ");

Lcd_Out(3,10,"V VOLTAJE");

lcd_Out(4,1,"SOLO VOLTAJE DC");

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;

case 7: // PANTALLA FINAL prueba selenoide

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,2,"TEST SELENOIDE"); // PANTALLA FINAL PRUEBA SELENOIDE

Lcd_Out(2,2,"PULSE TECLA ENTER");

TRISB.F0=0X00;

// codigo ejecucion pruebA SELENOIDE

while(1){

if (Button(&PORTC,7,50,1)) {

break; }

if (Button(&PORTC,6,100,1)&& (opcion3==7)){

contador=1; }

if ( contador && Button(&PORTC,6,100,0)) {

LATB.F0 = ~LATB.F0;

contador=0; }
}

break;

case 8:

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,2,"POTENCIOMETRO 12V"); // PANTALLA FINAL PRUEBA SELENOIDE

Lcd_Out(2,8,"V VOLTAJE");

Lcd_Out(3,8,"% PORCENTAJE");

ciclo3=0;

// CODIGO EJECUCION POTENCIOMETRO

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;

// SI PULSO RC7 ME DEVUELVO A MENU PRINCIPAL ( SUBMENU=0)

if (Button(&PORTC,7,50,1)) {

Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen


Lcd_Out(1,1,"SIMULADOR-PRUEBA DE");

Lcd_Out(2,1,"SENSORES AUTOMOTRIZ");

Lcd_Out(3,3,"OPCION SIMULACION");

Lcd_Out(4,3,"OPCION TEST PRUEBA");

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;

También podría gustarte