IBM H8 Network Card User Manual


 
HTEB1
User manual
Issue 0.2 Page 33 07/2002
3.1 Key’s and LED’s
The first demo program shows the usage of LEDs and keys on HTEB1. For
time-controlling we use TIMER_A as an periodic interval timer. The
interrupt service routine (isr) is checking the state of the keys, actualising
the LED port and reading out the AD1-channel to determine the running
light speed. If you want to do some experiments, first check out to find if
other LED pattern maybe in form of a table read out or calculate them by
functions developed by yourself. If speed control should be changed, first
change the calculation of the A/D-conversion value to timer ticks.
/*------------------------------------------------------------------
** 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_1|KEY_2|KEY_3|KEY_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;