Max. and Min. Thermometer

 

Photograph of the prototype hardware:

 

 

Note: the LM35 temperature sensor is at the end of the flexible lead shown at the bottom of the picture.

 

Circuit diagram:

 

 

Controlling program:

 

(*$d 2313 - processor is AT90S2313*)

(*$c 4    - 4MHz clock crystal *)

PROGRAM Thermometer;

(* Simple thermometer program to check operation of LCD and ADC0831A modules *)

USES

  LCDdisp2, Convert, ADC0831A;  (* declare these library modules *)

VAR

  max, min, ambient : BYTE;

 

(* declare subroutines from LCDdisp2 module *)

PROCEDURE InitLCD; LIBRARY;

PROCEDURE WriteCh(ch:BYTE); LIBRARY;

PROCEDURE WriteStr(str:STRING); LIBRARY;

PROCEDURE CursorAt(posn:BYTE); LIBRARY;

PROCEDURE ClearLCD; LIBRARY;

 

(* declare subroutines from convert module *)

PROCEDURE Bin2BCD(VAR hundreds,tens,units:BYTE; data:BYTE); LIBRARY;

FUNCTION Bin2String(data:BYTE):STRING; LIBRARY;

 

(* declare subroutines from ADC0831A module *)

PROCEDURE InitADC; LIBRARY;

FUNCTION GetADC:BYTE; LIBRARY;

 

BEGIN

  (* setup LCD *)

  InitLCD;

  InitADC;

  ClearLCD;

 

  (* display constant text *)

  CursorAt(#1);

  WriteStr("Ambient=");      (* msg on top line *)

  CursorAt(#11);

  WriteCh(Chr($b2)); WriteCh('C');    (* °C *)

  CursorAt(#16);

  WriteStr("Max=  "); WriteCh(Chr($b2));

  WriteStr("C Min=");

  CursorAt(#31);

  WriteCh(Chr($b2));

 

  (* set initial temps *)

  ambient := GetADC;

  max := ambient; min := ambient;

 

  (* main loop *)

  REPEAT

    (* display temperatures *)

    CursorAt(#9);

    WriteStr(Bin2String(ambient));

    CursorAt(#20);

    WriteStr(Bin2String(max));

    CursorAt(#29);

    WriteStr(Bin2String(min));

    Wait(500);

    (* sample temperature again *)

    ambient := GetADC;

    (* update max/min temps if necessary *)

    IF ambient > max THEN

      max := ambient

    ELSE IF ambient < min THEN

      min := ambient;

  FOREVER;

END.

 

Back