#include<16f88.h>
#device adc =10
#use delay (clock=4M)
#fuses XT,NOWDT
#include <lcd.c>
int16 calculoBandaEr(int16 cero,int16 toper);
int16 z=0, a=0,b=0,c=0,d=0,e=0,f=0;
int16 calculoBandaBr(int16 cero, int16 topbr);
int16 g=0,h=0,i=0,j=0,k=0,l=0,m=0;
int16 cursor=0,toper=0,topbr=0,cero=0;
int16 resultadoEr =0,resultadoBr =0;
void main()
{
setup_adc_ports (sAN0|sAN1|sAN2|sAN3|VSS_VDD);
setup_adc (ADC_CLOCK_DIV_8);
set_tris_a(0b00001111);
//*************************************************************************
set_adc_channel (3);
delay_us (20);
cero = read_adc();
//***************************************************************************
set_adc_channel (0);
delay_us (20);
topbr = read_adc ();
resultadoBr = calculoBandaBr(topbr,cero);//( topbr -cero ) / 8;
g = resultadoBr + cero;
h =cero+resultadoBr+resultadoBr;
i =cero+(resultadoBr*3);
j =cero+(resultadoBr*4);
k =cero+(resultadoBr*5);
l =cero+(resultadoBr*6);
m =cero+(resultadoBr*7);
set_adc_channel (1);
delay_us (20);
toper = read_adc ();
resultadoEr = calculoBandaEr (cero, toper);
z= resultadoEr + toper;
a = (resultadoEr * 3)+toper;
b =( resultadoEr * 4)+toper;
c =( resultadoEr * 5)+toper;
d =( resultadoEr * 6)+toper;
e =( resultadoEr * 7)+toper;
f =( resultadoEr * 8)+toper;
lcd_init ();
WHILE (1) {
//*********************************************************
set_adc_channel (2);
delay_us (20);
cursor = read_adc ();
//*********************************************
IF (cursor >0 && cursor<= toper)
{
// output_high (PIN_a3); //led************************
lcd_gotoxy (1,1) ;
printf (lcd_putc, " 40\337er top ");
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " |>>>>>>>>");
}
IF (cursor > toper && cursor <=z)
{
lcd_gotoxy (1,1) ;
printf (lcd_putc, " 35\337er ");
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " |>>>>>>>>");
}
IF (cursor >z && cursor <a)
{
lcd_gotoxy (1, 1) ;
printf (lcd_putc, " 30\337er ") ;
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " |>>>>>>> ");
}
IF (cursor >a &&cursor<b)
{
lcd_gotoxy (1, 1) ;
printf (lcd_putc, " 25\337er ") ;
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " |>>>>>> ");
}
IF (cursor >b && cursor<c)
{
lcd_gotoxy (1, 1) ;
printf (lcd_putc, " 20\337er ") ;
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " |>>>>> ");
}
IF (cursor >c && cursor<d)
{
lcd_gotoxy (1, 1) ;
printf (lcd_putc, " 15\337er ");
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " |>>> ");
}
IF (cursor >d && cursor<e)
{
lcd_gotoxy (1, 1) ;
printf (lcd_putc, " 10\337er ");
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " |>> ") ;
}
IF (cursor>e&&cursor<f)
{
lcd_gotoxy (1, 1) ;
printf (lcd_putc, " 5\337er ");
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " |> ");
}
//*****************************************************************************
IF (cursor == cero)
{
lcd_gotoxy (1, 1) ;
printf (lcd_putc, " 0 ");
lcd_gotoxy (1, 2) ;
printf (lcd_putc, " | ");
}
//*****************************************************************************
if (cursor>cero&&cursor<g)
{
lcd_gotoxy(1,1);
printf(lcd_putc," 5\337br ");
lcd_gotoxy(1,2);
printf(lcd_putc," <| ");
}
if (cursor>g&&cursor<h)
{
lcd_gotoxy(1,1);
printf(lcd_putc," 10\337br ");
lcd_gotoxy(1,2);
printf(lcd_putc," <<| ");
}
if (cursor>h&&cursor<i)
{
lcd_gotoxy(1,1);
printf(lcd_putc," 15\337br ");
lcd_gotoxy(1,2);
printf(lcd_putc," <<<| ");
}
if (cursor>i&&cursor<j)
{
lcd_gotoxy(1,1);
printf(lcd_putc," 20\337br ");
lcd_gotoxy(1,2);
printf(lcd_putc," <<<<| ");
}
if (cursor>j&&cursor<k)
{
lcd_gotoxy(1,1);
printf(lcd_putc," 25\337br ");
lcd_gotoxy(1,2);
printf(lcd_putc," <<<<<| ");
}
if (cursor>k&&cursor<l)
{
lcd_gotoxy(1,1);
printf(lcd_putc," 30\337br ");
lcd_gotoxy(1,2);
printf(lcd_putc," <<<<<<| ");
}
if (cursor>l&&cursor<m)
{
lcd_gotoxy(1,1);
printf(lcd_putc," 35\337br ");
lcd_gotoxy(1,2);
printf(lcd_putc,"<<<<<<<| ");
}
if (cursor>m&&cursor<=topbr)
{
// output_high(PIN_a4);//led************************
lcd_gotoxy(1,1);
printf(lcd_putc,"top 40\337br ");
lcd_gotoxy(1,2);
printf(lcd_putc,"<<<<<<<| ");
}
}
}
//funciones*********************************************
int16 calculoBandaEr(int16 cero, int16 toper)
{
RETURN (cero - toper) / 8;
}
int16 calculoBandaBr(int16 topbr,int16 cero )
{
RETURN ( topbr -cero ) / 8;
}