#include <16F88.h>
#device adc = 8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for #FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOFCMEN //Fail-safe clock monitor enabled
#FUSES NOIESO //Internal External Switch Over mode enabled
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay ( clock = 4000000 )
#use rs232 ( baud = 9600 , parity = N , xmit = PIN_B5 , rcv = PIN_B2 , bits = 8 )
#BYTE TRISB = 0x86
#BYTE PORTB = 0x06
#BYTE TRISA = 0x85
#BYTE PORTA = 0x05
int16 tiempoalto ;
int16 tiempobajo = 0x4A38 ;
int16 potencia = 0x00 ;
#int_RDA
void RDA_isr ( void )
{
tiempobajo = potencia * 78 ;
if ( tiempobajo > 19400 ){
tiempobajo = 19400 ;
}
tiempoalto = 19400 - tiempobajo ;
}
void main ()
{
setup_adc_ports ( NO_ANALOGS | VSS_VDD );
setup_adc ( ADC_CLOCK_DIV_2 );
//setup_spi(SPI_SS_DISABLED);
setup_timer_0 ( RTCC_INTERNAL | RTCC_DIV_1 );
setup_timer_1 ( T1_DISABLED );
setup_timer_2 ( T2_DISABLED , 0 , 1 );
setup_comparator ( NC_NC_NC_NC );
setup_vref ( FALSE );
enable_interrupts ( INT_RDA );
enable_interrupts ( GLOBAL );
bit_set ( TRISB , 7 ); //B7 como entrada
bit_clear ( TRISB , 6 ); //B6 como salida
while ( true ){
if ( bit_test ( PORTB , 7 ) == 1 ){
bit_clear ( PORTB , 6 );
delay_us ( tiempobajo );
bit_set ( PORTB , 6 );
delay_us ( tiempoalto );
}
}
}