KEY(1) ON: ON KEY(1) GOSUB FINIS
KEY(5) ON: ON KEY(5) GOSUB RETIRE
KEY(10) ON: ON KEY(10) GOSUB ALLON
PORT% = &H378
OUT PORT%, 0
LOCATE 8, 10: PRINT "<--- --->"
V$ = STRING$(27, "²")
LOCATE 5, 6: PRINT V$; SPC(1); "CONTROL PANEL"; SPC(2); V$
LINE (40, 31)-(600, 180), 1, B
LINE (40, 40)-(600, 180), 1, B
LINE (40, 100)-(600, 120), 1, BF
LINE (140, 40)-(460, 110), 1, B
LOCATE 8, 65: PRINT "ON-----Q"
LOCATE 12, 65: PRINT "OFF----W"
LOCATE 19, 15: PRINT "F1"; SPC(24); "F5"; SPC(27); "F10"
LOCATE 21, 10: PRINT "EMERGENCY OFF"; SPC(16); "LOGOUT"; SPC(24); "ALLON"
D$ = DATE$
J$ = MID$(D$, 1, 3)
K$ = MID$(D$, 4, 3)
L$ = MID$(D$, 9, 2) LOCATE 5, 7: PRINT SPC(1); K$; J$; L$; SPC(1); ""
STAT:
PSET (145, 85): DRAW "R20U10L20D10"
PSET (185, 85): DRAW "R20U10L20D10"
PSET (225, 85): DRAW "R20U10L20D10"
PSET (265, 85): DRAW "R20U10L20D10"
PSET (305, 85): DRAW "R20U10L20D10"
PSET (345, 85): DRAW "R20U10L20D10"
PSET (385, 85): DRAW "R20U10L20D10"
PSET (425, 85): DRAW "R20U10L20D10"
T$ = TIME$
Y$ = MID$(T$, 1, 2)
Y = VAL(Y$)
IF Y < 12 THEN PP$ = "AM" ELSE PP$ = "PM"
IF Y > 12 THEN Y = Y - 12
U$ = MID$(T$, 3, 3)
LOCATE 5, 64: PRINT SPC(1); Y; U$; PP$; SPC(1); ""
LOCATE 9, 20: PRINT "1"; SPC(4); "2"; SPC(4); "3"; SPC(4); "4"; SPC(4); "5"; SPC(4); "6"; SPC(4); "7"; SPC(4); "8"
LOCATE 12, 19: PRINT AA; SPC(2); SS; SPC(2); DD; SPC(2); FF; SPC(2); GG; SPC(1); SPC(1); HH;
SPC(2); JJ; SPC(2); KK
X$ = INKEY$
X$ = RIGHT$(X$, 1)
N = INP(PORT%)
IF X$ = "K" THEN J = J - 40
IF X$ = "M" THEN J = J + 40
PSET (J + 105, 85): DRAW
"R20U10L20D10R2U10R2D10R2U10R2D10R2U10R2D10R2U10R2D10R2U10R2D10"
FOR T = 1 TO 400: NEXT
PRESET (J + 105, 85): DRAW
"R20U10L20D10R2U10R2D10R2U10R2D10R2U10R2D10R2U10R2D10R2U10R2D10"
IF J + 105 < 105 THEN J = 0
IF J >= 360 THEN J = 360
IF (J = 40) AND (X$ = "Q" OR X$ = "q") THEN GOSUB APPLE
IF (J = 40) AND (X$ = "W" OR X$ = "w") THEN GOSUB APPLEOF
IF (J = 80) AND (X$ = "Q" OR X$ = "q") THEN GOSUB BAT
IF (J = 80) AND (X$ = "W" OR X$ = "w") THEN GOSUB BATOF
IF (J = 120) AND (X$ = "Q" OR X$ = "q") THEN GOSUB TALE
IF (J = 120) AND (X$ = "W" OR X$ = "w") THEN GOSUB TALEOF
IF (J = 160) AND (X$ = "Q" OR X$ = "q") THEN GOSUB FLAT
IF (J = 160) AND (X$ = "W" OR X$ = "w") THEN GOSUB FLATOF
IF (J = 200) AND (X$ = "Q" OR X$ = "q") THEN GOSUB FAT
IF (J = 200) AND (X$ = "W" OR X$ = "w") THEN GOSUB FATOF
IF (J = 240) AND (X$ = "Q" OR X$ = "q") THEN GOSUB SILK
IF (J = 240) AND (X$ = "W" OR X$ = "w") THEN GOSUB SILKOF
IF (J = 280) AND (X$ = "Q" OR X$ = "q") THEN GOSUB SEVEN
IF (J = 280) AND (X$ = "W" OR X$ = "w") THEN GOSUB SEVENOF
IF (J = 320) AND (X$ = "Q" OR X$ = "q") THEN GOSUB LAST
IF (J = 320) AND (X$ = "W" OR X$ = "w") THEN GOSUB LASTOF
GOTO STAT '------------ALL THE SUBROUTINES ARE BELOW--------------
APPLE: SOUND 500, 2
AA = 1
LOCATE 6, 50
Q = 1 OR N
OUT PORT%, Q
RETURN
BAT: SOUND 500, 2
SS = 1
W = 2 OR N
OUT PORT%, W
RETURN
TALE: SOUND 500, 2
DD = 1
Q = 4 OR N
OUT PORT%, Q
RETURN
FLAT: SOUND 500, 2
FF = 1
Q = 8 OR N
OUT PORT%, Q
RETURN
FAT: SOUND 500, 2
GG = 1
Q = 16 OR N
OUT PORT%, Q
RETURN
SILK: SOUND 500, 2
HH = 1
Q = 32 OR N
OUT PORT%, Q
RETURN
SEVEN: SOUND 500, 2
JJ = 1
Q = 64 OR N
OUT PORT%, Q
RETURN
LAST: SOUND 500, 2
KK = 1
Q = 128 OR N
OUT PORT%, Q
RETURN
TALEOF: SOUND 400, 1
IF DD = 0 THEN RETURN
DD = 0
IF N = 4 THEN P = 0
IF N < 4 THEN P = N
IF N > 4 THEN P = N - 4
OUT PORT%, P RETURN
APPLEOF: SOUND 400, 1
IF AA = 0 THEN RETURN
AA = 0
IF N = 1 THEN I = 0
IF N > 1 THEN I = N - 1
OUT PORT%, I
RETURN BATOF: SOUND 400, 1
IF SS = 0 THEN RETURN
SS = 0
IF N = 2 THEN U = 0
IF N > 2 THEN U = N - 2
IF N < 2 THEN U = N
OUT PORT%, U RETURN
FLATOF: SOUND 400, 1
IF FF = 0 THEN RETURN FF = 0
IF N = 8 THEN E = 0
IF N < 8 THEN E = N
IF N > 8 THEN E = N - 8
OUT PORT%, E
RETURN
FATOF: SOUND 400, 1
IF GG = 0 THEN RETURN
GG = 0
IF N = 16 THEN Y = 0
IF N < 16 THEN Y = N
IF N > 16 THEN Y = N - 16
OUT PORT%, Y
RETURN
SILKOF: SOUND 400, 1
IF HH = 0 THEN RETURN
HH = 0 IF N = 32 THEN Y = 0
IF N < 32 THEN Y = N
IF N > 32 THEN Y = N - 32
OUT PORT%, Y
RETURN
SEVENOF: SOUND 400, 1
IF JJ = 0 THEN RETURN
JJ = 0
IF N = 64 THEN U = 0
IF N < 64 THEN U = N
IF N > 64 THEN U = N - 64
OUT PORT%, U
RETURN
LASTOF: SOUND 400, 1
IF KK = 0 THEN RETURN
KK = 0
IF N = 128 THEN Z = 0
IF N < 128 THEN Z = N
IF N > 128 THEN Z = N - 128
OUT PORT%, Z
RETURN
ALLON: SOUND 500, 4
OUT PORT%, 255
AA = 1: SS = 1: DD = 1: FF = 1: GG = 1: HH = 1: JJ = 1: KK = 1
RETURN
FINIS: SOUND 400, 2
OUT PORT%, 0
AA = 0: SS = 0: DD = 0: FF = 0: GG = 0: HH = 0: JJ = 0: KK = 0
RETURN
RETIRE:
OUT PORT%, 0
END
/*program to control devices using PC parallel port
The devices are controlled by pressing the keys 1-8
that corresponds to each of the 8 possible devices
*/
#include
#include
#include
#define PORT 0x378 /* This is the parallel port address */
main()
{
char val=0,key=0;
char str1[]="ON ";
char str2[]="OFF";
char *str;
clrscr();
printf("Press the approriate number key to turn on/off devices:\n\n");
printf("Here Device1 is connected to D0 of parallel port and so on\n\n");
printf("Press \"x\" to quit\n\n");
gotoxy(1,8);
printf("Device1:OFF Device2:OFF Device3:OFF Device4:OFF\n");
printf("Device5:OFF Device6:OFF Device7:OFF Device8:OFF");
while(key!='x' && key!='X')
{
gotoxy(1,12);
printf("Value in hex sent to the port:");
key=getch();
switch(key){
case '1':
gotoxy(9,8);
val=(val&0x01)?(val&(~0x01)):val|0x01;
str=(val&0x01)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '2':
gotoxy(21,8);
val=(val&0x02)?(val&(~0x02)):val|0x02;
str=(val&0x02)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '3':
gotoxy(33,8);
val=(val&0x04)?(val&(~0x04)):val|0x04;
str=(val&0x04)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '4':
gotoxy(45,8);
val=(val&0x08)?(val&(~0x08)):val|0x08;
str=(val&0x08)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '5':
gotoxy(9,9);
val=(val&0x10)?(val&(~0x10)):val|0x10;
str=(val&0x10)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '6':
gotoxy(21,9);
val=(val&0x20)?(val&(~0x20)):val|0x20;
str=(val&0x20)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '7':
gotoxy(33,9);
val=(val&0x40)?(val&(~0x40)):val|0x40;
str=(val&0x40)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '8':
gotoxy(45,9);
val=(val&0x80)?(val&(~0x80)):val|0x80;
str=(val&0x80)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",(unsigned char)val);
break;
}
}
}
/* 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=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[0],"end");i++)
printf("\n\t %2d.%s",i,dev_list);
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!=0;i++)
printf("\n%d.%s",ptr,dev_list[ptr]);
printf("\n\nTHE FOLLOWING DEVICES WILL BE SWITCHED OFF.....\n");
for(i++;ptr!=0;i++)
printf("\n%d.%s",ptr,dev_list[ptr]);
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!=0;i++)
if(device[ptr]==0)
switch_load(ptr);
for(i++;ptr!=0;i++)
if(device[ptr]==1)
switch_load(ptr);
}
}
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==1)
{
printf("\nThe Device is already ON");
getch();
}
else
switch_load(i);
}
else if(on_off==0)
{
if(device==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[0],"end");i++)
if(device==1)
printf("\n%d.%s",i,dev_list);
printf("\n\nTHE FOLLOWING DEVICES ARE OFF:\n");
for(i=1;strcmpi(&dev_list[0],"end");i++)
if(device==0)
printf("\n%d.%s",i,dev_list);
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;
if(i>=256)
break;
else
fputc(ch,status);
i++;
}
fclose(status);
return 0;
}


