Основное и вспомогательное освещение дома. Мнемосхема. Листинг программы визуализации

Страницы работы

Фрагмент текста работы

Санкт-Петербургский государственный университет

 информационных технологий, механики и оптики

Отчет по домашнему заданию

«Микропроцессорные системы»

«Освещение дома»

Вариант №4

Выполнили студенты группы 4103

А.

Проверил:

доцент

Санкт-Петербург

2008


Задание :

С помощью LOGO! Должно автоматически включаться внешнее освещение дома. При этом различается два вида освещения: основное и вспомогательное. Основное освещение подсвечивает весь дом, а дополнительное – локальные участки.

Основное освещение дома (Q1) должно включаться с понедельника по воскресенье с 6:00 до 24:00 при срабатывании сумеречного реле (A1). Дополнительное освещение (Q2) должно включаться с 6:00 до 8:00 на 90 секунд при срабатывании датчика движения(L2) и сумеречного реле (A1). Кроме того основное и вспомогательное освещение может включаться в ручном режиме (L4).

·  L1 сумеречное реле (аналоговый датчик А1)

·  L2 сигнализатор перемещений

·  L4 ручное включение освещения

·  Q1 основное освещение

·  Q2 вспомогательное освещение

Мнемосхема


Программа на LOGO

Листинг программы визуализации

unit Unit1;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, jpeg, ExtCtrls, StdCtrls, ComCtrls;

