Programa con PIC 18f4550 para taximetro

disculpe alguien me puede ayudar a hacer un programa con el pic 18f4550 sobre un taximetro :
tiene que llevar:
1. el taxmetro cuanta con un display para mostrar el monto a pagar
2. tien un boton de inicio
3. tiene un boton de paro
4. tiene un switch para la tarifa (T1=diurno, T2=nocturno)

al iniciar el taximetro, el monto inicial a pagar es de acuerdo al turno:
a. T1= $6.90
b. T2= $7.50

el importe se incrementara en $0.95para T1 y en $1.05 para T2 las dos siguientes condiciones:
a. se cumplan 45 segundos de tiempo, o
b. se recorra 250 metros de distancia


POR FAVOR AYUDENME PORQUE YA ME CONFUNDÍ DEMASIADO CON ESTE PROGRAMA...

ESTE ES EL CODIGO QUE TENGO...

Código:
#include <18F4550.h>
#device adc=8
#FUSES NOWDT                       //No Watch Dog Timer
#FUSES WDT128                      //Watch Dog Timer uses 1:128 Postscale
#FUSES INTHS                       //Internal Oscillator, HS used by USB
#FUSES NOPROTECT                   //Code not protected from reading
#FUSES BROWNOUT                    //Reset when brownout detected
#FUSES BORV46                      //Brownout reset at 4.6V
#FUSES PUT                         //Power Up Timer
#FUSES NOCPD                       //No EE protection
#FUSES STVREN                      //Stack full/underflow will cause reset
#FUSES NODEBUG                     //No Debug mode for ICD
#FUSES NOLVP                       //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                       //Program memory not write protected
#FUSES NOWRTD                      //Data EEPROM not write protected
#FUSES IESO                        //Internal External Switch Over mode enabled
#FUSES FCMEN                       //Fail-safe clock monitor enabled
#FUSES NOPBADEN                    //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                      //configuration not registers write protected
#FUSES NOWRTB                      //Boot block not write protected
#FUSES NOEBTR                      //Memory not protected from table reads
#FUSES NOEBTRB                     //Boot block not protected from table reads
#FUSES NOCPB                       //No Boot Block code protection
#FUSES MCLR                        //Master Clear pin enabled
#FUSES NOLPT1OSC                   //Timer1 configured for higher power operation
#FUSES NOXINST                     //Extended set extension and Indexed Addressing mode disabled 
#FUSES PLL2                        //Divide By 2(8MHz oscillator input)
#FUSES CPUDIV4                     //System Clock by 4
#FUSES NOUSBDIV                    //USB clock source comes from primary oscillator
#FUSES NOVREGEN                    //USB voltage regulator disabled
#FUSES ICPRT                       //ICPRT enabled
#use delay(internal=8000000)
#include <lcd.c>
#define LCD_TYPE 2

int tiempo;
float pago,presio,distansia;

#int_RTCC
void  RTCC_isr(void) 
{
set_timer0(0);
tiempo++;
      if (tiempo>=45)
      {
         pago+=presio;
         tiempo=0;
         distansia=0;
      }
}

#int_EXT1
void  EXT1_isr(void) 
{
 distansia+=0.483; //rin  15 con  cuatro sensores
       if (distansia>=250)
      {
         pago+=presio;
         set_timer0(0);
         tiempo=0;
         distansia=0;
      }
}
void main()
{
   lcd_init();

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   lcd_init();
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT1);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
    
   set_tris_a(0xff);
   set_tris_b(0xff);
    
  lcd_putc("Importe a Pagar:\n           pesos ");
    
   while(true)
   {
   
  
   
   
      
      if(input(pin_a1))
      {                       //inisio
      tiempo=0;
      distansia=0;
      set_timer0(0);
      
      
      
       
      if(input(pin_a0))
      {
      presio=0.95;                   //diurno
      pago=6.90;
      }
      
      if(!input(pin_a0))            //nocturno
      {
      presio=1.05;
      pago=7.50;
      
      }
      }

      
      if(input(pin_a2))          //fin
      
      {
      set_timer0(0);
      presio=0;
      
      
      }
      
       
       lcd_gotoxy(1,2);
       printf(lcd_putc,"$%f ",pago);   


      
   }
}

Y ESE ES EL CIRCUITO...
 

Adjuntos

  • 00000001.png
    00000001.png
    24.2 KB · Visitas: 68
Última edición por un moderador:
por lo que veo tu programa cobra el tiempo de espera siempre, y no cuando el vehiculo esta detenido... generalmente la formula para esto es k que es una constante y distancia/tiempo para sacar la velocidad de cruce, busca velocidad de cruce en google y se explica a la perfeccion. yo en un tiempo tambien quiero desarrollar algo parecido pero con un pic18f26j50.

salu2
 
Atrás
Arriba