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

📄 wake.c

📁 Mitsubishi M30245 SampleCode
💻 C
字号:
/*****************************************************************************
*
*	File Name:   wake.c                                        
*                                                                  
*	Content:
*		Sample key-on wakeup program.   This program puts the CPU
*   	to sleep, then wakes-up when one of the two keys (S3 or S4)
*   	is pressed.  A corresponding LED will then light for a few 
*    	seconds indicating which key was pressed.
*  		The CPU then goes back to sleep.
*
*  		Version: 1.1
*       Released:  08-29-2002           
*                                                                  
*	Copyright 2002 Mitsubishi Electric & Electronics USA, Inc.                           
*	All rights reserved                                            
*                                                                  
*=============================================================================
*	$Log:$
*===========================================================================*/


#include "sfr245.h"		/* Include M30245 header file */

/*	Setup interrupt routine for key-on wakeup
	 This must also be setup in the vector table in SECT30.INC */

#pragma INTERRUPT /B  Key_wakeup_ISR



/*****************************************************************************
Name:   Main        
Parameters:                     
Returns:        
Description:  This is the main program area    

*****************************************************************************/
   

main()
{
	unsigned long delay; 	/* declare variable for program delay */

	pd10 = 0x00;   	/* Configure port 10 as all inputs */
	pd7 = 0xFF;	 	/* Configure port 7 as all outputs */
	p7 = 0x0F;		/* Initialize port7	- All Leds off */
	
	pu25 = 0;	 	/* Pull-up resistors are already on the board */
	kupm = 0x20;	/* P10_6 and P10_7 key-input enable on falling edge */
	
	asm ("FSET I");	/* enable global interrupts */
	prc0 = 1;		/* enable writing to clock registers */
	 
/**************** Program Loop ***********************/

	while (1)
	{
		kupic = 0x04;	/* Set key input interrupt to level 4 */

	 	cm10 = 1;	 	/* stop clock */

		for (delay=0x2FF00; delay>0; delay--)	  /* approx 3 second delay after */
			asm ("NOP");						  /* wake-up to display key value */

	 	p7 = 0x0F;		/* turn all LED's off before stopping clock again */
	}
}


/*****************************************************************************
Name:  Key interrupt routine         
Parameters:                     
Returns:        
Description: This interrupt occurs after a key is pressed and the CPU wakes
 			  up. One of the LEDs is turned on corresponding to which
			  key was pressed.
*****************************************************************************/

void Key_wakeup_ISR (void)    
{							
	int key;					/* Declare key pressed variable */ 
	unsigned debounce;			/* Declare debounce delay variable */		

	asm ("NOP");				/* Four NOPs are recommended to clear the */
	asm ("NOP");				/*  instruction queue after returning from */
	asm ("NOP");				/*  stop mode. */
	asm ("NOP");

	kupic = 0x00;			/* Disable key input interrupt */

	for (debounce=0xff; debounce>0; debounce--)	/* key debounce delay */
		asm ("NOP");

		key = p10; 				/*  load P10 value into key */
		if (p10_6 == 0)			/* sw3 was pressed */
		   	p7_1 = 0;			/* turn on led D1 */
		else if (p10_7 == 0)	/* sw4 was pressed */
			p7_0 = 0;			/* turn on led D0 */
		else
			p7_3 = 0;			/* error */		
	
	while ((p10_6 != 1) && (p10_7 != 1));   	/* wait for key to be released */

	for (debounce=0xff; debounce>0; debounce--)  /* key debounce delay	*/
		asm ("NOP");
}

⌨️ 快捷键说明

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