Documente Academic
Documente Profesional
Documente Cultură
PROGRAM IN C++
I MATHEWS BOBY prompted to enter the delay between the functions to draw lines, rectangles,
the consecutiveLEDs to glow in milli- output text, change colour, etc.
FF h i s I i g h t c h a s e rp r o g r a m i s seconds.Next, you have to enter the 7. coordinates( ) and click(h f). This
written in C++ and compiled number of times you need to display function checks whether the mouse
I
t using Turbo C++ compiler.It the lighting pattern. pointer is inside any of the rectangu-
can be used to create lighting anima- Now, press any key to start the Iar buttons being drawn. If the pointer
tion sequencesto attract attention in Iight display.Justpressany key on the is inside, it invokes the click(int) func-
advertising and promotion. In addi- keyboard once to stop the current dis- tion, where the argument represents
tion, it can be used to produce pleas- play. You can exit from the program the rectangle in whicl-r the pointer en-
ing lighting effectsand disco lights. by clicking'exit' button. tered. Now, the click(int) function
The program can be implemented checks for a left button click event. lf
with a simple interfacing circuit using Software there is a click event, the correspond-
eight LEDs connectedacrossthe PC's A total of eight functions have been ing LEDs display sequence comes inti'r
parallel port. The software is easy to defined in the software program ex- action.
'main (
understand and anyone can easily cluding ).' Each function is ex- 8. main( ). The program's main( )
modify it to produce a new display plained below: contains an infinite loop through
sequence. f. initialize( ). This function which the functions menu( ) and coor-
initialises graphics, mouse and also dinates( ) are executed one after the
GUI-basedprogram clears the parallel port. The third ar- other. First, the initialise( ) function is
Graphics function is included in the gument to the'initgraph'function is a invoked followed by the infinite loop.
program to make a GUI (graphical string specifying to the path of the
user interface)menu-driven applica-
'egavga.bgi'
graphic driver file. If the Executionof the program
tion. Mouse function makes it user- file is present in the folder where the We will now see how the execution
friendly. You can use the mouse to execution program is stored, you of the program takes place. First, the
click various options in the menu. needn't specify anything in the pro- code present in the main( ) function
When you run the program, you gram. Mouse is initialised by passing is executed. Before the loop starts,
'51' (=9a33
can see three separatesectionson the a value in hex) to the soft- the initialise( ) function is invoked.
I
I screen/namely, 'styles,' 'settings'and ware interrupt interface function The mouse and the graphics are
I 'instructions.' 'int86.'
initialised and the parallel port is
r
r Under 'styles'section,you can see 2. shozumouse( ). This function cleared. The address for parallel port
a total of nine rectangularbuttons with mousepointer on the output is'0x0378' in hexadecimal system. In-
red borders. Eight of them are num- :i:H formation is sent to the port r.t'ith the
bered '1' to '8' and the last one is 'exit'
'outport(int
3. hiilemouse( ). This function hides command portid, int
button. You can select a display pat- the mouse pointer from the output value)' Thc bir-rary equivalent (as a
'value'
tern style from any given eight options screen. This is done when we have to byte) is sent to the data pins
I
I
After selecting a style, you are the menu of the program. It contains showmouse( ) function.
li
Next, executethe co- statement on the value of variable'2.'
ordinates() funcfion. In- LEOl So you enter into
o 14R14 Displayformats
side the coordinates( ) o- ^vw the loop. Inside the
vl
function, the program
continuously polls the
U o-
o R2
a loop, you can see
'flag1' equated to
The LEDs will glow according to the
J 7 l byte available at the parallel port. The
coordinatesof the mouse 3 .ff. d '0.'Now, read the byte available is the binary equivalent
E o- 7l
pointer, that is, savesthe F o status of the of the value sent to the port using the
position of the mouse Uz o--
^L.^ a mouse through the outport command. Let us seedifferent
Y 18 .ff.
z
pointer on the screenand (J a readmouse() func- display formats available in this pro-
ot
c h e c k s w h e t h e r t h e tr
F -l
tion. The next two gram.
pointer is inside any of I ct ? .16^ a lines of the code In the sourcecode,you can seethat
J 7l
00000001 00000001 00000001 10101010 111'r0000 1 1 1 1 1 1 1 11 0 0 0 0 0 0 1 0000001 1 2005 issue of EFY maga-
00000010 00000011 0 0 0 0 0 0 1 10 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1 00000000 01000010 000001 10 zine.
Construct the hard-
00000100 00000111 000001 11 00100100 00001100
ware according to the fig-
00001000 00001111 00001 111 00011000 00011000
ure given. Connect the 25-
00010000 00011111 0 0 0 1 1 1 1 1 00110000
pin male connector to the
0 0 1 0 0 0 0 00 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 , 01100000
parallel port. The files
0'1000000 01111111 0 1 1 1 1 1 I1 1 11000000 'egavga.bgi'
and'trip.chr'
1 0 0 0 0 0 0 01 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
must be present in the
11111111
folder where the main ex-
01111111
ecutable program is lo-
00t11111
cated. Note that'trip.chr'
00011111 present in the same folder
00001 111 is a font file.
000001 11 EFY notes. 1. The
0000001 1 source code and other rel-
'
00000001 evant files of this project
ecutes the exit(0) statement and you Pins 18 to 25 are grounded. A 25-pin have been included in this month's
can exit the program. male connector must be used to inter- EFY{D.
face the external circuit to the PC. Eight 2. This program cannot be used
Hardware transistors (8C547) can be used to with Windows XP because it cannot
The hardwarccomprisesinterfacingof drive the higher-power LEDs with ex- accessthe port due to security reasons.
the parallelport of the PC with LEDs. ternal power supply. In this circuit, Also if there are some other software
The parallel port consistsof 25 pins, transistors are not used. For connect- installed that uses parallel port like
out of which eight data pins starting ing heavy loads using relays, you may microcontroller programmer, the pro-
from 2 and ending al9 are used here. refer to the project 'Device Control gram may not work satisfactorily.
It: l glow-num--; l
switch(z) )while(glow-num>0);
{ outport(PORT,0);
case 1: if(flagi) gets(ch); vojd coordinates0//CHECKS WHETHER MOUSU'S
do break, POINTER IS INSIDE
{ case5: I //ANY OF THE RECTANCLESDI{AWN,
for(i=1;i<=128;i=i+2)//FOR STYLE1 glow num+=2; //STYLE5 showmouseO; //lF INSIDE INVOKESFUNCTION
do 'click(int)'.
I
f
outport(PORT,i)j I while(1)
if(bioskey(i))//EXITSlF A KEY IS PRESSED if(r==240) {
I r-15; readmouse0;
flag1=1; elseif(r==15) if(((x1>70&&x1<170)&&y1>140)&&y1<160)
break; r=240; I
I outport(PORT,r), click(1);
delav(glow-delay); if(bioskey(1))//EXITSlF A KEY lS PRESSED if(flag)
I I break;//GOESTO MAIN
clow num--j flag1=1; l
lwhile(glow_num>0); break; if(((x1>270&&xl<32))&&yl> l 40)&&y1<160)
if(flag1)gets(ch); ) I
outport(PORT,0); delay(glow-delay); click(2);
break; Blow_num--; if(flarj)
case2: lwhile(glow-num>0); break;//GOESTO MAIN
do outport(PORT,0), I
{ if(fla91 ) gets(ch); if (((x1>470&&x1
<570)&&y1>140)&&y1<160)
i=0;v=l; / /ST\I.E2 break; {
do case 6: click(3);
I glow-num*=2; /ISTYLF.6 if(flag)
i=i+v; do break;/ /GOES TO MAIN
I l
ougort(PORT,i); if(s==255) if(((x1>70&&x1<170)&&y1>196)&&y1<216)
if(bioskey(1))//EXITSIF A KEY IS PRESSED s=0; {
l elseif(s==0) click(4);
fla81=1; s=255; if(flag)
break; outport(PORT,s); break;//GOES TO MAIN
I if(bioskey(1))//EXITSIF A KEY IS PRESSED )
delay(glow_delay); { if(((x1>270&&x1<370)&&y1
>196)&&y1
<216)
)while(i<=255); flagl=1; {
glow_num--; break; click(5);
outport(PORT,0); l if(flag)
Iwhile(glow-num>0); delay(glow delay); break;/ /GOES TO MAIN
outport(PORT,o); glow num--: I
if(fla91)gets(ch); iwhile(glow_num>0); if(((x1>470&&x1<570)&&y1>1e6)&&y1
<216)
break; outport(PORT,0); {
case3: if(flagl) gets(ch); click(6);
do break: if(flag)
l case 7i / /sTvLET break;//COESTO MAIN
i=0;v=1; / /STYLE3 d<r 1
do l <170)&&y1>252)&&y1<272)
if(((x1>70&&x1
I t=0; I
i=i+v; for(i=129;j<s;i=((i+(3.j))/2)) click(7);
outport(PORT,i); { if(flag)
v--v*2; outport(PORT,i); break;//GOESTO MAIN
if(bioskey(1))//EXITSIF A KEY IS PRESSED if(bioskey(l))//EXITS IF A KEY IS PRESSED l
I I >252)&&y1<272)
if(((x1>270&&x1<370)&&yl
flagl=1; flag1=1; {
break; breaki click(8);
I l if(flag)
delay(glow_delay); delay(glow_delay); break;,/,/COES TO MAIN
if(i==255) if(j==21 I
I i=4; if(((x1>470&&xl
<570)&&y1
>252)&&y1
<272)
o=128; else click(9);
do j*t; I
{ ) l
outport(PORT,i); outport(PORT,O);
i=i-oi glow_num--; void mainO
o=o/2) Iwhile(glow_num>0); l
if&ioskey(1))//EXITS IF A KEY IS PRESSED if(fla91)gets(ch); initialise0;
{ break; while(1)
flagl=l; case 8l //STYLE 8 {
break; do menut),
I I c@rdinates0;
delay(glow_delay); for(i=3,i<=192;i=it2) flag=9;
Iwhile(i>=1); { I
l outport(PORT,i); ).
)while(i<-255); if(bioskey(1))//EXITSIF A KEY IS PRESSED