Está en la página 1de 22

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

// opciones

char opcion,opcion2,opcion3 ,opcion4,opcion5 , opcion6;

//menu

char submenu;

// ciclo trabajo

char ciclo1;
// valor de voltaje

float voltaje;

// valor de Apertura

float apertura;

// valor rpm

float rpm;

// texto voltaje /apertura/ rpm simulacion

unsigned char txt1[6], txt2[6],txt3[6];

void main()

Lcd_Init(); //INICIALIZA LCD

Lcd_Cmd(_LCD_CLEAR); //LIMPIAR LCD

Lcd_Cmd(_LCD_CURSOR_OFF); //APAGAR CURSOR

// CONFIGURACION PUERTOS

LATC=0; // puerto c , cero logico

TRISC=0x11111001; // congiguracion puertoC

INTCON2.F7=1; //

// DECLARACION DE VARIABLES
cursor = 1;

submenu = 0;

cursor2 = 1;

cursor3=1;

cursor4=1;

opcion=0;

opcion2=0;

opcion3=0;

opcion4=0;

opcion5=0;

cursor5=1;

cursor6=1;

opcion6=0;

ciclo1=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,100,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,100,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,"TPS");

Lcd_Out(2,2,"MAP");

Lcd_Out(3,2,"MAF");

Lcd_Out(4,11,"SIGUIENTE");

Lcd_Out(1,7,"IAT");

Lcd_Out(2,7,"ECT");

Lcd_Out(3,7,"CKP");

Lcd_Out(1,12,"CMP");
Lcd_Out(2,12,"ABS");

Lcd_Out(3,12,"EGR");

Lcd_Out(1,17,"APP");

Lcd_Out(2,17,"KNOC");

Lcd_Out(3,17,"VSS");

submenu = 2;

break;

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

if (Button(&PORTC,5,100,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=11;

cursor2=12;

break;

case 12:

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

Lcd_Chr(2,16,'>');

opcion2=12;

cursor2=1;

break;

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

if (Button(&PORTC,6,100,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(2000);

PWM1_Start();

PWM1_Set_Duty(ciclo1);

while(1) {

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

break; }

if(Button(&PORTC,4,100,1)&& (opcion2==1)){

ciclo1++;

PWM1_Set_Duty(ciclo1);

delay_ms(10);

// voltaje

voltaje= 0.0196*(ciclo1);

FloatToStr_FixLen(voltaje,txt1,4);

Lcd_out(3,1,Txt1);

// apertura

apertura=(ciclo1)*100 / 255;

FloatToStr_FixLen(apertura,txt2,4);

Lcd_out(2,1,Txt2);
// RPM

rpm=23.5294*(ciclo1);

FloatToStr_FixLen(rpm,txt3,4);

Lcd_out(4,1,Txt3);

if(Button(&PORTC,0,100,1)&& (opcion2==1)){

ciclo1--;

PWM1_Set_Duty(ciclo1);

delay_ms(10);

//voltaje

voltaje= 0.0196*(ciclo1);

FloatToStr_FixLen(voltaje,txt1,4);

Lcd_out(3,1,Txt1);

//apertura

apertura=(ciclo1)*100 / 255;

FloatToStr_FixLen(apertura,txt2,4);

Lcd_out(2,1,Txt2);

// RPM

rpm=23.5294*(ciclo1);

FloatToStr_FixLen(rpm,txt3,4);

Lcd_out(4,1,Txt3);

}
}

break;

case 2:

Lcd_Cmd(_LCD_CLEAR);

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

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

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

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

break;

case 3:

Lcd_Cmd(_LCD_CLEAR);

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

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

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

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 FINAL SIMULACION MAF

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

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

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,"MEZCLA POBRE");

Lcd_Out(4,3,"MEZCLA RICA");

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

Lcd_Out(4,6,"Kpa");

break;

case 9:

Lcd_Cmd(_LCD_CLEAR);

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

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

Lcd_Out(3,6,"RPM");

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

break;

case 10:

Lcd_Cmd(_LCD_CLEAR);

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

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

Lcd_Out(3,6,"RPM");

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

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 (SUBMENU PRUEBA)

if (Button(&PORTC,5,100,1)&& ( submenu==2))

switch (cursor3){

case 1:

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

Lcd_Chr(3,16,' ');

opcion3=1;

cursor3=2;

break;

case 2:

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

Lcd_Chr(2,1,'>');
opcion3=2;

cursor3=3;

break;

case 3:

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

Lcd_Chr(3,1,'>');

opcion3=3;

cursor3=4;

break;

case 4:

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

Lcd_Chr(4,10,'>');

opcion3=4;

cursor3=5;

submenu=6;

break;

case 5:

Lcd_Chr(4,10,' '); // IAT

Lcd_Chr(1,6,'>');

cursor3=6;

opcion3=5;

break;

case 6:

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

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

cursor3=7;

break;

case 7:

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

Lcd_Chr(3,6,'>');

opcion3=7;

cursor3=8;

break;

case 8:

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

Lcd_Chr(1,11,'>');

cursor3=9;

opcion3=8;

break;

case 9:

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

Lcd_Chr(2,11,'>');

opcion3=9;

cursor3=10;

break;

case 10:

Lcd_Chr(2,11,' '); // EGR

Lcd_Chr(3,11,'>');

opcion3=10;
cursor3=11;

break;

case 11:

Lcd_Chr(3,11,' '); // APP

Lcd_Chr(1,16,'>');

opcion3=11;

cursor3=12;

break;

case 12:

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

Lcd_Chr(2,16,'>');

opcion3=12;

cursor3=13;

break;

case 13:

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

Lcd_Chr(3,16,'>');

opcion3=13;

cursor3=1;

break;

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


if (Button (&PORTC,5,100,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,100,1)&&(submenu==4))

switch ( cursor5){

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

Lcd_Chr(4,2,' ');

opcion5=1;

cursor5=2;

break;

case 2:

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

Lcd_Chr(4,2,'>');

opcion5=2;

cursor5=1;

break;

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

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

switch ( cursor6){

case 1:

Lcd_Chr(3,2,'>'); // MEZCLA POBRE

Lcd_Chr(4,2,' ');

opcion6=1;

cursor6=2;

break;
case 2:

Lcd_Chr(3,2,' '); // MEZCLA RICA

Lcd_Chr(4,2,'>');

opcion6=2;

cursor6=1;

break;

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

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

if (Button(&PORTC,7,100,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");

cursor = 1;

submenu = 0;

cursor2 = 1;

cursor3=1;
cursor4=1;

cursor5=1;

opcion=0;

opcion2=0;

opcion3=0;

opcion4=0;

opcion5=0;

opcion6=0;

cursor6=1;

Delay_ms(300);

ciclo1=0;

PWM1_Stop();

También podría gustarte