IBM H8 user manual A/D + Pwm

Page 41

HTEB1

User manual

3.4 A/D + PWM

This sample shows the usage of the A/D converter. We sample the voltage of P1/P2, filter it and show the result on the LCD. On D/A-Con you will see a reversed voltage at P2 – built with a RC-filter from TOW (P76).

/*------------------------------------------------------------------

**AD_PWM Demo shows some funcions of the A/D converter

**and the use of PWM (= inverse output from P2) at D/A-Con

**-----------------------------------------------------------------

 

*/

#include "mydefs.h"

 

 

// with further includes!

#include "stdlib.h"

 

 

// for abs()

void wait(u16 wastetime)

// local LCD port delay

{

 

 

 

while(wastetime--

);

 

 

}

 

 

 

/*

 

 

 

LCD-Port / Bits on TinyEvalBoard

 

RS = P75, R/W

= P74,

EN

= P20, DATA = P5

*/

 

 

 

//some defines for easy access #define CLEAR_LCD_RS (PDR7 &= ~0x20)

#define SET_LCD_RS

 

(PDR7 = 0x20)

#define CLEAR_LCD_RW

(PDR7 &= ~0x10)

#define SET_LCD_RW

 

(PDR7 = 0x10)

#define CLEAR_LCD_EN

(PDR2 &= ~0x01)

#define SET_LCD_EN

 

(PDR2 = 0x01)

#define LCD_DATA_PORT (PDR5)

 

#define LCD_DATA_CTRL (PCR5)

 

#define LCD_OUT

0xff

 

#define LCD_IN 0x00

 

 

#define LCD_WAIT

 

{wait(100);}

void LCDWriteCmd(u8 cmd)

// write cmd to LCD port

{

 

 

CLEAR_LCD_RS;

 

 

CLEAR_LCD_RW;

 

 

SET_LCD_EN;

 

 

LCD_DATA_PORT = cmd;

 

LCD_WAIT;

 

 

CLEAR_LCD_EN;

 

 

LCD_WAIT;

 

 

}

 

 

void LCDWriteData(u8 data)

// write data to LCD port

{

 

 

SET_LCD_RS;

 

 

CLEAR_LCD_RW;

 

 

SET_LCD_EN;

 

 

LCD_DATA_PORT = data;

 

LCD_WAIT;

 

 

CLEAR_LCD_EN;

 

 

LCD_WAIT;

 

 

}

 

 

u8 LCDReadStatus(void)

 

// get the LCD status register

{

 

 

u8 status;

 

 

CLEAR_LCD_RS;

 

 

SET_LCD_RW;

 

 

Issue 0.2

Page 41

07/2002

Image 41
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