⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 08232x2.asm

📁 实现继电器开关在市电的零点闭合
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;
;  BZ-100RC   F I R M W A R E
;
;--------------------------------------------------------------------------
; Copyright (c) 2002-2004 by
; The Watt Stopper, Inc., Santa Clara, CA., USA
; All Rights Reserved.  Unpublished rights  reserved  under  the
; copyright laws of the United States.
;
; The software contained  on  this media is proprietary to and embodies the
; confidential technology of The Watt Stopper, Inc. Possession, use, dupli-
; cation or dissemination of the software and media is authorized only
; pursuant to a valid written license from The Watt Stopper, Inc.
;
; This software is furnished under a  license  and  may  be used and copied
; only in accordance with the terms of  such license and with the inclusion
; of the above copyright notice.  This software or any other copies thereof
; may not be provided or otherwise made available to  any other person.  No
; title to and ownership of the software is hereby transferred.
;
; The information in this software is subject to change without  notice and
; should not be construed as a commitment by The Watt Stopper, Inc.
;
; The Watt Stopper, Inc. assumes  no  responsibility for the use or
; reliability of its software on equipment which is not supplied by
; The Watt Stopper, Inc.
;
; RESTRICTED RIGHTS  LEGEND  Use,  duplication,  or  disclosure by the U.S.
; Government is subject  to  restrictions  as  set  forth  in  Subparagraph
; (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable.
;--------------------------------------------------------------------------
;
; Revision History:
; ----------------
; 
;equ	MAJOR_VERSION	=
;equ	MINOR_VERSION	=
;
;
;-----------------------------------
;2006/8/12	Bili
;schematic design. 
;2006/10/17	Bili
;modify the zerocross deteted, can adjust the zerocorss very good perfomer.
;2006/10/7	Bili
;modify the LED display(blinks the version number)
;2006/12/22 Bili
;modify the priority of sensor input ( Manual On > Hold Off > Hold On > Control In )
;-----------------------------
;Last Edit:	1 Nov 2006 by Bili
;
;
;***** Specify Device
;device ATtiny11
;
;
;
;
;									  ATtiny11
;				    		1	+-------------------+  8
;			   SENSOR INPUT ----|PB5     O      VCC	|----POWER SUPPLY
;								|					|
;		        			2	|					|  7
;			MANUAL ON INPUT ----|PB3            PB2	|----RELAY CONTROL OUTPUT
;								|					|
;			  				3	|					|  6
;		 LED CONTROL OUTPUT ----|PB4			PB1	|----LINE ZEROCROSS INPUT
;								|					|
;							4	|					|  5
;					COMMON	----|GND			PB0	|----LOAD ZEROCROSS INPUT
;								|					|
;								+-------------------+
;
;
;
;
;
;Every cycle length is the same to power cycle, we also use the power cycle to guide the
;relay off time(30sec.)
;
;
;This version have the study mode and keep relay warming mode. 
;For the ATtiny11 have no eeprom in it so we need to catch the zerocross as soon as possible.
;keep the relay's coil warming in order to keep the zero cross from moving 
;after a long time of relay opens.
;A more exact of initial delay (TCNT0)is 130 at 50HZ and 180 at 60HZ.
;In the new BZ50 we have modify it adjust the different 
;AC power input voltage phase frequence.
;we made it can load different type of load also have the zero cross. 
;Such as ballast fluorescent and incandescence. 

.INCLUDE "tn11def.inc"  
.DEF	ZERO		=R0			;define the number 0
.DEF	ONE			=R1			;define the number 1
.DEF	TWO			=R2			;define the number 2
.DEF	THREE		=R3			;define the number 3
.DEF	FOUR		=R4			;define the number 4
.DEF	EIGHT		=R5 		;define the number 8
.DEF	SIXTEEN		=R6			;define the number 32
.DEF	PINBINT		=R7			;define pin's change interrupt
.DEF	SLEEPMODE	=R8			;define	sleep mode
.DEF	PIN3		=R9			;define PINB.3 original value
.DEF	PIN5		=R10		;define PINB.5 original value
.DEF	IO3			=R11		;define PINB.3 change value
.DEF	IO5			=R12		;define PINB.5 change value
.DEF	MANFIRST	=R13		;define the MANUAL ON override the SENSOR CONTROL
.DEF	CYCSTART	=R14		;define the start/end of AC POWER CYCLE
.DEF	COUNT		=R15		;define if need the 30 secs. delay off
.DEF	TCNTON		=R16		;define the initial value of delay on
.DEF	TCNTOFF 	=R17		;define the initial value of delay off
.DEF	PIN3CH		=R18		;define the MANUAL ON input valid times
.DEF	PIN5CH		=R19		;define the CONTROL ON input valid times
.DEF	NEUTSTAOFF	=R20		;define the NEUTRAL wire's state when the MCU is ready to open the relay("0/1")
.DEF	NEUTSTAON	=R21		;define the NEUTRAL wire's state when the MCU is ready to close the relay("0/1")
.DEF	DELAY1		=R22		;define the 30 secs. timer register1
.DEF	DELAY0		=R23		;define the 30 secs. timer register0 
.DEF	HZ			=R24		;define to save the power cycle length (50Hz/60Hz)
.DEF	RELAYONOFF	=R25		;RELAY ON/OFF "3"=OFF  "2"=ON others remain the previous state of relay
.DEF	INTMODE		=R26		;define the external interrupt mode select
.DEF	CONFIRM		=R27		;
.DEF	TEMP0		=R28		;TEMPORARY REGISTER 0
.DEF	TEMP1		=R29		;TEMPORARY REGISTER 1
.DEF	TEMP2		=R30		;TEMPORARY REGISTER 2
.DEF	TEMP3		=R31		;TEMPORARY REGISTER 3
;------------------------------------------------------------------
.ORG 	$000
RJMP 	RESET
.ORG 	$001
RJMP 	INTT
.ORG 	$003
RJMP 	TOV
.ORG 	$005
RESET:	
		LDI		TEMP0,0X00		;write the number 0 to ZERO
		MOV		ZERO,TEMP0
		LDI		TEMP0,0X01		;write the number 1 to ONE
		MOV		ONE,TEMP0
		LDI		TEMP0,0X02		;write the number 2 to TWO
		MOV		TWO,TEMP0
		LDI		TEMP0,0X03		;write the number 3 to THREE
		MOV		THREE,TEMP0
		LDI		TEMP0,0X04		;write the number 4 to FOUR
		MOV		FOUR,TEMP0
		LDI		TEMP0,0X08		;write the number 8 to EIGHT
		MOV		EIGHT,TEMP0
		LDI		TEMP0,0X20		;write the number 32 to SIXTEEN
		MOV		SIXTEEN,TEMP0
		LDI		TEMP0,0X40		;write the number 64 to PINBINT
		MOV		PINBINT,TEMP0
		CBI		DDRB,0			;PB.0 INPUT PIN
		CBI	 	DDRB,1			;PB.1 INPUT PIN
		SBI		DDRB,2
		CBI		DDRB,3
		SBI		DDRB,4
		SBI		PORTB,0			;ENABLE THE INTERNAL PULLUP RISISTER
		SBI  	PORTB,1			;ENABLE THE INTERNAL PULLUP RISISTER
		CBI		PORTB,2			;OPEN THE RELAY
		SBI		PORTB,3			;ENABLE THE INTERNAL PULLUP RISISTER
		SBI		PORTB,4			;LED OFF
		MOV		IO3,EIGHT		;initial the original value of PINB.3
		MOV		IO5,SIXTEEN		;initial the original value of PINB.5
		LDI	    PIN3CH,0		;CLEAR THE PINB.3 CHANGE
		LDI     PIN5CH,0		;CLEAR THE PINB.5 CHANGE
		MOV		CYCSTART,ZERO	;CLEAR THE POWER CYCLE END SYMBOL
		MOV		COUNT,ZERO
		RCALL	DELAY1S
AGAIN:	LDI		TEMP1,0
		LDI		TEMP2,0
		LDI		TEMP3,200
RR:		DEC		TEMP3
		CPI		TEMP3,0
		BREQ	AGAIN
		RCALL	DELAY10
		CPI		TEMP1,30
		BREQ	P4_HOT
		CPI		TEMP2,30
		BRNE	RRR
		RJMP	P5_HOT
RRR:	IN		TEMP0,PINB
		AND		TEMP0,THREE
		CPI		TEMP0,0
		BREQ	RR
		CPI		TEMP0,1
		BREQ	RRR0
		CPI		TEMP0,2
		BREQ	RRR1
		RJMP	RR
RRR0:	INC		TEMP1
		LDI		TEMP2,0
		RJMP	RR
RRR1:	INC		TEMP2
		LDI		TEMP1,0
		RJMP	RR

P4_HOT:	OUT 	GIMSK,PINBINT	;ENABLE EXT. INTERRUPT
		MOV		INTMODE,TWO
		LDI		TEMP0,0X22
		MOV		SLEEPMODE,TEMP0	
		OUT		MCUCR,INTMODE	;SELECT THE INTO INTERRUPT MODE  (falling edge)
RE0:	CBI		PORTB,4			;fit the different of power frequency(50/60Hz)	
		RCALL	DELAY1S			;so that we can get the same delay off time(30sec.)
		SBI		PORTB,4
		RCALL	DELAY1S
		CBI		PORTB,4
		SEI
		RCALL	SLEEPP
		MOV		CYCSTART,ZERO	;CLEAR THE POWER CYCLE ENDING
		LDI		TEMP1,0	
RE1:	INC		TEMP1			;1
		RCALL	DELAY10			;3+8
		CP		CYCSTART,ONE	;1
		BRNE	RE1				;1
		MOV		CYCSTART,ZERO
		LDI		TEMP2,160
		CLC
		CP		TEMP1,TEMP2
		BRSH	RE50
		RJMP	RE60
RE50:	LDI		TCNTON,80		;RELAY CLOSE (ON) DELAY
		LDI		TCNTOFF,80		;RELAY OPEN (OFF) DELAY
		LDI		HZ,15
		RJMP	MAIN
RE60:	LDI		TCNTON,100		;RELAY CLOSE (ON) DELAY
		LDI		TCNTOFF,100		;RELAY OPEN (OFF) DELAY
		LDI		HZ,18
		RJMP	MAIN

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MAIN:	CLI
		OUT  	TIMSK,TWO		;CLOCK INTERRUPT ENABLE
		LDI     PIN5CH,0		;CLEAR THE PINB.2 CHANGE
		LDI	    PIN3CH,0		;CLEAR THE PINB.3 CHANGE
		MOV		CYCSTART,ZERO	;CLEAR THE POWER CYCLE ENDING 
		MOV		COUNT,ZERO
		MOV		MANFIRST,ZERO
		LDI		DELAY0,100		;DELAY 30SECS.
		MOV		DELAY1,HZ
		OUT		MCUCR,TWO
		MOV		INTMODE,TWO
		LDI		TEMP0,0X22
		MOV		SLEEPMODE,TEMP0		
		OUT		MCUCR,INTMODE	;SELECT THE INTO INTERRUPT MODE
		SEI
M3:		MOV		CYCSTART,ZERO	;CLEAR THE POWER CYCLE ENDING
		RCALL	MAN
		CPI		PIN3CH,10
		BREQ	M4
M2:		CP		MANFIRST,ONE	;"1" SHI FOU YOU GUO YI CI SHOU DONG AN JIAN (WITHIN 30SEC.)
		BRNE	M7				;"0" MEI YOU GUO SHOU DONG KONG ZHI SHU RU, JIN RU SHUI MIAN.
		RJMP	M5				;"1" YOU GUO SHOU DONG SHU RU, JIN RU SENSOR KONG ZHI
M4:		MOV  	IO5,SIXTEEN
		LDI		PIN3CH,0
		MOV		IO3,PIN3
		SBIC	PINB,3
		RJMP	M2				;invalid manual on input, no operation, go to label-M2
		LDI		RELAYONOFF,2	;valid manual on input, close the relay
		RCALL	SLEEPP			;go to sleep to waitting for a new cycstart then start the timer 0
		MOV		CYCSTART,ZERO
		OUT		TCNT0,TCNTON	;initial the relay close delay
		OUT		TCCR0,THREE		;set prescaler at 64
		RCALL	SLEEPP			;sleep
		RCALL	JUDGE			;judge if the relay close at the zero point
RELEASE:SBIS	PINB,3			;wait for manual on press release
		RJMP	RELEASE
		IN 		PIN5,PINB		;get newly state of the pin5
		AND 	PIN5,SIXTEEN
		MOV  	IO5,PIN5
		MOV		COUNT,ZERO		
		MOV		MANFIRST,ONE
		LDI		DELAY0,100		;DELAY 30SECS.
		MOV		DELAY1,HZ
		RJMP	M3
M5:		CP		COUNT,ONE		;no sensor input yet?
		BREQ	M6				;
		RCALL	SEC30			;go on 30sec count backwards
		CPI		DELAY1,0		;end of 30sec delay?
		BRNE	M6				
		MOV		COUNT,ZERO		;yes, clear the sensor input flag
		MOV		MANFIRST,ZERO	;clear the manual on input flag
		LDI		RELAYONOFF,3	;open the relay
		RCALL	SLEEPP			;go to sleep
		MOV		CYCSTART,ZERO	;wake up, clear the cycle start flag
		OUT		TCNT0,TCNTOFF	;initial the relay open delay value
		OUT		TCCR0,THREE		;set the prescaler at 64
		RCALL	SLEEPP			;sleep again
		RCALL	JUDGE			;judge the relay open at zero point or not
		RJMP	MAIN			;return to the top
M6:		CPI		CONFIRM,1		;need confirm or not
		BRNE	MM0				;no, have no change in the pinb.5, go to normal scan
		RJMP	MM1				;yes, change have occur in the pinb.5, go to confirm the input state
MM0:	RCALL	CTRL			;scan the pin5 input state change
		CPI		PIN5CH,2		;eliminate the input tremble
		BREQ	M8				;change
		SBIC	PORTB,2			;no change,sleep or warm up the relay coil
		RJMP	M7		
		RCALL	PWMOUT			;warm up the relay coil
		RJMP	M3
MM1:	RCALL	ENSURE			;confirm the pin5 input state
		CPI		TEMP1,9
		BREQ	M9
		CPI		TEMP2,9
		BREQ	M9
		SBIC	PORTB,2
		RJMP	M7
		RCALL	PWMOUT			;warm up the relay coil
		RJMP	M3
M7:		RCALL	SLEEPP
		RJMP	M3
M8:		MOV		COUNT,ONE
		LDI		CONFIRM,1
		LDI		PIN5CH,0
		MOV		IO5,PIN5
		RJMP	M3
M9:		LDI		CONFIRM,0
		LDI		TEMP1,0
		LDI		TEMP2,0
		MOV		IO5,PIN5
		RCALL	SLEEPP
		MOV		CYCSTART,ZERO
		RCALL	SCAN
		RCALL	SLEEPP
		RCALL	JUDGE
		MOV		CYCSTART,ZERO
		RCALL	SLEEPP
		RJMP	M3

P5_HOT:	CBI		PORTB,4			;TURN ON LED
		RCALL	DELAY1S	
		SBI		PORTB,4			;TURN OFF LED
		RCALL	DELAY1S
		CBI		PORTB,4			;TURN ON LED
		RCALL	WAIT
		OUT		TCCR0,THREE
		OUT		TCNT0,ZERO
_RE0:	SBIS	PINB,0
		RJMP	_RE0
		OUT		TCCR0,ZERO

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -