📄 led.c
字号:
/*--------------------------------------------------------------------------
LED.C
LED access macros and functions for the DE51-S by Windsun
--------------------------------------------------------------------------*/
#include <LED.h>
#define P_IOA_Data (volatile unsigned int *)0x7000
#define P_IOA_Buffer (volatile unsigned int *)0x7001
#define P_IOA_Dir (volatile unsigned int *)0x7002
#define P_IOA_Attrib (volatile unsigned int *)0x7003
#define P_IOB_Data (volatile unsigned int *)0x7005
#define P_IOB_Buffer (volatile unsigned int *)0x7006
#define P_IOB_Dir (volatile unsigned int *)0x7007
#define P_IOB_Attrib (volatile unsigned int *)0x7008
#define P_Watchdog_Clear (volatile unsigned int *)0x7012
#ifdef INTOUT
#define DELAY 300
unsigned char dig[4];
void delayfordig()
{unsigned int i;
for(i=0;i<=DELAY;i++);
}
void setdig_dec(unsigned int *toshow)
{
dig[0]=*toshow%10;
dig[1]=(*toshow/10)%10;
dig[2]=(*toshow/100)%10;
dig[3]=(*toshow/1000)%10;
};
void setdig_hex(unsigned int *toshow)
{dig[0]=*toshow&0x000f;
dig[1]=(*toshow>>4) &0x000f;
dig[2]=(*toshow>>8)&0x000f;
dig[3]=(*toshow>>12)&0x000f;
}
void showdig()
{
static unsigned int num;
for(num=0;num<4;num++)
{
*P_IOA_Data=NUMTOSEG7(dig[num],0);
*P_IOB_Data=(*P_IOB_Data&0xffc7)|(0x20>>num)|0x0004;
delayfordig();
}
}
#endif
unsigned char NUMTOSEG7(unsigned char DATA,unsigned char point)
{ unsigned char AA;
switch (DATA)
{ case 0: AA=0x3f;break; /* ‘0’*/
case 1: AA=0x06;break; /* ‘1’*/
case 2: AA=0x5b;break; /* ‘2’*/
case 3: AA=0x4f;break; /* ‘3’*/
case 4: AA=0x66;break; /* ‘4’*/
case 5: AA=0x6d;break; /* ‘5’*/
case 6: AA=0x7d;break; /* ‘6’*/
case 7: AA=0x07;break; /* ‘7’*/
case 8: AA=0x7f;break; /* ‘8’*/
case 9: AA=0x6f;break; /*9*/
case 10:AA=0x77;break; /*A*/
case 11:AA=0x7c;break; /*b*/
case 12:AA=0x39;break;/*c*/
case 13:AA=0x5e;break;/*d*/
case 14:AA=0x79;break;/*E*/
case 15:AA=0x71;break;/*F*/
default: AA=0x00;
}
if(point)AA|=0x80;
return(AA);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -