| ;********************************************************************** ; * ; If the internal RC oscillator is not implemented then the first * ; instruction after the ORG 0x000 directive is not required. * ; * ;********************************************************************** ; * ; Filename: PICLuceDiCortesia.asm * ; Date: 7/11/02 * ; File Version: 1.10 * ; * ; Author: Dario Greggio * ; Company: ADPM Synthesis sas * ; * ;********************************************************************** ; * ; Files required: * ; * ;********************************************************************** ; * ; Notes: * ; ;**********************************************************************
#IFDEF __12C509 ; 2003-2006 list p=12c509,r=dec ; list directive to define processor, r=RADICE numerica di default (dec, hex...) #include <p12c509.inc> ; processor specific variable definitions #endif #IFDEF __12F509 ; 2011 list p=12f509,r=dec ; list directive to define processor, r=RADICE numerica di default (dec, hex...) #include <p12f509.inc> ; processor specific variable definitions #endif
__CONFIG _CP_OFF & _WDT_ON & _MCLRE_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word.
__IDLOCS 0x4744 ; metterci SERNUM
;***** VARIABLE DEFINITIONS
;************************************************************************* ;** PORT DEFINITIONS ;** ;************************************************************************* ;NON TUTTI hanno pullup... solo 0,1,3 AuxOBit equ 5 ; Uscita aux (1 quando luce accesa) LedOBit equ 4 ; led AuxIBit equ 3 ; Input aux (forza lampeggio per indicare ? allarme?) con PULLUP LuceOBit equ 2 ; Uscita luce (PWM) DisIBit equ 1 ; disable Luce di cortesia (solo ON/OFF, no ritardo) con PULLUP PulsIBit equ 0 ; Input (portiera) con PULLUP
AuxOVal equ 1 << AuxOBit LedOVal equ 1 << LedOBit AuxIVal equ 1 << AuxIBit LuceOVal equ 1 << LuceOBit DisIVal equ 1 << DisIBit PulsIVal equ 1 << PulsIBit
RAMSTART equ 7 RAMEND equ 0x1f
VAL_ACCESO EQU 31 DELAY_BASE_PWM equ 50 ; voglio un "IRQ" simulato ogni 312.5 uS: il prescaler è 8, 1uSx8=8uSx38=304uS DURATA_BASE EQU 1 ; divisore per rampa luce RAMPA_ANCHE_ALL_ACCENSIONE equ 1
SERNUM equ 1000 VERNUMH equ 1 VERNUML equ 1 ; (non dovrebbero superare 0xF, visto che viene pack-ata in un byte nella GetID...)
INT_VAR UDATA_SHR
BANK0_VARS UDATA
counter_10ms res 1 ;incremented every 10 msec counter_100ms res 1 tmr_comp res 1 Timer32 res 1 ; per PWM TimerLuce res 1 ; 0=luce spenta, 31 (VAL_ACCESO)=luce accesa. Timer1 res 1 durata res 1 ; divisore per durata luce FLAGS res 1 ; Flags InitOK res 1
; definizioni in flags RAMP_UP equ 1 RAMP_DOWN equ 2
;********************************************************************** ; ORG 0x1FF ; processor reset vector ; Internal RC calibration value is placed at location 0x1FF by Microchip ; as a movlw k, where the k is a literal value.
;************************************************************************* ;** INIT ;** Hardware reset entry point ;** ;************************************************************************* RESET_VECTOR CODE 0x0000 ; processor reset vector INIT: ;Power-on entry movwf OSCCAL ; update register with factory cal value
;************************************************************************* ;** RESET ;** software reset entry point ;** ;************************************************************************* RESET: ;Soft reset movfw STATUS movwf InitOK goto start
INT_VECTOR CODE 0x0004 ; interrupt vector location
Copyright dt "(C) Cyberdyne 2011; ADPM Synthesis 2003-2006 - G.Dar\n\r",0 dt "4/3/11"
MAIN_PROG CODE
;initialize and start start: cold_reset: ; controllo del tipo di RESET fatto DOPO! clrwdt ; DOPO!
btfss InitOK,4 ;solo se reset vero (non watchdog!) goto skip_ram_test
movlw RAMSTART ;initialize pointer movwf FSR ; to RAM RAMcheck: clrf INDF ;clear INDF register incf FSR,f ;inc pointer btfss FSR,4 ;all done? goto RAMcheck ;NO, clear next
RAMcheck2: clrf INDF ;clear INDF register incf FSR,f ;inc pointer btfsc FSR,4 ;all done? goto RAMcheck2 ;NO, clear next
skip_ram_test:
clrf FSR ; serve perche' dopo il RAMcheck FSR varrebbe 0x20, che su 12C509 indirizza il 2° banco! clrwdt movlw 10000010b ; pull-up attivi, prescaler TMR, prescaler=8 OPTION movlw DURATA_BASE movwf durata
warm_reset: clrwdt movlw 0 movwf GPIO movlw DisIVal | PulsIVal | AuxIVal ; 1=input tris GPIO clrf TMR0 ;clr tmr0 & prescaler movlw DELAY_BASE_PWM movwf tmr_comp
main:
clrwdt
; il PWM deve andare a 100Hz, quindi (avendo 32 liv.) il timer deve essere OK ; ogni 312uS
movfw tmr_comp ;is tmr0 = tmr_comp (300uS over?) xorwf TMR0,W btfss STATUS, Z ;skip if it is goto main
movlw DELAY_BASE_PWM addwf tmr_comp,f ;update 300uS compare register
movfw TimerLuce ; gestisco i livelli PWM subwf Timer32,w btfss STATUS,C
bsf GPIO,LuceOBit btfsc STATUS,C bcf GPIO,LuceOBit
incf Timer32,f btfss Timer32,5 ; se >= 32... goto main
clrf Timer32
incf counter_10ms,f ; il timer a 100Hz movfw counter_10ms xorlw 5 btfss STATUS,Z goto main
clrf counter_10ms incf counter_100ms,f ; il timer a 20Hz movfw counter_100ms andlw 1 movlw LedOVal btfss STATUS,Z ; (divido x 2 freq. led che mi da' in testa!) xorwf GPIO,f
; ogni 100mS btfsc GPIO,AuxIBit ; se modalita' lampeggio... goto no_lampeggio_aux
movfw counter_100ms ; il timer a 20Hz andlw 3 ; ogni .25sec circa btfss STATUS,Z goto no_lampeggio_aux movlw AuxOVal xorwf GPIO,f movfw TimerLuce movlw VAL_ACCESO btfss STATUS,Z movlw 0 movwf TimerLuce goto fine_main
no_lampeggio_aux:
btfss GPIO,DisIBit ; se modalita' no-luce cortesia... goto no_luce_cortesia
btfss GPIO,PulsIBit ; se la porta è aperta... goto porta_aperta
movfw TimerLuce ; altrimenti gestisco la rampa di spegnimento... btfsc STATUS,Z goto luce_spenta
bsf FLAGS,RAMP_DOWN movfw durata btfss STATUS,Z goto durata_div movlw DURATA_BASE movwf durata decf TimerLuce,f goto fine_main durata_div: decf durata,f goto fine_main
luce_spenta: bcf FLAGS,RAMP_DOWN bcf FLAGS,RAMP_UP bcf GPIO,AuxOBit goto fine_main
porta_aperta: ; ...luce accesa! #ifdef RAMPA_ANCHE_ALL_ACCENSIONE movlw 32 subwf TimerLuce,w btfsc STATUS,C ; fino a 32... goto ok_accesa
bsf FLAGS,RAMP_UP incf TimerLuce,f goto ok_accesa2
ok_accesa: bcf FLAGS,RAMP_UP movlw 110 movwf TimerLuce
ok_accesa2:
#else movlw 110 ; (circa il TRIPLO del max valore rampa=VAL_ACCESO) movwf TimerLuce #endif bsf GPIO,AuxOBit goto fine_main
no_luce_cortesia: movlw VAL_ACCESO btfsc GPIO,PulsIBit movlw 0 movwf TimerLuce btfss GPIO,PulsIBit bcf GPIO,AuxOBit btfsc GPIO,PulsIBit bsf GPIO,AuxOBit goto fine_main
fine_main:
goto main
END ; directive 'end of program' ; ************* EOF PICLucec.ASM ********************************
|