TheByteWorks

    Quality ready made and affordable custom software

Home
What's new here

Software

PHP Serial
rsterm
Easy Control
Rack Designer
EzCom2Web

Quick Texts
Wallpaper Slideshow

Articles

All articles
WS2300 weather station PHP project
Your own terminal in 17 lines
PC PIC Voltmeter
Network messenger in 22 lines
Phone Dialer

Download
Purchase

Support

Details
E-mail

Copyright 2001-2016
© Cosmin Buhu

  PC PIC Voltmeter
Screenshot

PIC PC Voltmeter

A complete voltmeter that uses a Microchip microcontroller to aquire voltage and send it through one PC serial port.

Step 1
Design rack in Rack Designer, or you may download example archive which contains the
voltmeter rack (see screenshot on the left side of this article).
Controls' names in this rack are :
Analog meter : ameter1
Numeric display : num1
Power button : pbutton1
and two borders, border1 and border2.
Step 2
Code your microcontroller to do these easy jobs:
1) wait to receive on its serial input pin string "go"
2) read voltage value from one of its AD chanel
3) send on its serial output pin value read from AD, as a string, example a 123 value to be serout as "123"
4) send on its serial output pin crlf sequence (ascii 13, ascii 10)
5) jump to 1)
Step 3
Write or open in Easy Control this script code (note: syntax is for Easy Control v1.4):
#open port and rack
myport="com4"
#don't forget to supply path where you have rack
openrack (volt.res)
openport (myport,9600,8,n,1)
again:
#check if power button (pause here) is pressed, and stay here until is depressed
repeat
until (pbutton1==0)
#send query to microcontroller
send (myport,"go1")
#wait to receive data, ended with crlf
repeat
rec=receive (myport)
posofcrlf=pos (chr(13)&chr(10),rec)
until (posofcrlf<>0)
#cut crlf from the string received
lun=len(rec)-2
result=mid(rec,1,lun)
#calculate real value of voltage, assumes that max voltage is 5 volts
volt=(result*5000)/255
#check if is a integer or has decimal point
posofp=pos (".",volt)
#and set analog meter and numeric display
if (posofp<>0)
#has decimal point, cut string
num1=mid (volt,1,posofp-1)
ameter1=mid (volt,1,posofp-1)
else
#has not, leave it as is
num1=volt
ameter1=volt
endif
#flush port
flush (myport)
#and again, and again, until you stop script
goto again

Less than 25 lines of code, and a few clicks in Rack Designer !
That's all !

On a AMD K6-II/300 Mhz and with a 4 Mhz PIC 16C711 it reads more than 10 times per second.
Further improvements: implementing software filtering, detecting in script on which port device is,
timeouts, file logging,autoscalling etc....

Download this project :
Voltmeter

Enjoy !