?? 2604_template.asm
字號:
;*******************************************************************************
; FILENAME : 2604_TEMPLATE.ASM for S8KE ICE
; AUTHOR : SONiX
; PURPOSE : Template Code for SN8P2604
; 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 SN8P2604 ; 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
;-----------------------------------
push ;Save A and Pflag
;b0xch A,AccBuf ;B0xch instruction do not change C,Z flag
;b0mov A,PFLAG
;b0mov PflagBuf,A
;-----------------------------------
; Interrupt service routine
;-----------------------------------
INTP00CHK: ; Check INT0 interrupt request
B0BTS1 FP00IEN ; Check P00IEN
JMP INTTC1CHK ; Jump check to next interrupt
B0BTS0 FP00IRQ ; Check P00IRQ
JMP INTP00 ; Jump to INT0 interrupt service routine
INTTC1CHK: ; Check TC1 interrupt request
B0BTS1 FTC1IEN ; Check TC1IEN
JMP INT_EXIT ; Jump to exit of IRQ
B0BTS0 FTC1IRQ ; Check TC1IRQ
JMP INTTC1 ; Jump to TC1 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
;-------------------------------------------------------------------------------
; TC1 interrupt service routine
;-------------------------------------------------------------------------------
INTTC1:
b0bclr FTC1IRQ
;Process TC1 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 + -