HTEB1
User manual
3.1 Key’s and LED’s
The first demo program shows the usage of LEDs and keys on HTEB1. For
**KeysLEDs.c contains some sample code for using LEDs and Key's
**on TinyEvalBoard
**in addition Timer_A is used for timer tick with irq
#include "mydefs.h" | // for all nec. includes | |
/* defines */ |
|
|
#define KEY_1 | 0x10 |
|
#define KEY_2 | 0x20 |
|
#define KEY_3 | 0x04 |
|
#define KEY_4 | 0x02 |
|
#define KEY_ALL | (KEY_1KEY_2KEY_3KEY_4) | ||
#define KEY_RELEASED | 0x40 |
| |
#define | KEY_PROCESSED | 0x80 |
|
#define | LED_SPEED_INIT4 | // = 4/32 = 1/8s = 125ms |
/* variables */ u8 KeyCode=0;
u8 LED_Out, LED_Dir, LED_Run, LED_Speed;
/* functions */ void KeyCheck(void)
{
if ((PDR1 & KEY_ALL) != KEY_ALL) // is any key pressed ?
{
if (!(PDR1 & KEY_1)) KeyCode = KEY_1;
else if (!(PDR1 & KEY_4)) KeyCode = KEY_4; else if (!(PDR1 & KEY_3)) KeyCode = KEY_3; else if (!(PDR1 & KEY_2)) KeyCode = KEY_2;
} |
|
else |
|
{ |
|
KeyCode = KEY_RELEASED; | // no, mark key_released |
} |
|
} |
|
void RunningLightUpdate(void) | // check for keypresse |
{ | // and update LEDs |
u8 dummy; |
|
u16 adval; |
|
if (!(KeyCode & KEY_RELEASED))
{
if ((KeyCode & KEY_1)==KEY_1) LED_Dir = 1;
else if ((KeyCode & KEY_4)==KEY_4) LED_Dir = 0; else if ((KeyCode & KEY_2)==KEY_2) LED_Run = 0; else if ((KeyCode & KEY_3)==KEY_3) LED_Run = 1; KeyCode = KEY_RELEASED;
Issue 0.2 | Page 33 | 07/2002 |