69 lines
1.4 KiB
Plaintext
69 lines
1.4 KiB
Plaintext
' ########### start ###########
|
|
' pic:PIC12F509
|
|
' ########### end ###########
|
|
'
|
|
' ******************************************************************
|
|
' Scacciazanzare with a PIC12F509
|
|
' 2016-05-18 (c) Paolo Iocco
|
|
' ******************************************************************
|
|
'
|
|
' Circuit diagram
|
|
' ---------------
|
|
' +--\/--+
|
|
' +5V ------>|1° 8|<-------GND
|
|
' LED <----|2 7|----> BUZ2
|
|
' D1 -----|3 6|----> BUZ1
|
|
' MCLR ---->|4 5|----- D3
|
|
' +------+
|
|
' ******************************************************************
|
|
|
|
#include "pic8_pin.h"
|
|
Config:
|
|
#Chip 12F509, 4
|
|
#Config WDT = ON, MCLRE=ON, CP = OFF ', PWRTE = ON
|
|
|
|
#define LED D0
|
|
#define BUZ1 D4
|
|
#define BUZ2 D5
|
|
|
|
dir D0 out
|
|
dir D4 out
|
|
dir D5 out
|
|
dim ciclo as word
|
|
|
|
Startup:
|
|
set D0 off
|
|
set D4 off
|
|
set D5 off
|
|
OPTION_REG=0b00001111 ' PSA + Prescaler 111 (1:128)
|
|
|
|
Loop:
|
|
do
|
|
' ** emette i suoni da ca. 41,6KHz a 25KHz
|
|
for periodo=12 to 20 ' us del semiciclo (ciclo: 24us=41,6KHz, 40us=25KHz)
|
|
for ciclo=1 to 4000 ' 40000 in run - 4000 in test
|
|
set BUZ1 on
|
|
set BUZ2 off
|
|
wait periodo 10us ' us in run - 10us in test
|
|
set BUZ1 off
|
|
set BUZ2 on
|
|
wait periodo 10us ' us in run - 10us in test
|
|
clrwdt
|
|
next ciclo
|
|
next periodo
|
|
|
|
' ** lampeggio
|
|
set LED on
|
|
Wait 250 ms
|
|
|
|
' ** reset delle uscite
|
|
PORTB=0
|
|
|
|
' ** dorme per 20 cicli di watchdog
|
|
for dormi=1 to 20
|
|
clrwdt
|
|
sleep
|
|
next dormi
|
|
|
|
loop
|