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

📄 sleep.asm

📁 the sleep file .the program is used to goto sleep mode.
💻 ASM
字号:
//-----------------------------------------------------------
//Program Name:		DTMFDial.asm
//Applied Body:		SPT6604A
//Project description:	This is a Demo code for sleep and wakeup
//Compile:		Sunplus u'nSP IDE
//Programmer:		WangXu
//Current Version:	1.0
//Write Date:		2002/11/05
//-----------------------------------------------------------
.include		SPT6605.INC
.include		KeyScan.ASM
.include		Display.ASM
.const			CW_StackBottom	=0x05ff
.public			_FIQ
.public			_IRQ0
.public			_IRQ1
.public			_IRQ2
.public			_IRQ3
.public			_IRQ4
.public			_IRQ5
.public			_IRQ6
.public			_IRQ7
.public			_BREAK
.public			_main
//---------------------------------------------------------
.RAM
RW_WakeUpBuf:		.dw		0
RW_SleepTime:		.dw		0
//---------------------------------------------------------
.Code
_main:
	int	off			//Disable FIQ and IRQ
	r1 =	0x55aa			//Reset watchdog
	[P_WatchdogClr] = r1
	sp =	CW_StackBottom		//Initial stack pointer
	r1 =	B_NormalCpuClock
	[P_SystemClock] = r1		//Give proper CPU clock
	r1 =	B_2Hz+B_128Hz+B_512Hz+B_Enable32768
	[P_TimeBaseSet] = r1		//Initial timebase
	r1 =	0x0000
	[P_WakeUp] = r1			//Disable all wake up sourcese
	r1 =	[P_WakeUpClr]
	[P_WakeUpClr] = r1		//Clear all wake up event flags
	test	r1,0x03ff
	jz	?L_PowerOnInit
	[RW_WakeUpBuf] = r1		//Store wake up flag
	test	r1,0x0080		//Check if 2Hz timer wake up
	jz	?L_TwoHzWakeCheckOk	//No
	nop
	nop
	nop
	Call	F_IRQ7Service		//Yes, call 2Hz timer service routine
?L_TwoHzWakeCheckOk:
	r1 =	[RW_WakeUpBuf]
	test	r1,B_IoaInt		//Check if IOA wake up
	jz	?L_NotIOAWakeUp		//No
	r1 =	0x0030			//Yes, set automatic sleep time limit
	[RW_SleepTime] = r1		//for key scan
?L_NotIOAWakeUp:
	goto	?L_InitInt
?L_PowerOnInit:
	r1 =	0x0000
	[P_IOA_Dir] = r1		//Set IOA0~IOA7 as input ports
	r1 =	0x001f
	[P_IOB_Dir] = r1		//Set IOB0~IOB5 as Output ports
	r1 =	0x1f00
	[P_IOA_PullR] = r1		//Enable Pull-high Resistor of IOA0~IOA4
	
	r1 =	0x0000			//Clear RAM
	r2 =	r1
?L_ClrRamLoop:
	[r2++]	=r1
	cmp	r2,0x400
	jb	?L_ClrRamLoop

	r2 =	0x7100			//Clear LCD display RAM
?L_ClrLcdLoop:
	[r2++]	= r1
	cmp	r2,0x711c
	jb	?L_ClrLcdLoop

	r1 =	0x00cf
	[P_LcdCtrl]=r1			//Enable LCD display

	r1 =	0x1104
	[RW_Date] = r1			//Initialize date
	r1 =	0x0917
	[RW_Time] = r1			//Initialize time
	
	call	F_ShowMonthDay		//Show date and time on LCD
	call	F_ShowDate
	call	F_ShowTime
?L_InitInt:

	r1 =	B_2HzInt+B_512HzInt	
	[P_Int] = r1
	INT	FIQ,IRQ
//---------------------------------------------------------	
L_MainLoop:
	R1 =	0x55aa
	[P_WatchdogClr] = R1
	call	F_KeyScan
	R1 =	0x55aa
	[P_WatchdogClr] = R1
	call	F_KeyDeal
	r1 =	[RW_SleepTime]
	jnz	L_MainLoop
