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

📄 2602a_template.asm

📁 松翰(SONIX)单片机的一个温控实例,对初级应用松翰的软件工程师可以参考下
💻 ASM
字号:
;*******************************************************************************
; FILENAME	: 2602A_TEMPLATE.ASM for S8KE ICE
; AUTHOR	: SONiX
; PURPOSE	: Template Code for SN8P1602
; REVISION	: 06/05/2004 V1.0	First issue
;               : 07/07/2004 V1.1	Remove ICE_MODE definition and some macro
;                                       for SN8ICE 2K and Add push/pop in ISR
;*******************************************************************************
;*  (c) Copyright 2004, SONiX TECHNOLOGY CO., LTD.
;*******************************************************************************

CHIP		SN8P2602A	; Select the CHIP
//{{SONIX_CODE_OPTION
	.Code_Option	Noise_Filter	Enable
	.Code_Option	Reset_Pin	Reset
	.Code_Option	Watch_Dog	Disable		; Disable Watchdog
	.Code_Option	High_Clk	4M_X'tal	; Crystal/Resonator: 2Mhz~10Mhz
	.Code_Option	Fcpu		#2     ; Fcpu = High_Clk/4
	.Code_Option	Security	Disable
//}}SONIX_CODE_OPTION

;-------------------------------------------------------------------------------
;			Include Files
;-------------------------------------------------------------------------------
.nolist							; do not list the macro file

	INCLUDESTD		MACRO1.H
	INCLUDESTD		MACRO2.H
	INCLUDESTD		MACRO3.H

.list							; Enable the listing function
	
;-------------------------------------------------------------------------------
;			Constants Definition
;-------------------------------------------------------------------------------
;	ONE		EQU	1

;-------------------------------------------------------------------------------
;			Variables Definition
;-------------------------------------------------------------------------------
.DATA
			org	0h			;Data section start from RAM address 0
	Wk00		DS	1			;Temporary buffer for main loop
	Iwk00		DS	1			;Temporary buffer for ISR
	AccBuf		DS	1			;Accumulater buffer
	PflagBuf	DS	1			;PFLAG buffer
	t1		DS	1	

;-------------------------------------------------------------------------------
;			Bit Variables Definition
;-------------------------------------------------------------------------------

	Wk00B0	    	EQU     Wk00.0 		     	;Bit 0 of Wk00
	Iwk00B1		EQU     Iwk00.1  	   	;Bit 1 of Iwk00
 
;-------------------------------------------------------------------------------
;			Code section
;-------------------------------------------------------------------------------
.CODE								

		ORG	0				;Code section start
	jmp		Reset				;Reset vector
							;Address 4 to 7 are reserved
		ORG	8				
	jmp		Isr				;Interrupt vector

		ORG	10h
;-------------------------------------------------------------------------------
; 			Program reset section
;-------------------------------------------------------------------------------
Reset:

	mov 	    	A,#07Fh				;Initial stack pointer and
   	b0mov 		STKP,A				;disable global interrupt	
	clr		PFLAG				;pflag = x,x,x,x,x,c,dc,z
	mov     	A,#00h				;Initial system mode
	b0mov   	OSCM,A
		
	mov		A, #0x5A
	b0mov		WDTR, A				;Clear watchdog timer	

    	call    	ClrRAM				;Clear RAM
    	call    	SysInit				;System initial
    	b0bset  	FGIE				;Enable global interrupt

;-------------------------------------------------------------------------------
; 			Main routine
;-------------------------------------------------------------------------------
Main:
	mov		A, #0x5A
	b0mov		WDTR, A				;Clear watchdog timer	

     	call		MnApp

	jmp		Main

;-------------------------------------------------------------------------------
; 			Main application
;-------------------------------------------------------------------------------
MnApp:

	;---------------------------------------------------------------
	; Put your main program here
	;---------------------------------------------------------------
	

	ret

;-----------------------------------
; Jump table routine
;-----------------------------------
		ORG	0x0100				;The jump table should start from the head 
							;of boundary.
	b0mov		A,Wk00              
	and		A,#3
	ADD         	PCL,A
	jmp         	JmpSub0
	jmp         	JmpSub1
	jmp         	JmpSub2
;----------------------------------- 

JmpSub0:
	; Subroutine 1
	jmp		JmpExit

JmpSub1:
	; Subroutine 2
	jmp		JmpExit

JmpSub2:
	; Subroutine 3
	jmp		JmpExit

JmpExit:
	ret						;Return Main

;-------------------------------------------------------------------------------
; Isr (Interrupt Service Routine)
; Arguments	:
; Returns	:
; Reg Change:
;-------------------------------------------------------------------------------
Isr:
;-----------------------------------
; Save ACC
;-----------------------------------

	;b0xch	  	A,AccBuf			;B0xch instruction do not change C,Z flag
	;b0mov       	A,PFLAG
   	;b0mov       	PflagBuf,A
   	push						;Save A and Pflag

;-----------------------------------
; Interrupt service routine  
;-----------------------------------
		
INTP00CHK:						; Check INT0 interrupt request
	B0BTS1	FP00IEN					; Check P00IEN
	JMP	INTTC0CHK				; Jump check to next interrupt
	B0BTS0	FP00IRQ					; Check P00IRQ
	JMP	INTP00					; Jump to INT0 interrupt service routine
INTTC0CHK:						; Check TC0 interrupt request
	B0BTS1	FTC0IEN					; Check TC0IEN
	JMP	INT_EXIT				; Jump to exit of IRQ
	B0BTS0	FTC0IRQ					; Check TC0IRQ
	JMP	INTTC0					; Jump to TC0 interrupt service routine

;-----------------------------------
; Exit interrupt service routine
;-----------------------------------

INT_EXIT:

	pop						;Restore A and Pflag
	
   	;b0mov       	A, PflagBuf
	;b0mov       	PFLAG, A			;Restore the PFlag
	;b0xch		A,AccBuf			;Restore the Reg. A
							;B0xch instruction do not change C,Z flag
	reti						;Exit the interrupt routine

;-------------------------------------------------------------------------------
;	INT0 interrupt service routine
;-------------------------------------------------------------------------------
INTP00:
	b0bclr	FP00IRQ

	;Process P0.0 external interrupt here

	jmp	INT_EXIT
;-------------------------------------------------------------------------------
;	TC0 interrupt service routine
;-------------------------------------------------------------------------------
INTTC0:
	b0bclr	FTC0IRQ

	;Process TC0 timer interrupt here

	jmp	INT_EXIT
;-------------------------------------------------------------------------------
; SysInit
; System initial to define Register, RAM, I/O, Timer......
;-------------------------------------------------------------------------------
SysInit:

	

	ret

;-------------------------------------------------------------------------------
; ClrRAM
; Use index @YZ to clear RAM (00h~2Fh)
;-------------------------------------------------------------------------------

ClrRAM:

	clr 		Y
	mov		A, #0x2F		 
	b0mov		Z, A				;Set @YZ address from 2fh

ClrRAM10:
	clr 		@YZ				;Clear @YZ content
	decms		Z   				;z = z - 1 , skip next if z=0
	jmp 		ClrRAM10 
	clr 		@YZ				;Clear address $00

	ret

;-------------------------------------------------------------------------------
	ENDP
 

⌨️ 快捷键说明

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