led.c

来自「Freescale 56800系列DSP的参考C语言源代码」· C语言 代码 · 共 109 行

C
109
字号
/*-----------------------------------------------------------------------*

	Sample Code for DSP56800 - Jan 2002
	(c) Metrowerks, A Motorola Company.
	
	Source code to illustrate writing library in C called by ISR 
	and the usage for #pragma directives necessary for buildling 
	libraries that are safe to be called by an ISR.
		
 *-----------------------------------------------------------------------*/


#include "56805.h"
#include "led.h"

/* libraries called by interrupt handlers need this pragma, it will:
1. save used register
2. return with RTS instead of RTI */
#pragma interrupt called

void initLED()
{
	/* disable SSI peripheral */
	asm(bfclr	#$0001,X:GPIO_B_PER);
	asm(bfclr	#$0002,X:GPIO_B_PER);
	asm(bfclr	#$0004,X:GPIO_B_PER);
	
	/* output direction */
	asm(bfset	#$0001,X:GPIO_B_DDR);
	asm(bfset	#$0002,X:GPIO_B_DDR);
	asm(bfset	#$0004,X:GPIO_B_DDR);
	
	/* off at first */
	asm(bfclr	#$0001,X:GPIO_B_DR);
	asm(bfclr	#$0002,X:GPIO_B_DR);
	asm(bfclr	#$0004,X:GPIO_B_DR);
}

/* libraries called by interrupt handlers need this pragma, it will:
1. save used register
2. return with RTS instead of RTI */
#pragma interrupt called

void onLED(int element)
{
	switch (element)
	{
		case 1:
			asm(bfset	#$0001,X:GPIO_B_DR);
			break;
		case 2:
			asm(bfset	#$0002,X:GPIO_B_DR);
			break;
		case 3:
			asm(bfset	#$0004,X:GPIO_B_DR);
			break;
		default:
			asm(debug);	/* not a graceful error handling, just freeze */
			break;
	}
}

/* libraries called by interrupt handlers need this pragma, it will:
1. save used register
2. return with RTS instead of RTI */
#pragma interrupt called

void offLED(int element)
{
	switch (element)
	{
		case 1:
			asm(bfclr	#$0001,X:GPIO_B_DR);
			break;
		case 2:
			asm(bfclr	#$0002,X:GPIO_B_DR);
			break;
		case 3:
			asm(bfclr	#$0004,X:GPIO_B_DR);
			break;
		default:
			asm(debug);	/* not a graceful error handling, just freeze */
			break;
	}
}

/* libraries called by interrupt handlers need this pragma, it will:
1. save used register
2. return with RTS instead of RTI */
#pragma interrupt called

void toggleLED(int element)
{
	switch (element)
	{
		case 1:
			asm(bfchg	#$0001,X:GPIO_B_DR);
			break;
		case 2:
			asm(bfchg	#$0002,X:GPIO_B_DR);
			break;
		case 3:
			asm(bfchg	#$0004,X:GPIO_B_DR);
			break;
		default:
			asm(debug);	/* not a graceful error handling, just freeze */
			break;
	}
}

⌨️ 快捷键说明

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