Thermometer Program
- Posted by Andy Briggs <briggsan at HOTMAIL.COM> Jan 05, 2000
- 658 views
This program appears to be an excellent example of using the parallel port. I get an error, however, when I run it. Besides the fact that I don't have the custom thermometer interface, I don't have the files that the program includes at the beginning; include udelay.e -- Sligth modification of delay.e. Same but the include ports.e -- parameter is in milliseconds include bitwise.e -- I miss a fast bitwise SHR SHL here... include keypress.e -- Missing in get.e. Keypress() return true if include graphics.e -- a key has been pressed, but doesn't get the include font.e -- character. (This one is mine!) include file.e I do not own a copy of the registered Euphoria. Do these include files come withe the full version. If not, does anyone know where I can get copies of them. Here is the whole program: -- Termometer based upon a Dallas DS1620 chip via parallel port on the PC -- From an article appeared at Electronique Practique -- By Jesus Consuegra (jconsuegra at redestb.es) -- Acknowledgments to Robert Craig for such a nice environment, -- to Jiri Babor for the font procedures, -- to Jacques Deschemes for his help in delay. include udelay.e -- Sligth modification of delay.e. Same but the include ports.e -- parameter is in milliseconds include bitwise.e -- I miss a fast bitwise SHR SHL here... include keypress.e -- Missing in get.e. Keypress() return true if include graphics.e -- a key has been pressed, but doesn't get the include font.e -- character. (This one is mine!) include file.e -- Globals -- byte PortCommand constant PowerOn = #01, -- We power the termometer on by raising D0 PowerOff = #FE, ClockOn = #20, ClockOff = #DF, ResetOn = #BF, ResetOff = #40, OutHigh = #80, OutLow = #7F, OutPort = #378, -- Change this if you are using LPT2 or 3 InPort = OutPort + 1 -- --------------------------------------- procedure InitPort() Output(PowerOn, OutPort) uDelay(1000) end procedure -- --------------------------------------- procedure ClosePort() Output(PowerOff, OutPort) uDelay(1000) end procedure -- --------------------------------------- procedure SendControl(byte ControlData) byte Control Control = ControlData for i=0 to 7 do PortCommand = AND(PortCommand, ClockOff) Output(PortCommand, OutPort) if (remainder(Control,2)=0) then PortCommand = AND(PortCommand, OutLow) else PortCommand = OR(PortCommand, OutHigh) end if Output(PortCommand, OutPort) Control = floor (Control / 2) uDelay(5) PortCommand = OR(PortCommand, ClockOn) Output(PortCommand, OutPort) uDelay(5) end for end procedure -- -------------------------------------- procedure Reset() PortCommand = AND(PortCommand, ResetOn) Output(PortCommand, OutPort) uDelay(5) PortCommand = OR(PortCommand, ResetOff) Output(PortCommand, OutPort) uDelay(5) end procedure -- -------------------------------------- function ReadChip() integer DataIn byte temp PortCommand = 0 Reset() SendControl(#0C) SendControl(#03) Reset() SendControl(#EE) SendControl(#00) Reset() SendControl(#AA) PortCommand = OR(PortCommand, OutHigh) Output(PortCommand, OutPort) DataIn = 0 for i=0 to 8 do PortCommand = AND(PortCommand, ClockOff) Output(PortCommand, OutPort) uDelay(5) temp = Input(InPort) DataIn = DataIn + (AND(floor(temp/64), #01) * power(2,i)) PortCommand = OR(PortCommand, ClockOn) Output(PortCommand, OutPort) uDelay(5) end for return DataIn end function -- -------------------------------------- -- -- Main body -- -- -------------------------------------- integer Temp1 atom TempE sequence f integer Xt,Yt,X0,Y0, Xr, Yr InitPort() if graphics_mode(18) then end if X0 = 0 Y0 = 0 Xt = 276 Yt = 46 set_rand(12345) fy = 10 fsc = 0 ftc = 14 f ={} f = f&fload("Modern28.f") fx = 10 while (not keypressed()) do Temp1 = ReadChip() if (Temp1 >= 256) then Temp1 = Temp1 - 512 end if TempE = Temp1/2 -- printf(1, "La temperatura es %f grados\n", TempE) Xr = rand(639-Xt) Yr = rand(479-Yt) fx = Xr + 10 fy = Yr + 10 fprint(sprintf("La temperatura es: %-5.1f", TempE)) fp[1] = 0 fp[6] = 0 fx=10 fy=10 ftc=14 uDelay(1000) end while ClosePort() if graphics_mode(-1) then end if -- Freeports()