beautypg.com

U08adc.c – Motorola USB08 User Manual

Page 117

background image

Source Code Files

Contents

USB08 Evaluation Board

Designer Reference Manual

MOTOROLA

Source Code Files

117

U08ADC.C

//============================================================================

// File: U08ADC.C

// Func: Software ADC for USB08

// Ver.: 1.00

// Auth: (C)2000,2001 by Oliver Thamm, MCT Elektronikladen GbR

// http://hc08web.de/usb08

// Rem.: View/Edit this File with TAB-Size=4

//============================================================================

#include "hc08jb8.h"

#include "u08adc.h"

//----------------------------------------------------------------------------

void initSADC() {

// disable internal Pull-Ups on PTE

POCR &= ~0x80;// disable PTE20P

}

//----------------------------------------------------------------------------

unsigned scaleSADC(unsigned t1, unsigned t2) {

t1 >>= 4;

t2 <<= 4;

_asm("lda 5,sp");

_asm("psha");

_asm("pulh");

_asm("ldx 2,sp");

_asm("lda 6,sp");

_asm("div");

// A = H:A/X

_asm("clrx");

// 0:A = t2/t1

}

//----------------------------------------------------------------------------

int getSADC(char channel) {

unsigned t0, t1, t2;

unsigned char p;

unsigned volatile zz;

// convert channel # 1/2/3 to 0x01/0x02/0x04

if(channel == 3) channel++;