Physical hit counter V2
![]()
This is a Physical Hit Counter V2. In this version I use MAX7219 and 7-segment common cathode LED display x 8 instead using mechanical counter like the first version. MAX7219 is a 8-Digit LED Display Drivers and serially interfaced.I use MAX7219 because I got two samples from MAXIM.To interface MAX7219 with PC serial port without MCU, we must convert RS232 voltage level to TTL level.
The circuit show in the figure below.
You can use other RS232 line driver IC(e.g. MAX232) instead using the circuit above. From the circuit above.The RS232 pin TX,DTR and RTS use to control DIN,CS and CLK pin of MAX7219.This circuit requires at least 300mA,9-12V DC or AC external power supply.The regulator(IC1) needs an appropriate heat sink.
Again,I have write the host software with Delphi 6 with Comport3 and Indy 10 components installed on my PC.The host software will read text file(hits.txt) from my web hosting every 10 seconds then send serially the number of hits to MAX7219 via RS232.
Here is the main code that I use to send serial data from RS232 to MAX7219.
procedure TForm1.WriteData(DIN:WORD);
var i:integer;
begin
CLK_Lo;
LOAD_Lo;
for i:=1 to 16 do
begin
ComPort1.SetBreak((DIN and $8000)<>$8000);
CLK_Hi;
CLK_Lo;
DIN := DIN shl 1; // shift left one bit
end;
LOAD_Hi;
end;
![]()
On the your web server,create a text file to keep the hits number(e.g.hits.txt) with set file permission to chmod 755 or 777 then place the PHP script below on any page that you need to count the page hits.
<?php
$hitfile = $_SERVER['DOCUMENT_ROOT']."/counter/hits.txt";
$hits = @file_get_contents($hitfile);
file_put_contents($hitfile,$hits+1,LOCK_EX);
echo ($hits+1);
?>
From the PHP script above,add a comment on line 5 if you do not want to show the hits number on your page.
![]()
The host software tested on Windows XP SP3 only and should work on all the Windows(not test).
See more interfacing MAX7219 examples in these books:
PICAXE Microcontroller Projects for the Evil Genius page 155.
Programming and Customizing the Basic Stamp page 134, data-logging thermometer example.
Programming The Basic Atom Microcontroller page 251.
