IBM H8 user manual Key’s and LED’s, LEDSPEEDINIT4

Page 33

HTEB1

User manual

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_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

Image 33
Contents Hitachi H8/Tiny 3664F Preface Table of Contents Hardware description System Development Kit contentFeatures Board overview Board overviewJP4, D/A CON Jumpers and switchesOrientation Operation X1 SubD9, Pin Operation Remark ConnectorsX3 LCD-CON SV1 SV2 SV3 SV4 PIN Start-Up instructions Installing the HTEB1Test program Software Installation Development Environment Creating a program using IAR-EWH8HTEB1 HTEB1 HTEB1 HTEB1 HTEB1 HTEB1 HTEB1 Download the code using FDT HTEB1 HTEB1 HTEB1 HTEB1 HTEB1 HTEB1 HTEB1 Workflow Examples LEDSPEEDINIT4 Key’s and LED’sPMR1 &= ~KEYALL RunningLightInit Init keys and LEDs TimerAInit LCD Clearlcdrs Setlcdrw Lcddatactrl = Lcdin Setlcden HTEB1 Isscitxfree SCIInit sci with 9600Baud, 8N1 A/D + PWM Lcddatactrl = Lcdin Setlcden Calculate av of last 15 values AT-Keyboard-Interface Setlcdrw Lcddatactrl = Lcdin Setlcden Mask = Msg buffer Tables Scan-Codes MFII-Keyboard Numeric Keypad Main Scan-Code Keypad Function Scan-Code Programs DatasheetsExamples DemoAppendix B Schematic Appendix C Board layout HTEB1 HTEB1 HTEB1