📄 led.c
字号:
/*-----------------------------------------------------------------------*
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -