Sei sulla pagina 1di 3

#INCLUDE <16F877A.

H>
#USE DELAY(CLOCK=20M)
#FUSES HS,NOWDT,NOPROTECT
#use rs232(baud=9600, xmit=pin_C6, rcv=pin_c7, bits=8, parity=N)
/*#define PCF_SDA PIN_C4
#define PCF_SCL PIN_C3
#use i2c(master, sda=PCF_SDA, scl=PCF_SCL)
#define PCF_ID 7
#define PCF 64 // Puede ser 112 � 64 (PCF8574T=64, PCF8574A=112, PCF8574=64)
#define blacking P3
#define LCD_RS P0
#define LCD_RW P1
#define LCD_E P2
#define LCD_DB4 P4
#define LCD_DB5 P5
#define LCD_DB6 P6
#define LCD_DB7 P7
#include <lcd_pcf.c>*/
#byte port_a=5
#byte port_b=6
#byte port_c=7
#byte port_d=8
#byte port_e=9
#USE FAST_IO (b)
char ch;
float a1,a2;
#INT_RDA
void rda_isr()
{
ch = getchar();
}
void automatico2()
{
set_adc_channel(1);
delay_ms(1);
a2=read_adc();
delay_ms(20);
/*clear_lcd();
lcd_gotoxy (1,1);
lcd_putc("MEDICIONES");
lcd_gotoxy (1,2);
printf(lcd_putc,"%f",a1);*/
if (a2>=48)
{
if(a2>=56)
{
port_b=(96);
}
else
{
port_b=(80);
}
}
else
{
port_b=(144);
}
}
void automatico()
{
set_adc_channel(0);
delay_ms(1);
a1=read_adc();
delay_ms(20);
/*clear_lcd();
lcd_gotoxy (1,1);
lcd_putc("MEDICIONES");
lcd_gotoxy (1,2);
printf(lcd_putc,"%f",a1);*/
if (a1>=76)
{
if(a1>=85)
{
port_b=(144);
}
else
{
port_b=(80);
}
}
else
{
port_b=(96);
}
}
VOID MAIN ()
{
SET_TRIS_b (0X00);
port_b=(0X00);
//lcd_init();
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
//lcd_gotoxy(1,1);
//lcd_putc("HOLA MUNDO QUE TAL");
port_b=(8);
while (true)
{
if (!ch==0)
{
//lcd_putc ("\f");
switch (ch)
{
case 'i':
//lcd_gotoxy(1,2);
//lcd_putc("i");
port_b=(80);
break;
case 'k':
//lcd_gotoxy(1,2);
//lcd_putc("k");
port_b=(160);
break;
case 'j':
//lcd_gotoxy(1,2);
//lcd_putc("j");
port_b=(96);
break;
case 'l':
//lcd_gotoxy(1,2);
//lcd_putc("l");
port_b=(144);
break;
case 'h':
//lcd_gotoxy(1,2);
//lcd_putc("h");
port_b=(0);
break;
case 'c':
automatico2();
break;
case 'd':
automatico();
break;
default:
//lcd_putc("NADA");
break;
}
}
}
}

Potrebbero piacerti anche