Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 26-10-2010
gaston260 gaston260 is offline
Miembro
 
Registrado: ene 2008
Posts: 169
Poder: 17
gaston260 Va por buen camino
codigo para usar con sensor de temperatura y humedad no funciona ni muestra nada

hola amigos tengo un codigo para usar con un sensor de temperatura y humedad por el puerto serie pero no puedo ver los datos , y la verdad que e estado alejado de la programacion por mucho tiempo y del puerto casi nunca lo e usado pero me seria de mucha utilidad poder usarlo , adjunto el circuito tambien !.

El codigo completo :

Código Delphi [-]
unit Finish;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, CPort;

type
  TForm1 = class(TForm)
    LblStatusCom: TLabel;
    ComPort: TComPort;
    Timer1: TTimer;
    BtnSetting: TButton;
    BtnConnect: TButton;
    Label1: TLabel;
    Label2: TLabel;
    LblTemp: TLabel;
    LblHumi: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Timer2: TTimer;
    Label5: TLabel;
    procedure BtnSettingClick(Sender: TObject);
    procedure BtnConnectClick(Sender: TObject);
    procedure IntSerialRX(Sender: TObject; Count: Integer);
//    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure IntTim2(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  DataSerial: Integer;
  DataSerialTemp: Integer;
  FlagRX: Integer;
  DataTrans: Integer;
  DataSHT: Real;
  Temp: Real;
implementation

{$R *.DFM}

procedure TForm1.BtnSettingClick(Sender: TObject);
begin
        ComPort.ShowSetupDialog;
end;

procedure TForm1.BtnConnectClick(Sender: TObject);
begin
        if  ComPort.Connected = true then
           begin
            ComPort.Close;
            LblStatusCom.Caption := ComPort.Port + ' Disconnected';
            BtnConnect.Caption := 'Connect';
            BtnSetting.Enabled := true;
           end
        else
           begin
           ComPort.Open;
           LblStatusCom.Caption := ComPort.Port + '   Connected';
           BtnConnect.Caption := 'Disconnect';
           BtnSetting.Enabled := False;
//           timer1.Enabled:=true;
           Timer2.Enabled := True;
           DataTrans := $01;
           end;

end;

procedure TForm1.IntSerialRX(Sender: TObject; Count: Integer);
begin
        ComPort.Read(DataSerial,1);

        FlagRX := FlagRX + 1;
        if (FlagRX = 1) then
        begin
        DataSerialTemp := DataSerial;
        end;
        if (FlagRX = 2) then
        begin
        DataSerialTemp := DataSerialTemp SHL 8;
        DataSerialTemp := DataSerialTemp OR DataSerial;
        FlagRX := 0;
        DataSHT := DataSerialTemp;

//Konversi Temperature dari SHT11
//  Celcius = (SOt * d2) + d1
//    dengan d2 = 0.01 (14-bit) dan d1 = -40 (VDD = 5Volt)
//  Celcius = (ADC_Temp * 0.01) - 40   -- dikalikan dengan 100
//  Celcius = (ADC_Temp - 4000)
//Catatan: Faktor konversi pada rumus dikalikan dengan 100 untuk
//         memperoleh hasil pengukuran temperature per-100 derajat (0,01)
//         dengan adanya pembulatan

           if (DataTrans = 1) then
           begin
           DataSHT := (DataSHT-4000) / 100;
           LblTemp.Caption := CurrToStr(DataSHT);
           DataTrans := 2;
           end

//Konversi Relative Humidity dari SHT11
//  Relatitive Humidity (linear)
//     RHLin = c1 + (c2 * SORH) + (c3 * SORH^2)
//  Untuk pengukuran 12-bit: c1 = -4; c2 = 0,0405 dan c3 = -2,8*10^-6
//     RHLin = (ADC_RH * 0,0405) - (ADC_RH^2 * 0,0000028) - 4

           else if (DataTrans = 2) then
           begin
           Temp := DataSHT;
           DataSHT := (Temp * 0.0405) - (Temp * Temp * 0.0000028) - 4;
           LblHumi.Caption := CurrToStr(DataSHT);
           DataTrans := 1;
           end

           else DataTrans := 1;
        Timer2.Enabled := True;
        end;
end;

{procedure TForm1.Timer1Timer(Sender: TObject);
begin
       timer1.Enabled := False;
end;}

procedure TForm1.FormCreate(Sender: TObject);
begin
        Label3.Caption := '%RH';
        Label4.Caption := '*C';
end;

procedure TForm1.IntTim2(Sender: TObject);
begin
        if ComPort.Connected = True then
        begin
          ComPort.Write(DataTrans,1);
          FlagRX := 0;
        end;
        Timer2.Enabled := False;
end;
end.

saludos y gracias por su ayuda !.
Archivos Adjuntos
Tipo de Archivo: zip esquema_SHT.zip (31,4 KB, 8 visitas)

Última edición por gaston260 fecha: 26-10-2010 a las 03:54:41. Razón: Los moderadores nuevos quieren que ponga titulo descriptivo mejor que el anterior , pero sigo pensando que necesito ayuda con el codigo .
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Ayuda con codigo ondraw serebi Varios 2 15-04-2010 00:18:33
Ayuda en un código kbaby Varios 75 18-06-2008 14:08:17
Ayuda con código. wofox Varios 6 11-12-2007 00:16:21
Ayuda con un codigo JoNieve C++ Builder 0 21-04-2007 12:27:33
Codigo de Barras.... Ayuda!!!!! adolfoz Varios 14 15-11-2006 17:13:55


La franja horaria es GMT +2. Ahora son las 06:45:55.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi