Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
INTRODUCTION
Avoltmeterfindsitsimportancewherevervoltageistobemeasured.
Avoltmeterisaninstrumentusedformeasuringtheelectricalpotentialdifference
betweentwopointsinanelectriccircuit.Analogvoltmetersmoveapointeracrossa
scaleinproportiontothevoltageofthecircuit.Generalpurposeanalogvoltmetersmay
haveanaccuracyofafewpercentoffullscale,andareusedwithvoltagesfroma
fractionofavolttoseveralthousandvolts.
Digitalvoltmetersgiveanumericaldisplayofvoltagebyuseofanalogtodigital
converter.Digitalmeterscanbemadewithhighaccuracy,typicallybetterthan1%.
Speciallycalibratedtestinstrumentshavehigheraccuracies,withlaboratoryinstruments
capableofmeasuringtoaccuraciesofafewpartspermillion.Meters
usingamplifierscanmeasuretinyvoltagesofmicrovoltsorless.Digitalvoltmeters
(DVMs)areusuallydesignedaroundaspecialtypeofanalogtodigitalconvertercalled
anintegratingconverter.Voltmeteraccuracyisaffectedbymanyfactors,including
temperatureandsupplyvoltagevariations.Toensurethatadigitalvoltmeter'sreadingis
withinthemanufacturer'sspecifiedtolerances,theyshouldbeperiodicallycalibrated.
Digitalvoltmetersnecessarilyhaveinputamplifiers,and,likevacuumtubevoltmeters,
generallyhaveaconstantinputresistanceof10megaohmsregardlessofset
measurementrange.
ThisprojectaimsatbuildingaDigitalVoltmeterusingan8051microcontroller.Allthe
dataaccessedandprocessedbythemicrocontrolleristhedigitaldata.Andthus,the
usageofananalogtodigitalconverterfindsitsnecessityhere.Astandardanalogto
digitalconverterADC0804isusedinthecurrentproject.Theinputvoltage(whichisthe
analoginput)isrestrictedtobeintherangeof015V.Theprocesseddatainthe8051is
usedtodriveadisplayoutputonaLCDdisplayunit.Thedisplayisintheformofdigits
andisaccuratetoavalueofonedecimal.TheinputvoltageisdesiredtobethatofaDC
voltageforsteadyobservationsofthevoltagevalueontheLCDpanel.Rather,ifanAC
inputvoltageisgivenattheinputterminals,theoutputvariesindefinitelyasisthe
natureofACvoltage.Thus,theinstantaneousvalueoftheACvoltageisnotsteadily
shownontheLCDpanel.
COMPONENTS
FollowingistheentiresetofthecomponentsusedtobuildtheDigitalVoltmeter:
1. Microcontroller,AT89S52
2. AnalogtoDigitalConverter,ADC0804
3. 16x1LCD
4. Oscillatorcircuitforthemicrocontroller
4.1 12MHzCrystalCapacitor
4.2 33pFCapacitors
5. Voltagedividercircuit/Inputterminals
5.1 200k,100kResistors
5.2 100nFCapacitor
6. ADCClockCircuit
6.1 10kResistor
6.2 150pFCapacitor
7. 100kPotentiometer(toadjustthebacklightoftheLCD)
DescriptionoftheComponentsused
Microcontroller,AT89S52
TheAT89S51isalowpower,highperformanceCMOS8bitmicrocontrollerwith4K
bytesofInSystemProgrammableFlashmemory.Thedeviceismanufacturedusing
Atmelshighdensitynonvolatilememorytechnologyandiscompatiblewiththe
industrystandard80C51instructionsetandpinout.TheonchipFlashallowsthe
programmemorytobereprogrammedinsystemorbyaconventionalnonvolatile
memoryprogrammer.Bycombiningaversatile8bitCPUwithInSystemProgrammable
Flashonamonolithicchip,theAtmelAT89S51isapowerfulmicrocontrollerwhich
providesahighlyflexibleandcosteffectivesolutiontomanyembeddedcontrol
applications.TheAT89S51providesthefollowingstandardfeatures:4KbytesofFlash,
128bytesofRAM,32I/Olines,Watchdogtimer,twodatapointers,two16bit
timer/counters,afivevectortwolevelinterruptarchitecture,afullduplexserialport,
onchiposcillator,andclockcircuitry.
Inaddition,theAT89S51isdesignedwithstaticlogicforoperationdowntozero
frequencyandsupportstwosoftwareselectablepowersavingmodes.TheIdlemode
stopstheCPUwhileallowingtheRAM,timer/counters,serialport,andinterruptsystem
tocontinuefunctioning.ThePowerdownmodesavestheRAMcontentsbutfreezes
theoscillator,disablingallotherchipfunctionsuntilthenextexternalinterruptor
hardwarereset.
PinconfigurationoftheAT89S52isasfollows:
40LeadPDIP
VCCSupplyvoltage.
GNDGround.
Port0Port0isan8bitopendrainbidirectionalI/Oport.Asanoutputport,eachpin
cansinkeightTTLinputs.When1sarewrittentoport0pins,thepinscanbeusedas
highimpedanceinputs.Port0canalsobeconfiguredtobethemultiplexedloworder
address/databusduringaccessestoexternalprogramanddatamemory.Inthismode,
P0hasinternalpullups.Port0alsoreceivesthecodebytesduringFlashprogramming
andoutputsthecodebytesduringprogramverification.Externalpullupsarerequired
duringprogramverification.
Port1Port1isan8bitbidirectionalI/Oportwithinternalpullups.ThePort1output
bufferscansink/sourcefourTTLinputs.When1sarewrittentoPort1pins,theyare
pulledhighbytheinternalpullupsandcanbeusedasinputs.Asinputs,Port1pinsthat
areexternallybeingpulledlowwillsourcecurrent(IIL)becauseoftheinternalpullups.
Port1alsoreceivestheloworderaddressbytesduringFlashprogrammingand
verification.
P1.5MOSI(usedforInSystemProgramming)
P1.6MISO(usedforInSystemProgramming)
P1.7SCK(usedforInSystemProgramming)
Port2Port2isan8bitbidirectionalI/Oportwithinternalpullups.ThePort2output
bufferscansink/sourcefourTTLinputs.When1sarewrittentoPort2pins,theyare
pulledhighbytheinternalpullupsandcanbeusedasinputs.Asinputs,Port2pinsthat
areexternallybeingpulledlowwillsourcecurrent(IIL)becauseoftheinternalpullups.
Port2emitsthehighorderaddressbyteduringfetchesfromexternalprogrammemory
andduringaccessestoexternaldatamemorythatuse16bitaddresses(MOVX@DPTR).
Inthisapplication,Port2usesstronginternalpullupswhenemitting1s.Duringaccesses
toexternaldatamemorythatuse8bitaddresses(MOVX@RI),Port2emitsthe
contentsoftheP2SpecialFunctionRegister.Port2alsoreceivesthehighorderaddress
bitsandsomecontrolsignalsduringFlashprogrammingandverification.
Port3Port3isan8bitbidirectionalI/Oportwithinternalpullups.ThePort3output
bufferscansink/sourcefourTTLinputs.When1sarewrittentoPort3pins,theyare
pulledhighbytheinternalpullupsandcanbeusedasinputs.Asinputs,Port3pinsthat
areexternallybeingpulledlowwillsourcecurrent(IIL)becauseofthepullups.Port3
receivessomecontrolsignalsforFlashprogrammingandverification.Port3alsoserves
thefunctionsofvariousspecialfeaturesoftheAT89S51,asshowninthefollowingtable.
Alternatefunctionsofport3,
P3.0RXD(serialinputport)
P3.1TXD(serialoutputport)
P3.2INT0(externalinterrupt0)
P3.3INT1(externalinterrupt1)
P3.4T0(timer0externalinput)
P3.5T1(timer1externalinput)
P3.6WR(externaldatamemorywritestrobe)
P3.7RD(externaldatamemoryreadstrobe)
RSTResetinput.Ahighonthispinfortwomachinecycleswhiletheoscillatoris
runningresetsthedevice.ThispindrivesHighfor98oscillatorperiodsafterthe
Watchdogtimesout.TheDISRTObitinSFRAUXR(address8EH)canbeusedtodisable
thisfeature.InthedefaultstateofbitDISRTO,theRESETHIGHoutfeatureisenabled.
ALE/PROGAddressLatchEnable(ALE)isanoutputpulseforlatchingthelowbyteof
theaddressduringaccessestoexternalmemory.Thispinisalsotheprogrampulseinput
(PROG)duringFlashprogramming.Innormaloperation,ALEisemittedataconstant
rateof1/6theoscillatorfrequencyandmaybeusedforexternaltimingorclocking
purposes.Note,however,thatoneALEpulseisskippedduringeachaccesstoexternal
datamemory.Ifdesired,ALEoperationcanbedisabledbysettingbit0ofSFRlocation
8EH.Withthebitset,ALEisactiveonlyduringaMOVXorMOVCinstruction.Otherwise,
thepinisweaklypulledhigh.SettingtheALEdisablebithasnoeffectifthe
microcontrollerisinexternalexecutionmode.
PSENProgramStoreEnable(PSEN)isthereadstrobetoexternalprogrammemory.
WhentheAT89S51isexecutingcodefromexternalprogrammemory,PSENisactivated
twiceeachmachinecycle,exceptthattwoPSENactivationsareskippedduringeach
accesstoexternaldatamemory.
EA/VPPExternalAccessEnable.EAmustbestrappedtoGNDinordertoenablethe
devicetofetchcodefromexternalprogrammemorylocationsstartingat0000Hupto
FFFFH.Note,however,thatiflockbit1isprogrammed,EAwillbeinternallylatchedon
reset.EAshouldbestrappedtoVCCforinternalprogramexecutions.Thispinalso
receivesthe12voltprogrammingenablevoltage(VPP)duringFlashprogramming.
XTAL1Inputtotheinvertingoscillatoramplifierandinputtotheinternalclock
operatingcircuit.
XTAL2Outputfromtheinvertingoscillatoramplifier.
MemoryOrganisation,
ProgramMemory:IftheEApinisconnectedtoGND,allprogramfetchesaredirected
toexternalmemory.OntheAT89S51,ifEAisconnectedtoVCC,programfetchesto
addresses0000HthroughFFFHaredirectedtointernalmemoryandfetchesto
addresses1000HthroughFFFFHaredirectedtoexternalmemory.
DataMemory:TheAT89S51implements128bytesofonchipRAM.The128bytesare
accessibleviadirectandindirectaddressingmodes.Stackoperationsareexamplesof
indirectaddressing,sothe128bytesofdataRAMareavailableasstackspace.
Interrupts:TheAT89S51hasatotaloffiveinterruptvectors:twoexternalinterrupts
(INT0andINT1),twotimerinterrupts(Timers0and1),andtheserialportinterrupt.
Eachoftheseinterruptsourcescanbeindividuallyenabledordisabledbysettingor
clearingabitinSpecialFunctionRegisterIE.IEalsocontainsaglobaldisablebit,EA,
whichdisablesallinterruptsatonce.TheTimer0andTimer1flags,TF0andTF1,areset
atS5P2ofthecycleinwhichthetimersoverflow.Thevaluesarethenpolledbythe
circuitryinthenextcycle.
ADC0804
TheADC080XfamilyareCMOS8Bit,successiveapproximationA/Dconverterswhich
useamodifiedpotentiometricladderandaredesignedtooperatewiththe8080A
controlbusviathreestateoutputs.Theseconvertersappeartotheprocessoras
memorylocationsorI/Oports,andhencenointerfacinglogicisrequired.The
differentialanalogvoltageinputhasgoodcommonmoderejectionandpermits
offsettingtheanalogzeroinputvoltagevalue.Inaddition,thevoltagereferenceinput
canbeadjustedtoalowencodinganysmalleranalogvoltagespantothefull8bitsof
resolution.
ThefunctionaldiagramoftheADC080XseriesofA/Dconvertersoperatesonthe
successiveapproximationprinciple.Analogswitchesareclosedsequentiallyby
successiveapproximationlogicuntiltheanalogdifferentialinputvoltage[VlN(+)VlN()]
matchesavoltagederivedfromatappedresistorstringacrossthereferencevoltage.
Themostsignificantbitistestedfirstandafter8comparisons(64clockcycles),an8bit
binarycode(11111111=fullscale)istransferredtoanoutputlatch.Thenormal
operationproceedsasfollows.OnthehightolowtransitionoftheWRinput,the
internalSARlatchesandtheshiftregisterstagesarereset,andtheINTRoutputwillbe
sethigh.AslongastheCSinputandWRinputremainlow,theA/Dwillremaininareset
state.Conversionwillstartfrom1to8clockperiodsafteratleastoneoftheseinputs
makesalowtohightransition.Aftertherequisitenumberofclockpulsestocomplete
theconversion,theINTRpinwillmakeahightolowtransition.Thiscanbeusedto
interruptaprocessor,orotherwisesignaltheavailabilityofanewconversion.ARD
operation(withCSlow)willcleartheINTRlinehighagain.Thedevicemaybeoperated
inthefreerunningmodeconnectingINTRtotheWRinputwithCS=0.Toensurestart
upunderallpossibleconditions,anexternalWRpulseisrequiredduringthefirstpower
upcycle.Aconversioninprocesscanbeinterruptedbyissuingasecondstartcommand.
DigitalOperation
TheconverterisstartedbyhavingCSandWRsimultaneouslylow.Thissetsthestartflip
flop(F/F)andtheresulting1levelresetsthe8bitshiftregister,resetstheInterrupt
(INTR)F/Fandinputsa1totheDflipflop,DFF1,whichisattheinputendofthe8bit
shiftregister.Internalclocksignalsthentransferthis1totheQoutputofDFF1.The
ANDgate,G1,combinesthis1outputwithaclocksignaltoprovidearesetsignalto
thestartF/F.Ifthesetsignalisnolongerpresent(eitherWRorCSisa1),thestartF/F
isresetandthe8bitshiftregisterthencanhavethe1clockedin,whichstartsthe
conversionprocess.Ifthesetsignalweretostillbepresent,thisresetpulsewouldhave
noeffect(bothoutputsofthestartF/Fwouldbeata1level)andthe8bitshift
registerwouldcontinuetobeheldintheresetmode.Thisallowsforasynchronousor
wideCSandWRsignals.Afterthe1isclockedthroughthe8bitshiftregister(which
completestheSARoperation)itappearsastheinputtoDFF2.Assoonasthis1is
outputfromtheshiftregister,theANDgate,G2,causesthenewdigitalwordtotransfer
totheThreeStateoutputlatches.WhenDFF2issubsequentlyclocked,theQoutput
makesahightolowtransitionwhichcausestheINTRF/Ftoset.Aninvertingbufferthen
suppliestheINTRoutputsignal.Whendataistoberead,thecombinationofbothCS
andRDbeinglowwillcausetheINTRF/Ftoberesetandthethreestateoutputlatches
willbeenabledtoprovidethe8bitdigitaloutputs.
DigitalControlInputs
Thedigitalcontrolinputs(CS,RD,andWR)meetstandardTTLlogicvoltagelevels.These
signalsareessentiallyequivalenttothestandardA/DStartandOutputEnablecontrol
signals,andareactivelowtoallowaneasyinterfacetomicroprocessorcontrolbusses.
Fornonmicroprocessorbasedapplications,theCSinput(pin1)canbegroundedand
thestandardA/DStartfunctionobtainedbyanactivelowpulseattheWRinput(pin3).
TheOutputEnablefunctionisachievedbyanactivelowpulseattheRDinput(pin2).
AnalogOperation
Theanalogcomparisonsareperformedbyacapacitivechargesummingcircuit.Three
capacitors(withpreciseratioedvalues)shareacommonnodewiththeinputtoan
autozeroedcomparator.TheinputcapacitorisswitchedbetweenVlN(+)andVlN(),
whiletworatioedreferencecapacitorsareswitchedbetweentapsonthereference
voltagedividerstring.Thenetchargecorrespondstotheweighteddifferencebetween
theinputandthecurrenttotalvaluesetbythesuccessiveapproximationregister.A
correctionismadetooffsetthecomparisonby1/2LSB.
10
AnalogDifferentialVoltageInputsandCommon
ModeRejection
ThisA/Dgainsconsiderableapplicationsflexibilityfromtheanalogdifferentialvoltage
input.TheVlN()input(pin7)canbeusedtoautomaticallysubtractafixedvoltagevalue
fromtheinputreading(tarecorrection).Thisisalsousefulin4mA20mAcurrentloop
conversion.Inaddition,commonmodenoisecanbereducedbyuseofthedifferential
input.ThetimeintervalbetweensamplingVIN(+)andVlN()is41/2clockperiods.There
ismaximumerrorvoltageduetothisslighttimedifferencebetweentheinputvoltage
samples.
Theallowedrangeofanaloginputvoltageusuallyplacesmoresevererestrictionson
inputcommonmodevoltagelevelsthanthis.Ananaloginputvoltagewithareduced
spanandarelativelylargezerooffsetcanbeeasilyhandledbymakinguseofthe
differentialinput.
AnalogInputCurrent
Theinternalswitchingactioncausesdisplacementcurrentstoflowattheanaloginputs.
Thevoltageontheonchipcapacitancetogroundisswitchedthroughtheanalog
differentialinputvoltage,resultinginproportionalcurrentsenteringtheVIN(+)input
andleavingtheVIN()input.Thesecurrenttransientsoccurattheleadingedgeofthe
internalclocks.Theyrapidlydecayanddonotinherentlycauseerrorsastheonchip
comparatorisstrobedattheendoftheclockperiod.
InputBypassCapacitors
BypasscapacitorsattheinputswillaveragethesechargesandcauseaDCcurrentto
flowthroughtheoutputresistancesoftheanalogsignalsources.Thischargepumping
actionisworseforcontinuousconversionswiththeVIN(+)inputvoltageatfullscale.For
a640kHzclockfrequencywiththeVIN(+)inputat5V,thisDCcurrentisatamaximumof
approximately5uA.Therefore,bypasscapacitorsshouldnotbeusedattheanalog
inputsortheVREF/2pinforhighresistancesources(>1kOhm.)Ifinputbypasscapacitors
arenecessaryfornoisefilteringandhighsourceresistanceisdesirabletominimize
capacitorsize,theeffectsofthevoltagedropacrossthisinputresistance,duetothe
averagevalueoftheinputcurrent,canbecompensatedbyafullscaleadjustmentwhile
thegivensourceresistorandinputbypasscapacitorarebothinplace.Thisispossible
becausetheaveragevalueoftheinputcurrentisapreciselinearfunctionofthe
differentialinputvoltageataconstantconversionrate.
InputSourceResistance
Largevaluesofsourceresistancewhereaninputbypasscapacitorisnotusedwillnot
causeerrorssincetheinputcurrentssettleoutpriortothecomparisontime.Ifalow
passfilterisrequiredinthesystem,usealowvalueseriesresistorforapassiveRC
sectionoraddanopampRCactivelowpassfilter.Forlowsourceresistance
applications,a0.1uFbypasscapacitorattheinputswillminimizeEMIduetotheseries
leadinductanceofalongwire.A100Ohmseriesresistorcanbeusedtoisolatethis
11
capacitor(boththeRandCareplacedoutsidethefeedbackloop)fromtheoutputofan
opamp,ifused.
StrayPickup
Theleadstotheanaloginputs(pins6and7)shouldbekeptasshortaspossibleto
minimizestraysignalpickup(EMI).BothEMIandundesireddigitalclockcouplingto
theseinputscancausesystemerrors.Thesourceresistancefortheseinputsshould,in
general,bekeptbelow5k.Largervaluesofsourceresistancecancauseundesired
signalpickup.Inputbypasscapacitors,placedfromtheanaloginputstoground,will
eliminatethispickupbutcancreateanalogscaleerrorsasthesecapacitorswillaverage
thetransientinputswitchingcurrentsoftheA/D(seeAnalogInputCurrent).Thisscale
errordependsonbothalargesourceresistanceandtheuseofaninputbypass
capacitor.ThiserrorcanbecompensatedbyafullscaleadjustmentoftheA/D(seeFull
ScaleAdjustment)withthesourceresistanceandinputbypasscapacitorinplace,and
thedesiredconversionrate.
ReferenceVoltageSpanAdjust
Formaximumapplicationflexibility,theseA/Dshavebeendesignedtoaccommodatea
5V,2.5Voranadjustedvoltagereference.ThishasbeenachievedinthedesignoftheIC.
NoticethatthereferencevoltagefortheICiseither1/2ofthevoltagewhichisapplied
totheV+supplypin,orisequaltothevoltagewhichisexternallyforcedattheVREF/2
pin.Thisallowsforapseudoratiometricvoltagereferenceusing,fortheV+supply,a5V
referencevoltage.Alternatively,avoltagelessthan2.5VcanbeappliedtotheVREF/2
input.TheinternalgaintotheVREF/2inputis2toallowthisfactorof2reductioninthe
referencevoltage.
12
ZeroError
ThezerooftheA/Ddoesnotrequireadjustment.Iftheminimumanaloginputvoltage
value,VlN(MlN),isnotground,azerooffsetcanbedone.Theconvertercanbemadeto
output00000000digitalcodeforthisminimuminputvoltagebybiasingtheA/DVIN()
inputatthisVlN(MlN)value.ThisutilizesthedifferentialmodeoperationoftheA/D.The
zeroerroroftheA/Dconverterrelatestothelocationofthefirstriserofthetransfer
functionandcanbemeasuredbygroundingtheVIN()inputandapplyingasmall
magnitudepositivevoltagetotheVIN(+)input.Zeroerroristhedifferencebetweenthe
actualDCinputvoltagewhichisnecessarytojustcauseanoutputdigitalcodetransition
from00000000to00000001andtheideal1/2LSBvalue(1/2LSB=9.8mVforVREF/2=
2.500V).
FullScaleAdjust
Thefullscaleadjustmentcanbemadebyapplyingadifferentialinputvoltagewhichis
11/2LSBdownfromthedesiredanalogfullscalevoltagerangeandthenadjustingthe
magnitudeoftheVREF/2input(pin9)foradigitaloutputcodewhichisjustchanging
from11111110to11111111.Whenoffsettingthezeroandusingaspanadjusted
VREF/2voltage,thefullscaleadjustmentismadebyinputtingVMlNtotheVIN()input
oftheA/DandapplyingavoltagetotheVIN(+)input.
ClockingOption
TheclockfortheA/DcanbederivedfromanexternalsourcesuchastheCPUclockoran
externalRCnetworkcanbeaddedtoprovideselfclocking.TheCLKIN(pin4)makesuse
ofaSchmitttrigger.
HeavycapacitiveorDCloadingoftheCLKRpinshouldbeavoidedasthiswilldisturb
normalconverteroperation.Loadslessthan50pF,suchasdrivingupto7A/Dconverter
13
clockinputsfromasingleCLKRpinof1converter,areallowed.Forlargerclockline
loading,aCMOSorlowpowerTTLbufferorPNPinputlogicshouldbeusedtominimize
theloadingontheCLKRpin(donotuseastandardTTLbuffer).
RestartDuringaConversion
IftheA/Disrestarted(CSandWRgolowandreturnhigh)duringaconversion,the
converterisresetandanewconversionisstarted.Theoutputdatalatchisnotupdated
iftheconversioninprogressisnotcompleted.Thedatafromthepreviousconversion
remaininthislatch.
ContinuousConversions
Inthisapplication,theCSinputisgroundedandtheWRinputistiedtotheINTRoutput.
ThisWRandINTRnodeshouldbemomentarilyforcedtologiclowfollowingapowerup
cycletoinsurecircuitoperation.
14
InterfacingtheMicrocontroller
InterfacingtheADC0804with8051
Asshowninthetypicacircuit,ADC0804canbeinterfacedwithanymicrocontroller.A
minimumof11pinsarerequiredtointerfacetheADC0804,eightfordatapinsand3for
controlpins.Asshowninthetypicalcircuitthechipselectpincanbemadelowifyou
arenotusingthemicrocontrollerportforanyotherperipheral(multiplexing).
ThereisauniversalruletofindouthowtouseanIC.Allweneedisthedatasheetofthe
ICweareworkingwithandalookatthetimingdiagramoftheICwhichshowshowto
sendthedata,whichsignaltoassertandatwhattimethesignalshouldbemadehighor
low,etc.
15
TimingDiagrams,
PinDescription
1.CS,ChipSelect:ThisisanactivelowpinandusedtoactivatetheADC0804.
2.RD, Read: This is an input pin and active low. After converting the analog data, the
ADCstorestheresultinaninternalregister.Thispinisusedtogetthedataoutofthe
ADC0804chip.WhenCS=0&hightolowpulseisgiventothispin,thedigitaloutputis
shownonthepinsD0D7.
16
3.WR,Write:Thisisaninputpinandactivelow.ThisisusedtoinstructtheADCtostart
theconversionprocess.IfCS=0andWRmakesalowtohightransition,theADCstarts
theconversionprocess.
4.CLKIN,ClockIN:Thisisaninputpinconnectedtoanexternalclocksource.
5.INTR, Interrupt: This is an active low output pin. This pin goes low when the
conversionisover.
6.Vin+:AnalogInput.
7.Vin:AnalogInput.Connectedtoground.
8.AGND:AnalogGround.
9.Vref/2: This pin is used to set the reference voltage. If this is not connected the
defaultreferencevoltageis5V.Insomeapplicationitisrequiredtoreducethestepsize.
Thiscanbedonebyusingthispin.
10.DGND:DigitalGround.
1118.OutputDataBits(D7D0).
19.CLKR:ClockReset.
20.Vcc:PositiveSupply
TheabovetimingdiagramsarefromADC0804datasheet.Thefirstdiagramshowshow
tostartaconversion.Alsoyoucanseewhichsignalsaretobeassertedandatwhattime
tostartaconversion.Solookingintothetimingdiagramwenotedownthestepsorsay
theorderinwhichsignalsaretobeassertedtostartaconversionofADC.Aswehave
decidedtomakeChipselectpinaslowsoweneednottobotherabouttheCSsignalin
thetimingdiagram.BelowstepsareforstartinganADCconversion.Iamalsoincluding
CSsignaltogiveyouaclearpicture.Whileprogrammingwewillnotusethissignal.
1.
2.
3.
4.
Makechipselect(CS)signallow.
Makewrite(WR)signallow.
Makechipselect(CS)high.
WaitforINTRpintogolow(meansconversionends).
OncetheconversioninADCisdone,thedataisavailableintheoutputlatchoftheADC.
Lookingattheseconddiagram,whichshowsthetimingdiagramofhowtoreadthe
convertedvaluefromtheoutputlatchoftheADC,dataofthenewconversionisonly
availableforreadingafterADC0804madeINTRpinloworsaywhentheconversionis
over.BelowarethestepstoreadoutputfromtheADC0804.
1.
2.
3.
4.
5.
Makechipselect(CS)pinlow.
Makeread(RD)signallow.
ReadthedatafromportwhereADCisconnected.
Makeread(RD)signalhigh.
Makechipselect(CS)high.
17
InterfacingtheLCDwith8051
PinInformationofLCD:
PinNo
Name
Description
Vss
Ground
Vdd
+5V
Vee
ContrastAdjustment2Vto5V
RS
RegisterSelect
RW
1Read,0Write
EnableStrobe
D0
DataLine
D1
DataLine
D2
DataLine
10
D3
DataLine
11
D4
DataLine
12
D5
DataLine
13
D6
DataLine
14
D7
DataLine
LED+
BacklitLED+VVdd(Optional
signal)
LED
BacklitLEDVVss(Optional
signal)
15
16
AlgorithmtosenddatatoLCD:
1.MakeR/Wlow
2.MakeRS=0;ifdatabyteiscommand
RS=1;ifdatabyteisdata(ASCIIvalue)
3.Placedatabyteondataregister
4.PulseE(HIGHtoLOW)
18
5.Repeatthestepstosendanotherdatabyte
LCDInitialization:
ProperworkingofLCDdependonthehowtheLCDisinitialized.Wehavetosendfew
commandbytestoinitializetheLCD.SimplestepstoinitializetheLCD
1. Specify function set: Send38Hfor 8bit, double line and 5x7 dot character
format.
2. DisplayOnOffcontrol:Send0FHfordisplayandblinkcursoron.
3. Entrymodeset:Send06Hforcursorinincrementpositionandshiftisinvisible.
4. Cleardisplay:Send01Htocleardisplayandreturncursortohomeposition.
Writingsoftware:
The LCD module is an intelligent component. We communicate to LCD module by
sending commands from microcontroller. To write data to LCD module separate
sequenceisfollowedfor4bitand8bitmode.
Writingcommandfor8Bitmode:
Write8bitdataonD0D7
GeneratestrobebytakingENfromhightolow
Writingcommandfor4Bitmode:
Write4bitdata(uppernibble)onD4D7
GeneratestrobebytakingENfromhightolow
Write4bitdata(lowernibble)onD4D7
GeneratestrobebytakingENfromhightolow
19
LCDCommands:
Instruction
RS RW D7 D6 D5 D4 D3
D2 D1 D0 Description
NOP
Clear
Display
Cursor
Home
Entrymode
set
Display
Control
0
0
Cursor/
Displayshift 0
Functionset 0
SetCGRAM
Address
SetDDRAM
Address
0
0
0
0
0
0
0
0
0
0
0
0
DL N
0
0
NoOperation
ClearDisplayand
Addresscounter
=0
Addresscounter
=0
I/D S
Setcursor
direction(I/D)
andautodisplay
shift(S)
Turndisplay(D)
andcursor(C)
ON/OFF.Set
cursorblinking(B)
Shift
display/cursor
(S),specify
direction(R/L)
SetInterface
datawidth(DL),
numberof
displaylines(N),
characterfont(F)
SetCGRAM
address(D0D5),
CGRAMdatais
sentafterthis
command
SetDDRAM
address(D0D6),
DDRAMdatais
sentafterthis
command
0
1
R/L x
BusyFlag
andAddress 0
BF
Readbusyflag
(BF)andaddress
counter(D0D6)
WriteData
Writedata(D0
20
D7)into
DDRAM/CGRAM
ReadData
Legendsusedintable:
I/D:1Increment,0Decrement
S:1AutoDisplayshift,0Nodisplayshift
D:1DisplayON,0DisplayOFF
C:1CursorON,0CursorOFF
B:1CursorblinkingON,0CursorblinkingOFF
S:1DisplayShift,0Cursormove
R/L:1Shiftright,0Shiftleft
DL:18bitinterface,04bitinterface
N:12lines,01line
F:15X10dotsfont,05X7dotsfont
BF:BusyFlag
ProgrammingtheLCD,subpartoftheprogram:
#include "lcd.h"
void busy()
{
flag=1;
rs=0;
rw=1;
while(flag!=0)
{
en=0;
en=1;
}
}
Readdata(D0
D7)from
DDRAM/CGRAM
21
void LCD_INI(void)
{
wrt_cmd(0X30);
wrt_cmd(0X0C);
wrt_cmd(0X01); wrt_cmd(0X06);
22
23
EntireProgramusedfortheDigitalVoltmeter
#include <REGX51.H>
#include "lcd.h"
#define adc_port P1
//ADC Port
#define rd P3_7
#define wr P3_6
#define cs P3_5
void conv();
void read();
void main(){
char i;
LCD_INI();
while(1){
//Forever loop
adc_avg = 0;
for(i=0;i<10;i++){
conv();
//Start conversion
read();
//Read ADC
adc_avg += adc;
}
adc_avg = adc_avg/10;
wrt_cmd(0x80);
wrt_string("V(DC): ");
adc = adc_avg * 59;
24
hex2lcd((unsigned char)(adc/1000));
wrt_data('.');
adc = adc%1000;
hex2lcd((unsigned char)(adc/10));
wrt_data('V');
}
}
void conv(){
cs = 0;
//Make CS low
wr = 0;
//Make WR low
wr = 1;
//Make WR high
cs = 1;
//Make CS high
while(intr);
void read(){
cs = 0;
//Make CS low
rd = 0;
//Make RD low
//Make RD high
cs = 1;
//Make CS high
25
#include <REGX51.H>
#define lcd_port P2
#define rs P3_0
#define rw P3_1
#define en P3_2
#define flag P2_7
#endif
26
TheoryoftheVoltageCalculationinthecircuit
AllwewantisinputvoltagetoADCshouldnotincrease5Vandourmaximuminput
voltagetovoltmeteris15Vonly.Sowedesignthevoltagedividercircuitasfollows.
VmaxisMaximuminputvoltagetovoltmeter.
VipisinputvoltagetoADC.
R1andR2areresistanceofvoltagedividercircuit.
Vmax=15V
V=R2*Vmax/(R1+R2)
5/15=R2/R1+R2
3=R1/R2+1
2=R1/R2
R2=R1/2
LetstakeR1as200KandR2willbe100K
Maximumcurrent:Imax=(VmaxVi/pmax)/R1(approx)
Vmax=15V
Vi/pmax=5V
R1=200K
Imax=(155)/200=10/200=0.02mA
27
ObservedOutput
Atableisdrawnwhichcomparestheactualvoltageappliedpriortothevoltagedivider
circuitandthefinalvoltagereadbythedigitalvoltmeter.
Also,acomparisionismadebetweenthevoltagereadbythedigitalvoltmeteranda
separatelyusedmultimeteratthesamelocation.
VoltageApplied(Volts)
VoltageaftertheVoltage
VoltageValueasseenin
DividerCircuit(Volts)
theDVM:
0.7
1.9
1.67
4.9
2.33
6.9
3.00
9.0
10
3.33
10.0
12
4.00
12.0
13
4.33
13.0
14
4.67
14.1
Conclusion
Adigitalvoltmeterhasbeensuccessfullydesignedusingamicrocontroller,which
handledallthecontrollogicandinterfacingwiththeADC0804andadisplay
interfacingwiththeLCD.
Although,theerroroccurringinthesuccessiveapproximationsmadebythe
AnalogtoDigitalConverter(ADC0804)inobtainingthedigitaldatafromthe
voltageappliedhasbeencarriedforwarduntilthevoltagebeingdisplayedonthe
LCDscreen.
28
Thevoltagestobemeasuredlimitstoahighervalueof14VandDCvoltagesare
muchconsiderablyviewed.Indeed,ACvoltagesalsocouldbeviewedbut,the
displayedchangesasfrequentlyasthemagnitudeoftheACvoltageissaidto
changebyitsnature.
Also,thevoltagedropacrossthevoltagedividercircuitvaries,withthe
continuoususageoftheDVM,andthusaresultingerrorinthevoltagevalue
mightbeseenwhenitsdisplayedontheLCDscreen.
Advantages
Thedigitalvoltmeterdesignedusesamicrocontrollerwhichissaidtobehighlyefficient
inhandlingthedatacarrieroperationintermsofbeingfasterandbeingerrorfreeand
accurate.Thus,itcanbeconsideredasareliabledeviceforobservingvoltagesof
magnitudesfrom0to14V.
Ratherthanusingtheobsoleteanaloguewaysoffindingoutthevoltages,thedigital
voltmeterprovidesmuchmorepreciseandaccuratevaluesofvoltagesinagivencircuit
intherangeofthevoltmeter.