IBM H8 user manual Calculate av of last 15 values

Page 43

HTEB1

User manual

{

 

 

u8 *data, *text, c,d;

 

 

if (line==0) text = &Line0[0];

// last digit = start address

else text = &Line1[0];

 

 

data = text+14;

 

 

d=3;

 

 

while (d)

 

 

{

 

 

*data = '0';

 

// default = '0'

c = code & 0x000f;

 

// check digit

if (c)

 

// if > 0 chk for value

{

 

 

if (c < 10) *data = '0'+c;

// 0..9

else *data = 'A'+c-10;

 

// a..f

}

 

 

data--;

 

// next digit

code >>= 4;

 

 

d--;

 

 

}

 

 

LCDWriteLine(line,text);

// show result

}

 

 

void Delay(void)

 

// "manual" delay

{

 

 

long z = 0x010000;

 

 

while(--z);

 

 

}

 

 

u16 oldval[2];

 

 

u16 Average(u8 channel, u16 adval)

// calculate av of last 15 values

{

 

 

if ((abs)(oldval[channel]-adval)>10) oldval[channel]=adval;

else

oldval[channel] = ((oldval[channel]*15)+adval)>>4; return oldval[channel];

}

/**************************************** TimerV-Test

setup : CLK/8 (=1µs @ 8MHz) PWM-Output at TMOV (P76)

****************************************/

void Test_Timer_V(void)

{

 

TCRV0 = 0x080x01;

// Clear by CompMatchA; IntClk/8

TCRV1 = 0x01;

// Clk/2, no external Trigger

TCSRV = 0x080x01;

// 0=onCompMatchA, 1=onCompMatchB (output on P76)

TCORA = 100;

// set periode to 100 => 10.000Hz

TCORB = 75;

// set init dutycycle to 75%

}

 

void main(void)

 

{

 

u16 val;

 

LCDInit();

// init ports and LCD

Test_Timer_V();

// for PWM-Output

while(1)

// do forever...

{

val = Average(0,Read_AD(0)); ShowHexValue(val,0);

val = Average(1,Read_AD(1)); ShowHexValue(val,1);

val /= 10; // max. 1023/10 = 102

TCORB = (unsigned char)(val & 0xff); // set PWM-output Delay();

}

}

Issue 0.2

Page 43

07/2002

Image 43
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 Demo DatasheetsPrograms ExamplesAppendix B Schematic Appendix C Board layout HTEB1 HTEB1 HTEB1