??? 03/18/07 16:57 Read: times |
#135204 - start by making your A/D convertor work Responding to: ???'s previous message |
You will likely need to measure some resistance and/or voltage for this so make the A/D convertor work and display the readings from a simple potentiometer as a starting point.
Pseudo code for access A/D devices is normally as follows: (How to apply to your specific controller/device is up to you) * activate A/D convertor * setup the channel you want to measure (normally A/D convertors on mcu are multichannel) * setup mode of conversion * start conversion * ... wait for conversion to finish (as a beginner use POLLING and NO interrupt - esp. for a test case like the one I propose) * put the value together For a T89C51CC02 that looks like follows in C (SDCC used): /* initialize A/D hardware */ void ADC_init() { ADCF=1; /* set P1.0 as analog input */ ADCON &= 0xF8; /* clear A/D channel select */ ADCON |= MSK_ADCON_ADEN; /* enable ADC */ } /* execute A/D conversion IN: channel 0-7 the A/D channel we want to measure OUT: conversion result - 16bit value */ int ADC(unsigned char channel) { int result=0; ADCON |= channel; /* set channel to measure */ ADCON |= MSK_ADCON_ADSST; /* start A/D input */ /* wait until conversion has finished - inline assembler is faster */ _asm adcloop: mov A,_ADCON jb ACC.3,adcloop _endasm; ADCON &= 0xef; /* read A/D value */ result=((ADDH<<2)+ADDL); return(result); } And your task is to transfer and adapt this new knowledge to your project and specific circuit! This WILL NOT work for whatever you have at hand, it is only to show principles and ideas. HTH, Matthias |