118 lines
2.4 KiB
NASM
118 lines
2.4 KiB
NASM
; ******************************************************************
|
|
; Scacciazanzare with a PIC10F200
|
|
; 2016-08-11 (c) Paolo Iocco
|
|
; ******************************************************************
|
|
;
|
|
; Circuit diagram
|
|
; ---------------
|
|
; +--\/--+
|
|
; LED <----------|1° 6|<--------|50K|---+5V
|
|
; GND ---------->|2 5|<------- +5V
|
|
; BUZ1 <---------|3 4|-------> BUZ2
|
|
; +------+
|
|
;
|
|
; ******************************************************************
|
|
|
|
INCLUDE "p10f200.inc" ; include le definizioni standard
|
|
list p=10F200 ; Processoer utilizzato
|
|
;errorlevel -302 ;suppress message "Bank Switch Check"
|
|
__CONFIG _IntRC_OSC & _WDT_ON & _CP_OFF & _MCLRE_OFF
|
|
|
|
; - - - - -
|
|
ciclo_l EQU 0x10 ; primo valore RAM (0x10-0x1F)
|
|
ciclo_h EQU 0x11
|
|
periodo EQU 0x12
|
|
dummy EQU 0x13
|
|
dormi EQU 0x14
|
|
|
|
#define LED GPIO,0
|
|
#define BUZ1 GPIO,1
|
|
#define BUZ2 GPIO,2
|
|
|
|
org 0x00
|
|
Start:
|
|
movlw b'11001111' ; PSA + Prescaler 111 (1:128)
|
|
option
|
|
movlw b'0000' ; set GPIO full OUT
|
|
tris GPIO
|
|
|
|
bcf LED ; set LED off
|
|
bcf BUZ1 ; set BUZ1 off
|
|
bcf BUZ2 ; set BUZ2 off
|
|
|
|
Loop:
|
|
; ** emette i suoni da ca. 63KHz a 15KHz (ciclo: 1=63,3KHz, 10=15,7KHz)
|
|
movlw d'10' ; Invia 10 trame di durata diversa
|
|
movwf periodo
|
|
|
|
Trama:
|
|
movlw d'160' ; 160*256 periodi per frequenza
|
|
movwf ciclo_h
|
|
|
|
Ciclo_High:
|
|
movlw d'255' ; ciclo interno
|
|
movwf ciclo_l
|
|
|
|
Ciclo_Low:
|
|
; * ************ *
|
|
; * Periodo ON *
|
|
; * ************ *
|
|
bsf BUZ1 ; set BUZ1 on
|
|
bcf BUZ2 ; set BUZ2 off
|
|
movf periodo,w
|
|
movwf dummy
|
|
OUT_ON:
|
|
decfsz dummy,f
|
|
goto OUT_ON
|
|
clrwdt ; clrwdt qui per equilibrare le durate ON ed OFF
|
|
; * ************* *
|
|
; * Periodo OFF *
|
|
; * ************* *
|
|
bcf BUZ1 ; set BUZ1 off
|
|
bsf BUZ2 ; set BUZ2 on
|
|
movf periodo,w
|
|
movwf dummy
|
|
OUT_OFF:
|
|
decfsz dummy,f
|
|
goto OUT_OFF
|
|
; * NEXT Ciclo Low
|
|
decfsz ciclo_l,f
|
|
goto Ciclo_Low
|
|
; * NEXT Ciclo High
|
|
decfsz ciclo_h,f
|
|
goto Ciclo_High
|
|
; * NEXT Trama
|
|
decfsz periodo,f
|
|
goto Trama
|
|
|
|
; * ************* *
|
|
; * Lampeggio LED *
|
|
; * ************* *
|
|
bsf LED ; set LED on
|
|
movlw d'255' ; Pausa (ca. xxx ms)
|
|
movwf dummy
|
|
LED_ON:
|
|
decfsz dummy,f
|
|
goto LED_ON
|
|
|
|
; * ****************** *
|
|
; * Preparazione SLEEP *
|
|
; * ****************** *
|
|
bcf LED ; set LED off
|
|
bcf BUZ1 ; set BUZ1 off
|
|
bcf BUZ2 ; set BUZ2 off
|
|
; * dorme per 20 cicli di watchdog
|
|
movlw d'20'
|
|
movwf dormi
|
|
Ciclo_Sleep:
|
|
clrwdt
|
|
sleep
|
|
nop
|
|
decfsz dormi,f
|
|
goto Ciclo_Sleep
|
|
|
|
; * Torna al ciclo principale
|
|
goto loop
|
|
end
|
|
|