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

📄 led.c

📁 DSP56F800e HYBRID Controller
💻 C
字号:




/*  metrowerks sample code  */



/*
	this source illustrates code called by ISR 
	and #pragma directives necessary for ISR-safe code		
*/



#include "MC56F835x.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 */       /* factored out for clarity */
	asm(bfclr	#$0001,X:GPIO_C_PER);  /* LED1 PC0 -- GPIO Port C Bit0 */
	asm(bfclr	#$0002,X:GPIO_C_PER);  /* LED2 PC1 -- GPIO Port C Bit1 */
	asm(bfclr	#$0004,X:GPIO_C_PER);  /* LED3 PC2 -- GPIO Port C Bit2 */
	asm(bfclr	#$0008,X:GPIO_C_PER);  /* LED4 PC3 -- GPIO Port C Bit3 */
	asm(bfclr	#$0040,X:GPIO_D_PER);  /* LED5 PD6 -- GPIO Port D Bit6 */
	asm(bfclr	#$0080,X:GPIO_D_PER);  /* LED6 PD7 -- GPIO Port D Bit7 */
	                                   /* note: some '36E EVM have led 6 & 7 mislabeled */
	
	/* output direction */
	asm(bfset	#$0001,X:GPIO_C_DDR);
	asm(bfset	#$0002,X:GPIO_C_DDR);
	asm(bfset	#$0004,X:GPIO_C_DDR);
	asm(bfset	#$0008,X:GPIO_C_DDR);
	asm(bfset	#$0040,X:GPIO_D_DDR);
	asm(bfset	#$0080,X:GPIO_D_DDR);
	
	
	/* off at first */
	offLED_1();
	offLED_2();
	offLED_3();
	offLED_4();
	offLED_5();
	offLED_6();
}




/* 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:
			onLED_1();
			break;
		case 2:
			onLED_2();
			break;
		case 3:
			onLED_3();
			break;
		case 4:
			onLED_4();
			break;
		case 5:
			onLED_5();
			break;
		case 6:
			onLED_6();
			break;
		default:
			asm(debughlt);	/* 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:
			offLED_1();
			break;
		case 2:
			offLED_2();
			break;
		case 3:
			offLED_3();
			break;
		case 4:
			offLED_4();
			break;
		case 5:
			offLED_5();
			break;
		case 6:
			offLED_6();
			break;
		default:
			asm(debughlt);	/* not a graceful error handling, just freeze */
			break;
	}
}




void offLED_1()
{
    asm(bfclr #$0001,X:GPIO_C_DR);
}



void offLED_2()
{
	asm(bfclr #$0002,X:GPIO_C_DR);
}



void offLED_3()
{
	asm(bfclr #$0004,X:GPIO_C_DR);
}



void offLED_4()
{
	asm(bfclr #$0008,X:GPIO_C_DR);
}



void offLED_5()
{
	asm(bfclr #$0040,X:GPIO_D_DR);
}



void offLED_6()
{
	asm(bfclr #$0080,X:GPIO_D_DR);
}




void onLED_1()
{
    asm(bfset #$0001,X:GPIO_C_DR);
}



void onLED_2()
{
	asm(bfset #$0002,X:GPIO_C_DR);
  
	
}



void onLED_3()
{
	asm(bfset #$0004,X:GPIO_C_DR);
}



void onLED_4()
{
	asm(bfset #$0008,X:GPIO_C_DR);
}



void onLED_5()
{
	asm(bfset #$0040,X:GPIO_D_DR);
}



void onLED_6()
{
	asm(bfset #$0080,X:GPIO_D_DR);
}











⌨️ 快捷键说明

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