;**********************************************************************

; Controllo Relay - Versione di test *
;**********************************************************************
; *
; Filename: P16F684_AC_Test.asm *
; Date: *
; File Version: 1.00 *
; *
; Author: InTeAS WebMaster *
; Company: https://www.inteas.it *
; *
; *
;**********************************************************************
; *
; Files Required: P16F684.INC *
; *
;**********************************************************************
;
list p=16f684 ; list directive to define processor
#include <P16F684.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _FCMEN_OFF & _IESO_OFF
;
; '__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.
;
;***** LOCAL VARIABLE DEFINITIONS
;
; Interval 0x20 - 0x7F , Bank 0
; Interval 0xA0 - 0xBF , Bank 1
;
VALFL EQU 0x79
PCOUNT1 EQU 0x78
;
; 0x20 to 0x78 and 0xA0 to 0xBF next bytes, indirectly addressed
;
COUNT1 EQU 0xBF
COUNT2 EQU 0xBE
ITERAZ EQU 0xB8
;
;**********************************************************************
; PROGRAM AREA
;**********************************************************************
;
ORG 0x000 ; processor reset vector
goto Init ; go to beginning of program
;
ORG 0x004 ; interrupt vector location
goto Init
;
Init:
;
; OPTION Register, on reset all bits = 1
; bit 7 (NOT_RAPU) Weak Pull-Ups Disabled=1
; bit 6 (INTEDG) Interrupt Edge Select
; bit 5 (T0CS) Timer0 Source Selection:
; 1= T0CKI Transition (default), 0= Internal Instruction (CLKOUT)
; bit 4 (T0SE) Timer0 Source Edge Selection: 1 = H-to-L (default), 0= L-to-H
; bit 3 (PSA) Prescaler Assignment: 1= to WDT (default), 0= to Timer0
; bits 2:0 (PS2,PS1,PS0) Prescaler Rate Selection: 1:128 default
movlw b'11011111' ; T0CS= 0 : Internal Timer0
bsf STATUS,RP0 ; Bank 1
movwf OPTION_REG
;
; *******************************
; Set of the PORTA I/O (bit 5:0)
; *******************************
;
bcf STATUS,RP0 ; Bank 0
bsf PORTC,3 ; inattiva Power Supply
movlw h'07' ; Set RA<2:0> and RC<4,1:0> to digital I/O
movwf CMCON0
bsf STATUS,RP0 ; Bank 1
clrf ANSEL ; Digital I/O
; 1=input 0=output
movlw b'11111111'
movwf TRISA ; write in TRISA register
;
; *******************************
; Set of the PORTC I/O (bit 5:0)
; *******************************
; 1=input 0=output
movlw b'11011011'
movwf TRISC ; write in TRISC register
bcf STATUS,RP0 ; Bank 0
bsf PORTC,5 ; inattiva Power Supply
bcf PORTC,2 ; spegne Probe Led
;
; I/O Summary
;
; PORTC,5 OUTPUT (pin 5) : Power Supply Control (attivo su 0)
; PORTC,3 INPUT (pin 7) : AC Signal
; PORTC,2 OUTPUT (pin 8) : Probe Led (attivo su 1)
;
Main:
bcf STATUS,RP0 ; Bank 0
bcf PORTC,2 ; accende Probe Led
clrf VALFL ; VALFL=0 Negative Polarity (Status Off)
call ACTCNT
bsf STATUS,RP0 ; Bank 1
;
movlw h'10'
call LDELAY
;
bcf STATUS,RP0 ; Bank 0
bsf PORTC,2 ; spegne Probe Led
incf VALFL ; VALFL=1 Positive Polarity (Status On)
call ACTCNT
bsf STATUS,RP0 ; Bank 1
;
movlw h'10'
call LDELAY
;
goto Main
;
;***********************************************
; DELAY Routine max 196,65 msec, min 0,771 msec
;***********************************************
;
DELAY_MAX:
movlw h'FF'
DELAY:
movwf COUNT2
Dly2:
movlw h'FF'
movwf COUNT1
Dly1:
decfsz COUNT1,1
goto Dly1
decfsz COUNT2,1
goto Dly2
return
;
;****************************************************
; LDELAY Routine lungo ritardo 1 ciclo circa 196 msec; max 49.8 sec circa
;****************************************************
;
LDELAY_STD:
movlw h'02'
LDELAY:
movwf ITERAZ
Dly3:
call DELAY_MAX
decfsz ITERAZ,1
goto Dly3
return
;
;*****************
; ACTUATOR CONTROL
;*****************
;
ACTCNT:
;
; Syncronization VALFL=0 Negative Polarity (Status Off)
; VALFL=1 Positive Polarity (Status On)
;
btfsc VALFL,0
goto Syncr2
; Negative Polarity
Syncr1:
btfss PORTC,3
goto Syncr1 ; waiting for AC=1
goto LdPr
; Positive Polarity
Syncr2:
btfsc PORTC,3
goto Syncr2 ; waiting for AC=0
;
; Loading procedure
;
LdPr:
call TRANSDET ; 0-->1
call PWSPCNT
return
;
; **********************
; Transition Detection
; **********************
;
TRANSDET:
btfsc PORTC,3
goto Tr10 ; jump if AC Signal=1
; AC Signal=0
Tr01:
btfss PORTC,3
goto Tr01 ; waiting for AC=1
return
Tr10:
btfsc PORTC,3
goto Tr10 ; waiting for AC=0
return
;
; **************************
; Power Supply Control Signal
; **************************
;
PWSPCNT:
movlw h'FF'
movwf PCOUNT1
PDly1:
decfsz PCOUNT1
goto PDly1
;
; Spike Emission
;
bcf PORTC,5 ; Signal Active
movlw h'10' ; durata spike
movwf PCOUNT1
Spk1:
decfsz PCOUNT1
goto Spk1
bsf PORTC,5 ; Signal Inactive
return
;
;******************************************************************************
END ; directive 'end of program'
;******************************************************************************