71 lines
1.6 KiB
Plaintext
71 lines
1.6 KiB
Plaintext
' ########### start ###########
|
|
' pic:PIC16C84
|
|
' ########### end ###########
|
|
'
|
|
' ******************************************************************
|
|
' Scacciazanzare with a PIC16C84
|
|
' 2016-05-18 (c) Paolo Iocco
|
|
' ******************************************************************
|
|
'
|
|
' Circuit diagram
|
|
' ---------------
|
|
' +--\/--+
|
|
' nc-----|1° 18|-----nc
|
|
' nc-----|2 17|-----nc
|
|
' nc-----|3 16|<--------H
|
|
' +5V--+50K+-->|4 15|<--------H = 4 MHz chrystal+ capacitors
|
|
' GND-------->|5 14|<--------+5V
|
|
' nc-----|6 13|-----BUZ2
|
|
' nc-----|7 12|-----BUZ1
|
|
' nc-----|8 11|-----nc
|
|
' nc-----|9 10|---->LED
|
|
' +------+
|
|
'
|
|
' ******************************************************************
|
|
|
|
Config:
|
|
#Chip 16C84, 4
|
|
#Config OSC = XT, WDT = OFF, PWRTE = ON, CP = OFF
|
|
|
|
#define LED portb.4
|
|
#define BUZ1 portb.6
|
|
#define BUZ2 portb.7
|
|
dir PORTA out
|
|
dir PORTB out
|
|
dim ciclo as word
|
|
|
|
Startup:
|
|
PORTA = 0
|
|
PORTB = 0
|
|
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
|