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

📄 test153s.asm

📁 义隆的8bitMCU。78P153控制步进电机系统。
💻 ASM
字号:
;----------------------------------------------------
; Project  :  Digital 
; Author   :  KeillenCheung
; Company  :  Mailly
; Date	   :  August  19 , 2004
; Version  :  2.00
; IC@Fosc  :  EM78P153S@IRC( 4.0MHz )
;-----------------------------------------------
; declare  the  include  file
;include		"Constants.h"
include		"Define.h"
;-----------------------------------------------
; main  routine  from   here
	org	000h
	jmp	MAIN	
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	JMP	MAIN	
	org	008h
	mov	stack0,a	;堆栈
	swap	stack0
	swapa	SF
	mov	stack1,a 
		
	JBS	Rf,TCIF
	jmp	Intend
	BC	RF,TCIF
	mov	a,@20;5
	add	tcc,a			;250*32=8ms
	;INC	TIME_1S
	;MOV	A,@250		;COUNT 2S
	;XOR	A,TIME_1S
	;JBS	SF,Z
	DJZ	TIME_1S
	JMP	Intend
	;CLR	TIME_1S
	BS	KEY_FLAG,F_1S	
Intend:
	swapa	stack1		
	mov	SF,a
	swapa	stack0	;
	Reti
;---------------------------------------------
MAIN:
	call		INITIAL_ROUTINE		; system  initiallization  routine
	call		DELAY_10MS		; 
	NOP	
;	mov		a,@0xf0
;	mov		port6,a
MAIN_Loop:		
	CALL		SCAN_KEY
	JBS		KEY_FLAG,F_push
	JMP		MAIN_Loop
	BC		KEY_FLAG,F_push	
	jbs		key_flag,Key1
	JMP		MAIN_LOOP	;CHK ON/off Key
MAIN_Loop_01:	
	JBS		PORT5,_inpin
	JMP		MAIN_Loop_01
	
	BS		PORT6,7	
	mov		a,@20;5
	MOV		tcc,a			;250*32=8ms
	BC		RF,TCIF		
	MOV		A,@1
	MOV		TEMP,A
	IOR		IOCF
	OR		A,TEMP		;set TICE is 1
	IOW		IOCF	
	ENI	
	BC		KEY_FLAG,F_1S
	mov		a,@125		;set delay time 1s
	MOV		TIME_1S,a	
	CLR		Sq_cnt
MAIN_Loop_02:
	JBC		KEY_FLAG,F_1S
	JMP		MAIN_Wait_1sEnd
	JBC		PORT5,_inpin
	JMP		MAIN_Loop_02				
MAIN_Loop_03:	
	JBC		KEY_FLAG,F_1S
	JMP		MAIN_Wait_1sEnd
	JBS		PORT5,_inpin
	JMP		MAIN_Loop_03	
	MOV		A,@100	
	XOR		A,Sq_cnt
	JBS		SF,Z
	INC		Sq_cnt	
	JMP		MAIN_Loop_02
MAIN_Wait_1sEnd:
	BC		PORT6,7
	BC		KEY_FLAG,F_1S
	mov		a,@8		;count time 64ms
	MOV		TIME_1S,a	
	CLR		Sq_cnt
MAIN_CHK_Sq:
	JBC		KEY_FLAG,F_1S
	JMP		MAIN_CHK_Sq_End
	JBS		PORT5,_inpin
	JMP		MAIN_CHK_Sq
	call		Delay_10us	;1
	JBS		PORT5,_inpin
	JMP		MAIN_CHK_Sq
	call		Delay_10us	;2
	JBS		PORT5,_inpin
	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;3
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;4
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;5
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;6
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;7
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq	
;	call		Delay_10us	;8
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;9
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;10
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;11
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
;	call		Delay_10us	;12
;	JBS		PORT5,_inpin
;	JMP		MAIN_CHK_Sq
MAIN_CHK_Sq_chklow:
	JBC		KEY_FLAG,F_1S
	JMP		MAIN_CHK_Sq_End
	JBC		PORT5,_inpin
	JMP		MAIN_CHK_Sq_chklow
MAIN_CHK_Sq_chklow_01:
	JBC		PORT5,_inpin
	JMP		MAIN_CHK_Sq_chklow
	call		Delay_10us	;1
	JBC		PORT5,_inpin
	JMP		MAIN_CHK_Sq_chklow
	call		Delay_10us	;2
	JBC		PORT5,_inpin
	JMP		MAIN_CHK_Sq_chklow
	call		Delay_10us	;3
	JBC		PORT5,_inpin
	JMP		MAIN_CHK_Sq_chklow
	call		Delay_10us	;4
