Discussion in "Project Help" started by    vinay    Sep 15, 2007.
Sat Sep 15 2007, 09:33 pm
#1
i got some code for device control. here i am not able to crck some code,can u plz help me
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#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;


i cant understand that bolded coded. can u plaese help
Sat Sep 15 2007, 11:55 pm
#2
Well it seems simple.. I hope i am correct.. and if i am not please correct me..

gotoxy(9,8);
val=(val&0x01)?(val&(~0x01)):val|0x01;
str=(val&0x01)?str1:str2;
printf("%s",str);

This part of code is to display the status of device.. either of or on.. and the first instruction is to set or clear the value..
i mean it checks if its set, then clear it.. if its 0 then make it 1.
because the part of code...
 val=(val&0x01)?(val&(~0x01)):val|0x01;

can also be written as..
if(val&0x01)
     val = val&(~0x01);
else
     val = val|0x01;


and after that this value will be sent to the parallel port... as well as displayed on the screen
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;

Hope you understood..
Sun Sep 16 2007, 01:12 am
#3
i had used these codes before 0x01 is for LSB bit 1 (D0)of parallel port (DB25) ie pin 2 , 0x02 for D1, 0x04 for D2, 0x08 for D3 and so on upto D7 (ie bit 8 of parallel port pin no 9) :-)

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am