Sei sulla pagina 1di 3

/*

* File: CONTADOR_2.c
* Author: CHRISTIAN
*
* Created on 1 de noviembre de 2019, 05:54 PM
*/

//#include <pic18f4553.h>

#include "CONFI.h"
#define _XTAL_FREQ 20000000
#include <adconv.h>
#define condicion PORTBbits.RB1
#define pausa PORTBbits.RB0

void contador(int j,int b);


int tiempo ();

void main(void) {

TRISD = 0;
TRISC = 0;
TRISB = 255;
TRISA = 255;
Config_ADC('R',20,2);
int x=0,y=0,t=0;

if ( condicion == 0)
{
x=0,y=0;
}
else
{
x=9,y=9;
}
while (1)
{
// Condicion del contador ascendente

if (condicion == 0)
{

if(x==10)
{ x=0;}

contador(x,y);

if(x==9)
{ y=y+1;}

if(y==10)
{ y=0;}

// El contador se pone en pausa

if (pausa == 0)
{x=x;}
if (pausa == 1)
{x=x+1;}

// Condicion del contador descendente

if (condicion == 1)
{
if(x==-1)
{ x=9;}

contador(x,y);

if(x==0)
{ y=y-1;}

if(y==-1)
{ y=9;}

// El contador se pone en pausa

if (pausa == 0)
{x=x;}

if (pausa == 1)
{x=x-1;}

}
}
return;
}

void contador (int j,int b)


{
int vec[]={63,6,91,79,102,109,125,7,127,103};
int i,h;

h = tiempo ();

for(i=0;i< h;i=i+1)
{
// Contola unidades
__delay_ms(10);
PORTC = 0b11111110;
PORTD = vec[j];

// Controla decenas

__delay_ms(10);
PORTC = 0b11111101;
PORTD = vec[b];

}
}
int tiempo ()
{
float entrada = 0 ;
int t;
entrada = Valor_ADC(1);

if (entrada < 819)


{
t=10;
}

if ( entrada < 1638 & entrada >= 819)


{
t=20;
}

if (entrada < 2457 & entrada >= 1638)


{
t=30;
}

if (entrada < 3276 & entrada >= 2457)


{
t=40;
}

if (entrada >= 3276)


{
t=50;
}
return t;

Potrebbero piacerti anche