#include <12F508.h>
#FUSES NOWDT,NOMCLR //No Watch Dog Timer
#FUSES NOPROTECT // codigo protegido
//#use delay(crystal=4000000) // oscilador con cristal
#use delay(internal=4000000) // oscilador interno
#DEFINE SW pin_B4 // le doy un nombre al pin
#define buzzer PIN_B2
#ORG 0x50, 0X01FF // proteger el codigo a partir de la linea 50
#BYTE PORTB=0X06 // lugar de memoria del puerto A ( muy importante )
#USE FAST_IO (B) // Optimizamos E/S del PORTB ( muy importante para ahorrar memoria )
int16 i;
// prototipos funciones
void sonido ();
//xxxxxxxxxxxxxxxxxxxxxxxxx
// funciones
void sonido()
{
for (i=0;i<250;i++) // 2,457 khz
{
output_high(buzzer);
delay_us(280);
output_low(buzzer);
delay_us(110);
}
i=0;
delay_ms(1000); //1 bip x segundo apx
}
// fin funciones
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void main()
{
//////// configura Gp2 como i/s digital y desabilita el tocki (ocs bit-5)
#asm
movlw (0B11000000); GPWU = 1, GPPU = 1, T0CS, T0SE, PSA, PS2, PS1, PS0 = 0
option
#endasm
/////////////////////////////////////////////////////////////////////////////
SET_TRIS_B(0B011010); //set_options (0B000000);
PORTB=0; // limpio el puerto
//Example buzzer
while(true)
{
while (input(SW))// si es uno llamo función sonido
{
sonido();
}
}
}