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

📄 elecbrush.asm

📁 低电压检测
💻 ASM
字号:
;======================================
;ProjectName:	ElecBrush
;Date:		2007-8-30 14:13
;Author:	Kendy(HSM)
;Body:		HT48R06
;======================================
;		IO Position Map
;		 	  ----V----
;		Moto PA3|1	18|PA4	NC
;	 ChargeCheck PA2|2	17|PA5	NC
;	  LightPower PA1|3	16|PA6	NC
;	   MotoPower PA0|4	15|PA7	ModeKey
;	      RedLed PB2|5	14|OSC2	Nc
;	     BlueLed PB1|6	13|OSC1	RC
;	    GreenLed PB0|7	12|VDD	VDD
;	         Gnd VSS|8	11|RST	Rst
;	  LightCheck PC0|9	10|PC1	NC
;			 -----------
#include HT48R06A-1.inc

data .section   'data'
AccBuf		db	? 
StatusBuf	db	?
SysFlag0	db	?
SysFlag1	db	?
KeyDelayTime	db	?
Timer4ms	db	?
Mode		db	?
MotoCyc		db	?
MotoDuty	db	?
MotoCnt		db	?
Flag4ms		db	?
TimerMotoDete	db	?
Timer2Min	db	?
Timer1Sec	db	?
CheckRam0	db	?
CheckRam1	db	?
CheckRam2	db	?
TimerIntCnt	db	?
TimerIntCntBuf	db	?
TestLoadCnt	db	?
ChargeDeteDelayTime	db	?
;*****Flag Define
FKeyPress	equ	SysFlag0.0	
FChargeOn	equ	SysFlag0.1
FPwmAdjust	equ	SysFlag0.2
FPwmInc		equ	SysFlag0.3
FMode2AdjustOk	equ	SysFlag0.4
F230gLoad	equ	SysFlag0.6
FTestLoad	equ	SysFlag0.7
FLoadOn		equ	SysFlag1.0

FTimer4ms	equ	Flag4ms.0
;*****IO Define
PBLed		equ	PB.0
PRLed		equ	PB.1
PGLed		equ	PB.2
PModeKey	equ	PA.7
PMoto		equ	PA.3
PLightPower	equ	PA.1
PChargeDete	equ	PA.2
;*****Const Define
CCheckRam0	equ	125
CCheckRam1	equ	35
CCheckRam2	equ	81
CKeyDelayTime	equ	12
CChargeDeteDelayTime	equ	12
CTimer4ms	equ	40
CTimer2Min	equ	120
CTimer1Sec	equ	250

CModeMax	equ	3
C2600P		equ	55
C2400P		equ	52
C2100P		equ	35
C2000P		equ	33
C1800P		equ	30
C1700P		equ	28
c1400		equ	23
CMode1Duty	equ	30
CMode1Duty_Load	equ	48
CMode2Duty	equ	26
CMode2Duty_Load	equ	39
CMode3Duty	equ	21
CMode3Duty_Load	equ	32

CMotoCycMax	equ	100
CTimerMotoDete	equ	50	;50*4
CMotoDutyMax	equ	100
CMotoDutyMin	equ	0
COddsMax	equ	10
CTestLoadCnt	equ	100

CMode1CntMax	equ	38
CMode1CntMin	equ	36

CMode2CntMax	equ	32
CMode2CntMin	equ	29

CMode3CntMax	equ	112
CMode3CntMin	equ	92


C174gIntCntMin	equ	95
C230gIntCntMin	equ	130

CLoadOffCnt	equ	60
CLoadOnCnt	equ	80
code .section at 0 'code'

	org	000h
	jmp	Reset
	jmp	Reset
	jmp	Reset
	jmp	Reset
	org	004h
	jmp	ExtInt
	jmp	ExtInt
	jmp	ExtInt
	jmp	ExtInt
	org	008h
	jmp	TimerInt
	jmp	TimerInt
	jmp	TimerInt
	jmp	TimerInt
	org	020h
	
CntSpeedSjmp:
	mov	a,Mode
	addm	a,PCL
	jmp	CntSpeedEnd
	jmp	CntMode1Speed
	jmp	CntSpeedEnd
	jmp	CntSpeedEnd
	
InitMotoDuty:
	mov	a,Mode
	addm	a,PCL
	jmp	InitMotoDutyEnd
	jmp	InitMode1Duty
	jmp	InitMode2Duty
	jmp	InitMode3Duty
InitMode1Duty:
	mov	a,CMode1Duty
	jmp	InitMotoDutyCom
InitMode2Duty:
	mov	a,CMode2Duty
	jmp	InitMotoDutyCom
InitMode3Duty:
	mov	a,CMode3Duty
	jmp	InitMotoDutyCom		
InitMotoDutyCom:
	mov	MotoDuty,a	
InitMotoDutyEnd:
	ret	
	
