eecs-bsp-test-code/key/source/main.c

82 lines
2.5 KiB
C

// This project is used for demonstrating digital tubes of BSP library.
#include "STC15F2K60S2.H"
#include "displayer.h"
#include "key.H"
#include "sys.H"
code unsigned long SysClock = 11059200; //必须。定义系统工作时钟频率(Hz),用户必须修改成与实际工作频率(下载时选择的)一致
#ifdef _displayer_H_ //显示模块选用时必须。(数码管显示译码表,用戶可修改、增加等)
code char decode_table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x00, 0x08, 0x40, 0x01, 0x41, 0x48,
/* 序号: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
/* 显示: 0 1 2 3 4 5 6 7 8 9 (无) 下- 中- 上- 上中- 中下- */
0x3f | 0x80, 0x06 | 0x80, 0x5b | 0x80, 0x4f | 0x80, 0x66 | 0x80, 0x6d | 0x80, 0x7d | 0x80, 0x07 | 0x80, 0x7f | 0x80, 0x6f | 0x80};
/* 带小数点 0 1 2 3 4 5 6 7 8 9 */
#endif
char changeBit(char x, char n, char y)
{
char temp = x;
temp &= ~(1 << n);
temp |= (y << n);
return temp;
}
void display_key()
{
static char status[8]={10,10,10,10,10,10,10,10};
static char led = 0x0;
char key1 = GetKeyAct(enumKey1), key2 = GetKeyAct(enumKey2), key3 = GetKeyAct(enumKey3);
switch (key1)
{
case enumKeyPress:
status[5] = 1;
led=changeBit(led, 0, 1);
break;
case enumKeyRelease:
status[5] = 10;
led=changeBit(led, 0, 0);
break;
}
switch (key2)
{
case enumKeyPress:
status[6] = 2;
led=changeBit(led, 1, 1);
break;
case enumKeyRelease:
status[6] = 10;
led=changeBit(led, 1, 0);
break;
}
switch (key3)
{
case enumKeyPress:
status[7] = 3;
led=changeBit(led, 2, 1);
break;
case enumKeyRelease:
status[7] = 10;
led=changeBit(led, 2, 0);
break;
}
status[0]=led/10;
status[1]=led%10;
Seg7Print(status[0], status[1], status[2], status[3], status[4], status[5], status[6], status[7]);
LedPrint(led);
}
void main()
{
DisplayerInit();
KeyInit();
SetDisplayerArea(0, 7);
SetEventCallBack(enumEventKey, display_key);
MySTC_Init();
LedPrint(0xff);
Seg7Print(10, 10, 10, 10, 10, 10, 10, 10);
while (1)
{
MySTC_OS();
}
}