106 lines
1.9 KiB
Plaintext
106 lines
1.9 KiB
Plaintext
' ########### start ###########
|
|
' pic:PIC12F675
|
|
' ########### end ###########
|
|
'
|
|
' ******************************************************************
|
|
' Scacciazanzare with a PIC12F675
|
|
' 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 12F675, 4
|
|
#Config WDT = ON, MCLRE=OFF, 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 byte
|
|
dim ciclo_h as byte
|
|
dim dummy as byte
|
|
dim periodo as byte
|
|
|
|
Startup:
|
|
set LED off
|
|
set BUZ1 off
|
|
set BUZ2 off
|
|
OPTION_REG=0b11001111 ' PSA + Prescaler 111 (1:128)
|
|
|
|
Loop:
|
|
do
|
|
' ** emette i suoni da ca. 63KHz a 15KHz
|
|
for periodo=1 to 10 ' us del semiciclo (ciclo: 1=63,3KHz, 10=15,7KHz)
|
|
|
|
movlw 160 ' 160*256 periodi per frequenza
|
|
movwf ciclo_h
|
|
step2:
|
|
movlw 255
|
|
movwf ciclo
|
|
step1:
|
|
' * ************ *
|
|
' * Periodo ON *
|
|
' * ************ *
|
|
bsf GPIO,1 'set BUZ1 on
|
|
bcf GPIO,0 'set BUZ2 off
|
|
movf periodo,w
|
|
movwf dummy
|
|
half1:
|
|
decfsz dummy,f
|
|
goto half1
|
|
clrwdt
|
|
' * ************* *
|
|
' * Periodo OFF *
|
|
' * ************* *
|
|
bcf GPIO,1 'set BUZ1 off
|
|
bsf GPIO,0 'set BUZ2 on
|
|
movf periodo,w
|
|
movwf dummy
|
|
half2:
|
|
decfsz dummy,f
|
|
goto half2
|
|
|
|
decfsz ciclo,f
|
|
goto step1
|
|
|
|
decfsz ciclo_h,f
|
|
goto step2
|
|
|
|
next periodo
|
|
|
|
' * ************* *
|
|
' * Lampeggio LED *
|
|
' * ************* *
|
|
set LED on
|
|
wait 125 ms
|
|
|
|
' * ****************** *
|
|
' * Preparazione SLEEP *
|
|
' * ****************** *
|
|
set LED off
|
|
set BUZ1 off
|
|
set BUZ2 off
|
|
|
|
' ** dorme per 20 cicli di watchdog
|
|
for dormi=1 to 20
|
|
clrwdt
|
|
sleep
|
|
nop
|
|
next dormi
|
|
|
|
loop
|