type

  TForm1 = class(TForm)

    Image1: TImage;

    TrackBar1: TTrackBar;

    Edit1: TEdit;

    Edit2: TEdit;

    Button1: TButton;

    Button2: TButton;

    Image2: TImage;

    Label1: TLabel;

    CheckBox1: TCheckBox;

    Image3: TImage;

    Edit3: TEdit;

    Edit4: TEdit;

    Edit5: TEdit;

    Label2: TLabel;

    DateTimePicker1: TDateTimePicker;

    Button3: TButton;

    Label3: TLabel;

    Label4: TLabel;

    Edit6: TEdit;

    Edit7: TEdit;

    Edit8: TEdit;

    Edit9: TEdit;

    Edit10: TEdit;

    Edit11: TEdit;

    Timer1: TTimer;

    Image4: TImage;

    Button4: TButton;

    Button5: TButton;

    Image5: TImage;

    Image6: TImage;

    Image7: TImage;

    procedure Image2Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure TrackBar1Change(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure CheckBox1Click(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure Timer1Timer(Sender: TObject);

    procedure Button4Click(Sender: TObject);

    procedure Button5Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form1: TForm1;

  i,i1,i2,i3,j,j1,j2,j3,g,g1,g2:integer;

implementation

{$R *.dfm}

procedure TForm1.Image2Click(Sender: TObject);

var

 Hour, Min, Sec, Msec: Word;

begin

Image1.visible:=True;

Image2.visible:=false;

edit1.Visible:=true;

edit2.Visible:=true;

Edit3.Visible:=true;

Edit4.Visible:=true;

Edit5.Visible:=true;

Edit6.Visible:=true;

Edit7.Visible:=true;

Edit8.Visible:=true;

Edit9.Visible:=true;

Edit10.Visible:=true;

Edit11.Visible:=true;

Button5.Visible:=true;

Button4.Visible:=true;

Button3.Visible:=true;

button2.Visible:=true;

button1.Visible:=true;

Label1.Visible:=true;

label2.Visible:=true;

label3.Visible:=true;

label4.Visible:=true;

CheckBox1.Visible:=true;

TRackBar1.Visible:=true;

DateTimePicker1.Visible:=true;

image3.Visible:=true;

  repeat

    DecodeTime(Time, Hour, Min, Sec, MSec);

    Edit3.Text := IntToStr(Hour);

    Edit4.Text := IntToStr(Min);

    Edit5.Text := IntToStr(Sec);

    g:=StrToInt(Edit3.text);

    g1:=StrToInt(Edit4.text);

    g2:=StrToInt(Edit5.text);

      if i=g then

       begin

         if i1=g1 then

         begin

         image5.Visible:=true;

         image3.Visible:=false;

         image6.Visible:=false;

         image7.Visible:=false;

         end;

       end;

      if i2=g then

       begin

         if i3=g1 then

         begin

         image5.Visible:=false;

         image3.Visible:=true;

         image6.Visible:=false;

         image7.Visible:=false;

         end;

       end;

      if j=g then

       begin

         if j1=g1 then

         begin

         image6.Visible:=true;

         image5.Visible:=false;

         image3.Visible:=false;

         image7.Visible:=false;

         end;

       end;

      if j2=g then

       begin

         if j3=g1 then

         begin

         image6.Visible:=false;

         image5.Visible:=false;

         image3.Visible:=true;

         image7.Visible:=false;

         end;

       end;

    Application.ProcessMessages;

  until Form1.Tag = 1;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

image7.Stretch:=false;

if CheckBox1.Checked=True then image7.Visible:=false;

 if CheckBox1.Checked=false then

  begin

     if TrackBar1.Position>=5 then

     begin

     image7.Visible:=true;

         image5.Visible:=false;

         image3.Visible:=false;

         image6.Visible:=false;

     end;

     if TrackBar1.Position<5 then

     begin

     image7.Visible:=false;

     image5.Visible:=false;

         image3.Visible:=true;

         image6.Visible:=false;

     end;

  end;

end;

procedure TForm1.TrackBar1Change(Sender: TObject);

begin

if CheckBox1.Checked=True then image5.Visible:=false;

if CheckBox1.Checked=false then

Begin

 if TrackBar1.Position>=5 then

 begin

 image5.Visible:=true;

         image7.Visible:=false;

         image3.Visible:=false;

         image6.Visible:=false;

 end;

 if TrackBar1.Position<5 then

 begin

 image5.Visible:=false;

         image7.Visible:=false;

         image3.Visible:=true;

         image6.Visible:=false;

 end;

end;

image5.Stretch:=false;

end;

procedure TForm1.Button3Click(Sender: TObject);

begin

  Form1.Tag := 1;

end;

procedure TForm1.CheckBox1Click(Sender: TObject);

begin

if CheckBox1.Checked=True then

begin

image3.Visible:=false;

 image5.Visible:=false;

  image6.Visible:=false;

   image7.Visible:=false;

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

if CheckBox1.Checked=false then

  begin

   image6.Visible:=true;

   image4.Stretch:=true;

   image5.Visible:=false;

         image3.Visible:=false;

         image7.Visible:=false;

  end;

end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin

   if image4.Stretch=true then

   begin

   image6.Visible:=false;

   image3.Visible:=true;

   end;

end;

procedure TForm1.Button4Click(Sender: TObject);

begin

image7.Visible:=false;

end;

procedure TForm1.Button5Click(Sender: TObject);

begin

i:=StrToInt(Edit1.Text);

i1:=StrToInt(Edit6.Text);

i2:=StrToInt(Edit7.Text);

i3:=StrToInt(Edit8.Text);

j:=StrToInt(Edit2.Text);

j1:=StrToInt(Edit9.Text);

j2:=StrToInt(Edit10.Text);

j3:=StrToInt(Edit11.Text);

end;

end.


Скриншот программы:

               


Программа для Keil:

//

// $Id$

//

#include <ADuC812.h>

#define true 1

#define false 0

typedef unsigned char byte;

typedef unsigned short word;

typedef unsigned long dword;

typedef char bool;

/// Доступные переключатели

typedef enum

{

asI1,

asI2,

//         asMax

} AvailableSwitch;

/// Выходные данные

typedef enum

{

aoQ1,

aoQ2,

aqMax

} AvailableOutput;

/// День недели.

typedef enum

{

dwMonday,

dwTuesday,

dwWednesday,

dwThursday,

dwFriday,

dwSaturday,

dwSunday

} DayOfWeek;

/// Аналоговые датчики.

enum AnalogSensor

{

aseA1 = 0,

aseA2 = 1,

aseMax

};

/// Сколько прошло времени в миллисекундах.

dword data ElapsedTime = 10 * 3600L * 1000L + 0 * 60L * 1000L + 0 * 1000L;

static char Hour = 0, Minute = 0, Second = 0;

static DayOfWeek Day = dwMonday;

static char Timer1Hour = 0, Timer1Minute = 0, Timer1Second = 0;

static char Timer2Hour = 0, Timer2Minute = 0, Timer2Second = 0;

static bool Timer1Enable = false, Timer2Enable = false;

static bool AnalogSensorState[aseMax];

static word AnalogSensorValue[aseMax];

static word AnalogSensorUpperValue[aseMax];

static word AnalogSensorLowerValue[aseMax];

sbit inputI1 = P0 ^ 0;

sbit inputI2 = P0 ^ 1;

sbit inputI4 = P0 ^ 3;

sbit outputQ1 = P3 ^ 0;

sbit outputQ2 = P3 ^ 1;

bool lastI3Value = false, lastI4Value = false;

void SetTimer1()

{

Timer1Hour = Hour;

Timer1Minute = Minute;

Timer1Second = Second;

Timer1Enable = true;

}

void SetTimer2()

{

Timer2Hour = Hour;

Timer2Minute = Minute;

Timer2Second = Second;

Timer2Enable = true;

}

bool CheckTimer1Interval( char hourToCheck, char minuteToCheck, char secondToCheck )

{

char hour = Hour + ( Hour < Timer1Hour ? 24 : 0 ) - Timer1Hour;

char minute = Minute - Timer1Minute;

char second = Second - Timer1Second;

if( second < 0 )

{

second += 60;

minute--;

}

if( minute < 0 )

{

minute += 60;

hour--;

}

if( hour < hourToCheck ) return true;

if( hour > hourToCheck ) return false;

if( minute < minuteToCheck ) return true;

if( minute > minuteToCheck ) return false;

if( second < secondToCheck ) return true;

return false;

}

bool CheckTimer2Interval( char hourToCheck, char minuteToCheck, char secondToCheck )

{

char hour = Hour + ( Hour < Timer2Hour ? 24 : 0 ) - Timer2Hour;

char minute = Minute - Timer2Minute;

char second = Second - Timer2Second;

if( second < 0 )

{

second += 60;

minute--;

}

if( minute < 0 )

{

minute += 60;

hour--;

}

if( hour < hourToCheck ) return true;

if( hour > hourToCheck ) return false;

if( minute < minuteToCheck ) return true;

if( minute > minuteToCheck ) return false;

if( second < secondToCheck ) return true;

return false;

}

void InvalidateParameters()

{

// Основное освещение Q1 - с 6.00 до 24.00

outputQ1 = !AnalogSensorState[aseA1] & Hour >= 6;

// Дополнительное освещение Q2 - с 6.00 до 8.00

outputQ2 = !AnalogSensorState[aseA1] & inputI4 & Hour >= 6 && Hour < 8;

if( Timer2Enable )

Timer2Enable = ( outputQ2 |= CheckTimer2Interval( 0, 1, 0 ) );

//Ручное включение основного и вспомогательного освещения Q1 и Q2

outputQ1 &= inputI2;

outputQ2 &= inputI2;

}

void SetTime( DayOfWeek day, char hour, char minute, char second )

{

Day = day;

Hour = hour;

Minute = minute;

Second = second;

InvalidateParameters();

}

void InitAPI()

{

char i;

for( i = 0; i < aseMax; i++ )

{

AnalogSensorValue[i] = 0;

AnalogSensorState[i] = false;

AnalogSensorLowerValue[i] = 0;

AnalogSensorUpperValue[i] = 0;

}

}

void SetAnalogSensorThreshold( enum AnalogSensor sensor, word lowerValue, word upperValue )

{

AnalogSensorLowerValue[sensor] = lowerValue;

AnalogSensorUpperValue[sensor] = upperValue;

InvalidateParameters();

}

char GetAnalogSensorState( enum AnalogSensor sensor )

{

while( ADCCON3 & 0x80 );

ADCCON2 = 0x10 | ( sensor & 0x7 );

while( ADCCON3 & 0x80 );

AnalogSensorValue[sensor] = ( ( word ) ( ADCDATAH & 0xF ) << 8 ) | ADCDATAL;

if( AnalogSensorState[sensor] )

{

if( AnalogSensorValue[sensor] < AnalogSensorLowerValue[sensor] )

AnalogSensorState[sensor] = false;

}

else

{

if( AnalogSensorValue[sensor] > AnalogSensorUpperValue[sensor]

Похожие материалы

Информация о работе