|

The very first option shows the list
of the loads that could be controlled using this software
along with their codes.

The outstanding part of this software
is activating of required PROFILES at once so that the burden
of controlling of individual devices is eliminated.

The activation of night profile is as shown
below. We can even set the user defined profiles.

As a basic requirement the control
over individual devices is also provided. If the user by
mistake tries to switch ON the device which is already ON, the
software detects it & the corresponding message is displayed.

The software also allows the user to
know the current status of the loads.

SOURCE
CODE:
/* PROGRAM TO CONTROL
MULTIPLE DEVICES USING PC'S PARALLEL PORT */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
FILE *status;
int ch;
char *dev_list[]={"idle","TUBELIGHT","FAN","NIGHTLAMP","TELEVISION",
"AIRCOOLER","REFRIGERATOR","DVD_PLAYER","end"
};
int
day[]={0,2,4,6,0,1,3,5,7,0};
int
night[]={0,1,2,3,5,6,7,0,4,0};
int
out[]={0,3,0,1,2,4,5,6,7,0};
int
reset[]={0,0,1,2,3,4,5,6,7,0};
int device[256];
int port=0x378;
void activate(int *ptr);
void switch_load(int);
main()
{
int disp_menu();
void disp_load();
void profiles();
void switching();
void load_status();
void exit_code();
int welcome();
int choice;
int hour;
status_file();
for(;;)
{
clrscr();
hour=welcome();
choice=disp_menu();
switch(choice)
{
case
1: disp_load();
printf("\n\n\n Press any
key to continue....");
getch();
break;
case
2: profiles();
break;
case
3: switching();
break;
case
4: load_status();
break;
case
5: exit_code(hour);
default: printf("\n\n INVALID CHOICE");
printf("\n\n\n\n\n
PRESS ANY KEY TO RETURN TO MAIN MENU.....");
getch();
}
}
}
status_file()
{
int i=0;
status=fopen("status.txt","r");
if(status==NULL)
{
puts("Unable to open device status file");
exit(1);
}
while(1)
{
ch=fgetc(status);
if(i>=256)
break;
else
device[i]=ch;
i++;
}
fclose(status);
return(0);
}
welcome()
{
struct time t;
struct date d;
clrscr();
printf("\n\n\t\t\t
$$$ POWER CONTROL USING PC $$$\n\n\n");
gettime(&t);
getdate(&d);
printf("\n\n
TIME: %2d:%2d",t.ti_hour,t.ti_min);
printf("\n\n
DATE: %2d/0%d/%2d",d.da_day,d.da_mon,d.da_year);
if(t.ti_hour>=0x5&&t.ti_hour<0xb)
printf("\n\n
GOOD MORNING....\n");
if(t.ti_hour>=0xb&&t.ti_hour<0x11)
printf("\n\n
GOOD AFTERNOON....");
if(t.ti_hour>=0x11&&t.ti_hour<0x16)
printf("\n\n
GOOD EVENING....");
return(t.ti_hour);
}
int disp_menu()
{
int choice;
printf("\n
1.LIST OF LOADS & THEIR CODES");
printf("\n
2.STANDARD PROFILES(DAY/NIGHT)");
printf("\n
3.SWITCHING");
printf("\n
4.LOAD'S STATUS");
printf("\n
5.EXIT\n");
printf("\t\t\t\t
ENTER YOUR CHOICE:");
scanf("%d",&choice);
return(choice);
}
void disp_load()
{
int i;
clrscr();
printf("\n THE LIST
OF LOADS WHICH CAN BE CONTROLLED ARE:\n\n");
for(i=1;strcmpi(&dev_list[i][0],"end");i++)
printf("\n\t
%2d.%s",i,dev_list[i]);
return;
}
void profiles()
{
char p;
for(;;)
{
clrscr();
printf("\n
STANDARD PROFILES:\n");
printf("\n\n\t\t
1.DAY MODE");
printf("\n\t\t
2.NIGHT MODE");
printf("\n\t\t
3.OUT OF STATION");
printf("\n\t\t
4.RESET");
printf("\n\t\t
5.EXIT");
printf("\n\n\n\n
ENTER YOUR CHOICE: ");
p=getchar();
switch(p)
{
case 'd':
case 'D':
case '1': activate(day);
return;
case 'n':
case 'N':
case '2': activate(night);
return;
case 'o':
case 'O':
case '3': activate(out);
return;
case 'r':
case 'R':
case '4': activate(reset);
return;
case 'e':
case 'E':
case '5': return;
}
}
}
void activate(int *ptr)
{
int i;
char c;
printf("\n\nTHE
FOLLOWING DEVICES WILL BE SWITCHED ON.....\n");
for(i=1;ptr[i]!=0;i++)
printf("\n%d.%s",ptr[i],dev_list[ptr[i]]);
printf("\n\nTHE
FOLLOWING DEVICES WILL BE SWITCHED OFF.....\n");
for(i++;ptr[i]!=0;i++)
printf("\n%d.%s",ptr[i],dev_list[ptr[i]]);
printf("\n\n DO
YOU WANT TO ACTIVATE THIS PROFILE....(y/n):");
c=getch();
printf("%c",c);
getch();
if(c=='y'||c=='Y')
{
for(i=1;ptr[i]!=0;i++)
if(device[ptr[i]]==0)
switch_load(ptr[i]);
for(i++;ptr[i]!=0;i++)
if(device[ptr[i]]==1)
switch_load(ptr[i]);
}
}
void switching()
{
int i,on_off;
disp_load();
printf("\n\n\n\nEnter
the code of the device to be switched:");
scanf("%d",&i);
printf("OPTIONS:");
printf("\t
0--OFF\t 1--ON\n");
printf("\n ENTER
YOUR CHOICE:");
reenter: scanf("%d",&on_off) ;
if(on_off==1)
{
if(device[i]==1)
{
printf("\nThe Device is already ON");
getch();
}
else
switch_load(i);
}
else if(on_off==0)
{
if(device[i]==0)
{
printf("\nThe Device is
already OFF...");
getch();
}
else
switch_load(i);
}
else
{
printf("Invalid option\n Please Re-enter");
goto
reenter;
}
}
void load_status()
{
int i;
clrscr();
printf("\n\n THE
FOLLOWING DEVICES ARE ON:\n");
for(i=1;strcmpi(&dev_list[i][0],"end");i++)
if(device[i]==1)
printf("\n%d.%s",i,dev_list[i]);
printf("\n\nTHE
FOLLOWING DEVICES ARE OFF:\n");
for(i=1;strcmpi(&dev_list[i][0],"end");i++)
if(device[i]==0)
printf("\n%d.%s",i,dev_list[i]);
printf("\n\n\n\nPress
any key to continue......");
getch();
}
void switch_load(int adrr)
{
if(device[adrr]==0)
{
device[adrr]=1;
outportb(port,adrr);
delay(50);
outportb(port,0x00);
}
else
{
evice[adrr]=0;
outportb(port,adrr);
delay(50);
outportb(port,0x00);
}
}
void exit_code(int hour)
{
clrscr();
printf("\t\t\t
THANK YOU FOR USING THIS SOFTWARE \n");
if(hour>=0x13||hour<=0x4)
printf("\n\n
GOOD NIGHT....\n");
file_update();
printf("\n\n\n\n\n\n\n
Press any key to EXIT......");
getch();
exit(0);
}
file_update()
{
int i=0;
status=fopen("status.txt","w+");
if(status==NULL)
{
puts("Unable to open device status file");
exit(1);
}
while(1)
{
ch=device[i];
if(i>=256)
break;
else
fputc(ch,status);
i++;
}
fclose(status);
return 0;
}
Click here to download the source code.
CONCLUSION:
This project, can be effectively and conveniently utilized for
the control of different appliances. As this project could be
extended to control about 255 devices, this could be used for
computerization of an office, home, or a firm. Though it is
quiet costlier, the circuit is simple and the working
mechanism could be easily understood. An added advantage of
this project is that we are able to know the status of the
device to be controlled. The program to control the appliances
is written in C language which is more user friendly and easy
to understand than other programming languages.
Disadvantages / Improvements:-
-
If at all a
new device has to be added to the hardware the software
doesn’t support this to achieve which the source code has to
be changed manually.
-
The status
of all the devices that are switched are maintained in a
database which may not coincide with actual status of the
devices as we are not reading the status directly from the
HARDWARE.
By
1. Anand Kumar. N. Ilkal
2. Anil Kumar Desai
3. Gara Naveen
4. Umesh. N. Sajjan
|
Previous page | |