Reset:
	clr	wdt
	clr	emi
	mov	a,CCheckRam0
	xor	a,CheckRam0
	snz	z
	jmp	ClrAllRam
	mov	a,CCheckRam1
	xor	a,CheckRam1
	snz	z
	jmp	ClrAllRam
	mov	a,CCheckRam2
	xor	a,CheckRam2
	snz	z
	jmp	ClrAllRam
;	jmp	MainLoop
		
ClrAllRam:
	mov	a,40h
	mov	mp0,a
	mov	a,7fh-40h
ClearAllRAMLoop:
	clr	R0
	inc	MP0
	sdz	ACC
	jmp	ClearAllRAMLoop
InitPort:
	mov	a,11100100b
	mov	PAC,a
	mov	a,11111000b
	mov	PBC,a
	mov	a,11111111b
	mov	PCC,a
InitInt:
	set	emi
	set	eti
	set	eei
	mov	a,10011000b
	mov	tmrc,a
	mov   	a,256-200
	mov   	tmr,a
InitPowerData:
	mov	a,CKeyDelayTime
	mov	KeyDelayTime,a
	mov	a,CTimer4ms
	mov	Timer4ms,a
	mov	a,20
	mov	MotoDuty,a
	mov	a,CTimerMotoDete
	mov	TimerMotoDete,a
	clr	PLightPower
	mov	a,CCheckRam0
	mov	CheckRam0,a
	mov	a,CCheckRam1
	mov	CheckRam1,a
	mov	a,CCheckRam2
	mov	CheckRam2,a
MainLoop:
	call	KeyCheck
	call	LedCheck
	call	DealPwm
	call	Timer
	call	ChargeDete
	jmp	MainLoop
;************************************
DealPwm:   
	mov	a,Mode
	addm	a,PCL
	jmp	DealPwmEnd
	jmp	Mode1Pwm
	jmp	Mode2Pwm
	jmp	Mode3Pwm
;Mode1Pwm:
;	mov	a,CMode1Duty
;	sz	FLoadOn
;	mov	a,CMode1Duty_Load
;	mov	MotoDuty,a
;	jmp	DealPwmEnd
Mode2Pwm:
	mov	a,CMode2Duty
	sz	FLoadOn
	mov	a,CMode2Duty_Load
	mov	MotoDuty,a
	jmp	DealPwmEnd
Mode3Pwm:
	mov	a,CMode3Duty
	sz	FLoadOn
	mov	a,CMode3Duty_Load
	mov	MotoDuty,a
	jmp	DealPwmEnd
Mode1Pwm:	
	snz	FPwmAdjust
	jmp	DealPwmEnd
	clr	FPwmAdjust

	snz	FPwmInc
	jmp	PwmDec
PwmInc:
	mov	a,MotoDuty
	sub	a,CMotoDutyMax
	sz	c
	jmp	DealPwmEnd
	inc	MotoDuty
	jmp	DealPwmEnd	
PwmDec:
	mov	a,MotoDuty
	sub	a,CMotoDutyMin
	snz	c
	jmp	DealPwmEnd
	
	dec	MotoDuty
	jmp	DealPwmEnd

DealPwmEnd:
	ret	
;************************************
Timer:
	snz	FTimer4ms
	jmp	TimerEnd
	clr	FTimer4ms
	
	mov	a,Mode
	xor	a,0
	sz	z
	jmp	TimerEnd
CntSpeed:
	sdz	TimerMotoDete
	jmp	DecTimer
	mov	a,CTimerMotoDete
	mov	TimerMotoDete,a
		
	mov	a,Mode
	jmp	CntSpeedSjmp	
CntMode1Speed:
	mov	a,CMode1CntMax
	sub	a,MotoCnt
	snz	c
	jmp	SetPwmDecFlag
	mov	a,CMode1CntMin
	sub	a,MotoCnt
	sz	c
	jmp	SetPwmIncFlag
	jmp	CntSpeedEnd
	
;CntMode2Speed:
;	mov	a,CMode2CntMax
;	sub	a,MotoCnt
;	snz	c
;	jmp	SetPwmDecFlag
;	mov	a,CMode2CntMin
;	sub	a,MotoCnt
;	sz	c
;	jmp	SetPwmIncFlag
;	jmp	CntSpeedEnd
	
;CntMode3Speed:
;	mov	a,CMode3CntMax
;	sub	a,MotoCnt
;	snz	c
;	jmp	SetPwmDecFlag
;	mov	a,CMode3CntMin
;	sub	a,MotoCnt
;	sz	c
;	jmp	SetPwmIncFlag
;	jmp	CntSpeedEnd
SetPwmDecFlag:
	set	FPwmAdjust
	clr	FPwmInc
	jmp	CntSpeedEnd
SetPwmIncFlag:
	set	FPwmAdjust
	set	FPwmInc
	jmp	CntSpeedEnd	
CntSpeedEnd:
	clr	MotoCnt		
DecTimer:
	sdz	Timer1Sec
	jmp	TimerEnd
	mov	a,CTimer1Sec
	mov	Timer1Sec,a
	
	sdz	Timer2Min
	jmp	TimerEnd
	mov	a,CTimer2Min
	mov	Timer2Min,a
	clr	Mode