;	JBC		PORT5,_inpin
;	JMP		MAIN_CHK_Sq_chklow
;	call		Delay_10us	;5
;	JBC		PORT5,_inpin
;	JMP		MAIN_CHK_Sq_chklow
;	call		Delay_10us	;6
;	JBC		PORT5,_inpin
;	JMP		MAIN_CHK_Sq_chklow
	INC		Sq_cnt
	JMP		MAIN_CHK_Sq
MAIN_CHK_Sq_End:
	nop
	nop		
MAIN_Wait_1sEnd_1:
	NOP
	JMP		MAIN_Wait_1sEnd_1		
;MAIN_Loop_01:
	NOP
	JMP		MAIN_Loop_01
	CALL		SCAN_KEY
	JBS		KEY_FLAG,F_push
	JMP		MAIN_Loop_01
MAIN_Loop_01_in:	
	BC		KEY_FLAG,F_push	
	jbc		key_flag,Key1
	JMP		MAIN_TURN_OFF	;CHK ON/off Key
	jbc		key_flag,Key2
	JMP		GET_KEY2
	jbs		key_flag,Key3
	JMP		main_loop_01
	JMP		GET_KEY3
MAIN_TURN_OFF:
	mov		a,@0
	mov		port5,a
	mov		port6,a
	MOV		A,@0X01
	AND		KEY_FLAG,A
	CLR		Key3_step
	jmp		MAIN_Loop		;jmp re-start	
;-----------------------	
GET_KEY2:
	jbc		key_flag,key2_again
	jmp		GET_KEY2_off
	bs		key_flag,key2_again
	bs		port5,3
	bs		port6,5
	bs		port6,6
	jmp		MAIN_Loop_01
GET_KEY2_off:
	bc		key_flag,key2_again
	bc		port5,3
	jbs		port6,7
	bc		port6,5
	bc		port6,6
	jmp		MAIN_Loop_01
		
GET_KEY3:
	clr		time_5min	
	BC		KEY_FLAG,F_1S
	CLR		TIME_1S
	MOV		A,@1
	MOV		TEMP,A
	IOR		IOCF
	OR		A,TEMP		;set TICE is 1
	IOW		IOCF	
	ENI		
	inc		Key3_step
	MOV		A,@7
	and		a,Key3_step
	add		pc,a
	nop
	jmp		GET_KEY3_5min
	jmp		GET_KEY3_10min
	jmp		GET_KEY3_20min
	jmp		GET_KEY3_30min
	nop
	nop
	nop
GET_KEY3_30min:
	clr		Key3_step
	mov		a,@6
	mov		key3_temp,a
	mov		a,@11100000b
	and		port6,a
	bs		port6,4		;set led6 on
	bs		port6,5
	bs		port6,7
	jmp		GET_KEY3_count_time	
GET_KEY3_5min:
	mov		a,@1
	mov		key3_temp,a
	mov		a,@11100000b
	and		port6,a
	bs		port6,0		;set led3 on
	bs		port6,5
	bs		port6,7
	jmp		GET_KEY3_count_time	
GET_KEY3_10min:
	mov		a,@2
	mov		key3_temp,a
	mov		a,@11100000b
	and		port6,a
	bs		port6,1		;set led4 on
	bs		port6,5
	bs		port6,7
	jmp		GET_KEY3_count_time	
GET_KEY3_20min:
	mov		a,@4
	mov		key3_temp,a
	mov		a,@11100000b
	and		port6,a
	bs		port6,2		;set led5 on
	bs		port6,5
	bs		port6,7
	jmp		GET_KEY3_count_time			
GET_KEY3_count_time:
	CALL		SCAN_KEY
	JBC		KEY_FLAG,F_push
	jmp		MAIN_Loop_01_in	;key retigger
	
	JBS		KEY_FLAG,F_1S
	JMP		GET_KEY3_count_time
	bc		KEY_FLAG,F_1S
	inc		time_5min
	mov		a,@150	;set timer 5min
	xor		a,time_5min
	jbs		sf,z
	jmp		GET_KEY3_count_time
	clr		time_5min
	djz		key3_temp
	jmp		GET_KEY3_count_time
GET_KEY3_off:
	jbs		port6,6
	bc		port6,5
	mov		a,@01100000b
	and		port6,a	
	jmp		MAIN_Loop_01	
			

	
	


	
SCAN_KEY:	
	JBS		KEY_FLAG,F_keep
	JMP		SCAN_KEY_01
	JBC		PORT5,0
	JMP		END_SCAN_KEY
	JBC		PORT5,1
	JMP		END_SCAN_KEY
;	JBC		PORT6,3
	BC		KEY_FLAG,F_keep
	JMP		END_SCAN_KEY