//---------------------------------------------------------
F_GotoSleep:
	int	off
	r1 =	0x03ff			//Clear all interrupt event flags
	[P_IntClr] = r1
	r1 =	0x0000			//Disable all interrupt resourcese
	[P_Int]	= r1
	r1 =	0x0082			//Enable 2Hz wakeup and IOA wake up
	[P_WakeUp] = r1
	r1 =	0x001F
	[P_IoaWakeUp] = r1		//Eanble IOA0~IOA4 wake up
	r1 =	0x0000
	[P_IOB_Data] = r1		//IOB0~IOB4 output low voltage
	r1 =	[P_IOA_Latch]		//Latch the current pad status of 
					//IOA0~IOA7 for key-change wakeup function
	r1 =	0x0007
	[P_SystemClock] = r1		//Enter sleep mode
//--------------------------------------------------------------
//Key Deal Routine
//--------------------------------------------------------------
F_KeyDeal:
	R2 =	[RPtr_KeyQueueBuf]
	test	r2,0x0f00		//Check if have key in key buffer
	jnz	?L_KeyValueNotNull	
	goto	?L_KeyDealOver		//No, key deal over
?L_KeyValueNotNull:
	r2&=	0x000f			//Yes, get key index in buffer
	
	R3 =	R2 lsr 1		//Get key value
	R3+=	SW_KeyQueueBuf
	R1 =	[R3]			
	test	R2,0x0001
	jz	?L_KeyValueOk
	R1 =	R1 lsr 4
	R1 =	R1 lsr 4
?L_KeyValueOk:
	R1&=	0x00ff
	
	R2 =	[RPtr_KeyQueueBuf]	//Key buffer point shift
	R2+=	0x0001			//to next key value
	R2-=	0x0100
	R2&=	0xfff7
	[RPtr_KeyQueueBuf] = R2
//--------------------------------------------------------------
	cmp	r1,0x000d		//Check if numeric key
	ja	?L_KeyDealOver		//No, not deal with it

	bp =	Digit13			//Yes, show it on LCD
	r2 =	r1
	call	F_ShowDigit
?L_KeyDealOver:
	retf
//--------------------------------------------------------------
F_IRQ7Service:
	r1 =	[P_ColonSeg]		//Flash colon on LCD
	r1^=	B_ColonCom
	[P_ColonSeg] = r1
	retf
//--------------------------------------------------------------

//--------------------------------------------------------------
//Interrupt Routine
.TEXT
_FIQ:	
	push r1,r5 to [sp]
	r1=	B_Ioc1Int
	[P_IntClr] = r1 	
	pop r1,r5 from [sp]
	reti 
//----------------------------------------------------------
_IRQ0:	
	push	r1,r5 to [sp] 
	r1=	B_Ioc0Int+B_RiInt
	[P_IntClr] = r1
	pop r1,r5 from [sp] 
	reti
//----------------------------------------------------------
_IRQ1:	
	push	r1,r5 to [sp]
	r1 =	B_IoaInt
	[P_IntClr] = r1
	pop	r1,r5 from [sp]
	reti 
//----------------------------------------------------------
_IRQ2:	
	push r1,r5 to [sp]
	r1=	B_TmrAInt
	[P_IntClr] = r1
	pop	r1,r5 from [sp]
	reti 
//----------------------------------------------------------
_IRQ3:
	push	r1,r5 to [sp];
	r1 = 	B_TmrBInt
	[P_IntClr] = r1
	pop	 r1,r5 from [sp]
	reti 
//----------------------------------------------------------
_IRQ4:
	push	r1,r5 to [sp];
	r1 = 	B_T32KHzInt
	[P_IntClr] = r1
	pop	 r1,r5 from [sp]
	reti
//---------------------------------------------------------
_IRQ5:
	push	r1,r5 to [sp] 
	r1=	B_T2KHzInt 
	[P_IntClr] = r1
	
	call	F_KeyTimerService
	
	r1 =	[RW_SleepTime]
	jz	?L_SleepTimeOver
	r1-=	0x0001
	[RW_SleepTime] = r1
?L_SleepTimeOver: 

	pop	r1,r5 from [sp] 
	reti 
//--------------------------------------------------------------
_IRQ6:
	push	r1,r5 to [sp] 
	r1 =	B_T128HzInt 
	[P_IntClr] = r1
	pop	r1,r5 from [sp] 
	reti 
//--------------------------------------------------------------
_IRQ7:
 	push	r1,bp to [sp]
	r1 =	B_T8HzInt
	[P_IntClr] = r1
	call	F_IRQ7Service
	pop	r1,bp from [sp] 
	reti 
//--------------------------------------------------------------
_BREAK:
	reti
//--------------------------------------------------------------

⌨️ 快捷键说明

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