TimerEnd:
	ret
		
		
Init2MinData:
	mov	a,CTimer1Sec
	mov	Timer1Sec,a
	mov	a,CTimer2Min
	mov	Timer2Min,a
	ret	
;************************************
ChargeDete:
	sz	FChargeOn
	jmp	ChargeOffCheck
ChargeOnCheck:
	snz	PChargeDete
	jmp	InitChargeDeteDelayTime
	sdz	ChargeDeteDelayTime
	jmp	ChargeDeteEnd
	set	FChargeOn
	clr	Mode
	jmp	InitChargeDeteDelayTime
ChargeOffCheck:
	sz	PChargeDete
	jmp	InitChargeDeteDelayTime
	sdz	ChargeDeteDelayTime
	jmp	ChargeDeteEnd
	clr	FChargeOn
	jmp	InitChargeDeteDelayTime
InitChargeDeteDelayTime:
	mov	a,CChargeDeteDelayTime
	mov	ChargeDeteDelayTime,a
	jmp	ChargeDeteEnd
ChargeDeteEnd:
	ret	
;************************************
KeyCheck:
	sz	FKeyPress
	jmp	KeyUnpressCheck
KeyPressCheck:
	sz	PModeKey
	jmp	InitKeyDelayTime
	sdz	KeyDelayTime
	jmp	KeyCheckEnd
	set	FKeyPress
	inc	Mode
	mov	a,CModeMax
	sub	a,Mode
	snz	c
;	clr	Mode
	call	Init2Min
WorkMode:
	clr	TimerIntCnt
	clr	TimerIntCntBuf
	call	InitMotoDuty	
	jmp	InitKeyDelayTime
KeyUnpressCheck:
	snz	PModeKey
	jmp	InitKeyDelayTime
	sdz	KeyDelayTime
	jmp	KeyCheckEnd
	clr	FKeyPress
	jmp	InitKeyDelayTime
InitKeyDelayTime:
	mov	a,CKeyDelayTime
	mov	KeyDelayTime,a
	jmp	KeyCheckEnd
KeyCheckEnd:
	ret
Init2Min:
	clr	Mode
	mov	a,CTimer1Sec
	mov	Timer1Sec,a
	mov	a,CTimer2Min
	mov	Timer2Min,a
	ret
;************************************
LedCheck:
	sz	FChargeOn
	jmp	InChargeStatus
InWorkStatus:
	mov	a,Mode
	addm	a,PCL
	jmp	NoWorkLed
	jmp	Mode1Led
	jmp	Mode2Led
	jmp	Mode3Led
NoWorkLed:
	set	PRLed
	set	PBLed
	set	PGLed
	jmp	LedCheckEnd	
Mode1Led:
	set	PRLed
	clr	PBLed
	set	PGLed
	jmp	LedCheckEnd
Mode2Led:
	clr	PRLed
	set	PBLed
	set	PGLed
	jmp	LedCheckEnd
Mode3Led:
	clr	PRLed
	clr	PBLed
	set	PGLed
	jmp	LedCheckEnd
InChargeStatus:
	set	PRLed
	set	PBLed
	clr	PGLed
	jmp	LedCheckEnd
LedCheckEnd:
	ret

;************************************
TimerInt:
	mov	AccBuf,a
	mov	a,Status
	mov	StatusBuf,a
	
	inc	TimerIntCnt
	mov	a,0
	xor	a,Mode
	sz	z
	jmp	OffMoto

	inc	MotoCyc
	mov	a,MotoCyc
	sub	a,CMotoCycMax
	sz	c
	clr	MotoCyc
	mov	a,MotoDuty
	sub	a,MotoCyc
	sz	c
	jmp	OnMoto 
	jmp	OffMoto
OnMoto:	
	set	PMoto
	jmp	Cnt4ms
OffMoto:
	clr	PMoto
	jmp	Cnt4ms
Cnt4ms:
	sdz	Timer4ms
	jmp	TimerIntOut
	mov	a,CTimer4ms
	mov	Timer4ms,a
	mov	a,0ffh
	mov	Flag4ms,a
TimerIntOut:
	mov	a,StatusBuf
	mov	Status,a
	mov	a,AccBuf
	reti
	

ExtInt:
	mov	AccBuf,a
	mov	a,Status
	mov	StatusBuf,a
	inc	MotoCnt
	
	snz	FLoadOn
	jmp	CheckLoadOn
CheckLoadOff:
	mov	a,CLoadOffCnt
	sub	a,TimerIntCnt
	sz	c
	clr	FLoadOn
	jmp	ExtIntOut
CheckLoadOn:
	mov	a,CLoadOnCnt
	sub	a,TimerIntCnt
	snz	c
	set	FLoadOn
	jmp	ExtIntOut

ExtIntOut:
	mov	a,TimerIntCnt
	mov	TimerIntCntBuf,a
	clr	TimerIntCnt
	mov	a,StatusBuf
	mov	Status,a
	mov	a,AccBuf
	reti
		

⌨️ 快捷键说明

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