SCAN_KEY_01:
	JBS		PORT5,0
	JMP		SCAN_KEY_02
	CALL		DELAY_10MS
	JBS		PORT5,0
	JMP		SCAN_KEY_02
	CALL		DELAY_10MS
	JBS		PORT5,0
	JMP		SCAN_KEY_02
	CALL		DELAY_10MS
	JBS		PORT5,0
	JMP		SCAN_KEY_02
	MOV		A,@1
	MOV		KEY_CNT,A
	bs		key_flag,Key1
	bc		key_flag,Key2
	bc		key_flag,Key3
	BS		KEY_FLAG,F_push
	BS		KEY_FLAG,F_keep
	JMP		END_SCAN_KEY
SCAN_KEY_02:
	JBS		PORT5,1
	JMP		SCAN_KEY_03
	CALL		DELAY_10MS
	JBS		PORT5,1
	JMP		SCAN_KEY_03
	CALL		DELAY_10MS
	JBS		PORT5,1
	JMP		SCAN_KEY_03
	CALL		DELAY_10MS
	JBS		PORT5,1
	JMP		SCAN_KEY_03
	MOV		A,@2
	MOV		KEY_CNT,A
	bs		key_flag,Key2
	bc		key_flag,Key1
	bc		key_flag,Key3
	BS		KEY_FLAG,F_push
	BS		KEY_FLAG,F_keep
	JMP		END_SCAN_KEY
SCAN_KEY_03:
	JMP		END_SCAN_KEY
	JBC		PORT6,3
	JMP		SCAN_KEY_04
	CALL		DELAY_10MS
	JBC		PORT6,3
	JMP		SCAN_KEY_04
	CALL		DELAY_10MS
	JBC		PORT6,3
	JMP		SCAN_KEY_04
	CALL		DELAY_10MS
	JBC		PORT6,3
	JMP		SCAN_KEY_04
	MOV		A,@3
	MOV		KEY_CNT,A
	bs		key_flag,Key3
	bc		key_flag,Key1
	bc		key_flag,Key2
	BS		KEY_FLAG,F_push
	BS		KEY_FLAG,F_keep
	JMP		END_SCAN_KEY	
SCAN_KEY_04:
	BC		KEY_FLAG,F_keep		
END_SCAN_KEY:
	RET	

;------------------------------------------------
; the  system  initiallization  sub_routine
INITIAL_ROUTINE:
	wdtc				; clr watchdog timer
	mov	a,@00000101b
	contw				; TCC  -> 1/128
	mov	a,@5
	mov	tcc,a			;250*32=8ms
	disi	
	mov	a,@00000111b
	iow	IOC5			; P5 -> input	
	mov	a,@00001000b
	iow	IOC6			; P66,P67,P63 -> output
	clr	PORT5
	clr	PORT6	
	mov	a,@11111000b		;set P5.0,1,2 internal pull-down
	iow	IOCB			;
	mov	a,@00000000b
	iow	IOCC			; Open_drain  control
	iow	IOCD			; set p6 pull high
	mov	a,@00000000b
	iow	IOCE			; WDT  disable	
	mov	a,@00000000b
	iow	IOCF			; ALL interrupt disable
CLEAR_ALL_RAM:	
	mov	a,@0x2f
	mov	Flag,a
	mov	a,@0x10
	mov	RSR,a			; clr RAM ( 10H~30H)
CLR_RAM:
	inc	RSR
	clr	R0			; = 0
	djz	Flag
	jmp	CLR_RAM
	clr	Flag	
	ret	
	
;------------------------------------------------
; delay  10ms  sub_routine
; Period  T = (15*257*5+143*5+11)*0.5 = 10ms
DELAY_10MS:
	mov	a,@0x10
	mov	DelayH,a
	mov	a,@0x8f
	mov	DelayL,a
LOOP_10MS:
	nop
	nop
	djz	DelayL
	jmp	LOOP_10MS
	wdtc
	nop
	djz	DelayH
	jmp	LOOP_10MS
	nop
	ret
;------------------------------------------------
; delay   1000us  sub_routine
; Period  T = (1*257*5+141*5+11)*0.5 = 1000.5us
DELAY_1MS:
	mov	a,@0x02
	mov	DelayH,a
	mov	a,@0x8d
	mov	DelayL,a
LOOP_1MS:
	nop
	nop
	djz	DelayL
	jmp	LOOP_1MS		; 5
	nop
	nop
	djz	DelayH
	jmp	LOOP_1MS		; 5*257
	nop
	ret
Delay_10us:
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop	
	ret
;------------------------------------------------
; end  program 
 	end

⌨️ 快捷键说明

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