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

Page 43
Image 43
IBM H8 user manual Calculate av of last 15 values