How do I read from LPT1? 
Author Message
 How do I read from LPT1?

Morning,
    I am looking into building something to interface with a standard
parallel port, and I'm planning to use QB4.5 to read from it, I know
the port is at 378h, so I assume I can use a% = INP(&H378) to read a
byte from it. How do I then interpret the byte though?
Can I use something as simple as;
IF a% = 01100100 THEN PRINT "A"
if a% = 10010001 THEN ...?

The aim is to have a few buttons connected to the port (not more than
8) and to evaluate which are pressed and which are not at the time of
reading the port. (Can I make the port read the switches
electronically, or does it have to be a programming instruction?)

Thanks for your help,
Simon.



Sun, 15 Oct 2000 03:00:00 GMT  
 How do I read from LPT1?



Quote:
> Morning,
>     I am looking into building something to interface with a
standard
> parallel port, and I'm planning to use QB4.5 to read from it, I
know
> the port is at 378h, so I assume I can use a% = INP(&H378) to read
a
> byte from it. How do I then interpret the byte though?
> Can I use something as simple as;
> IF a% = 01100100 THEN PRINT "A"
> if a% = 10010001 THEN ...?

The port will give you a number from 0 to 255 not the actual binary
number. I'm not sure how to convert them into numbers (i.e 10011010,
etc) as I have had no need for that.  I did manage to send data out
through the port to light light up bulbs and work motors but I
suppose that doesn't help much.

I hope you succeed with your project.

Benjamin

*"If you try to fail and succeed, what have you done?"

* apologies to whomever I stole that from.



Mon, 16 Oct 2000 03:00:00 GMT  
 How do I read from LPT1?



Quote:
> Morning,
>     I am looking into building something to interface with a
standard
> parallel port, and I'm planning to use QB4.5 to read from it, I
know
> the port is at 378h, so I assume I can use a% = INP(&H378) to read a
> byte from it. How do I then interpret the byte though?
> Can I use something as simple as;
> IF a% = 01100100 THEN PRINT "A"
> if a% = 10010001 THEN ...?

No BASIC that I know supports binary constants.

You can use
  a% = INP(&H379)
  IF a% AND 128 THEN PRINT "Bit 7 is set."
  IF a% AND 64 THEN PRINT "Bit 6 is set."
  IF a% AND 32 THEN PRINT "Bit 5 is set."
  IF a% AND 16 THEN PRINT "Bit 4 is set."
  IF a% AND 8 THEN PRINT "Bit 3 is set."

If the printer data port is at 378h, (that's one of three base addresses) the
printer status port is at 379h.  In a standard printer port, the data port is
write-only and the status port is read-only.  INP &H379 will return a number in
the range 0..255, but only the 5 most-significant bits are actually connected
to pins on the 25-pin connector:
  bit   pin
    7    11
    6    10
    5    12
    4    13
    3    15
These inputs expect TTL levels; nothing below ground or above 5 volts.  An
input left floating _may_ float high, but to get predictable results, make sure
that any input is either grounded or pulled high.  Optical isolators or relays
are cheap insurance.

If it's spam, it's a scam.  Don't do business with Net abusers.



Mon, 16 Oct 2000 03:00:00 GMT  
 How do I read from LPT1?


Quote:


>> Morning,
>>     I am looking into building something to interface with a
>standard
>> parallel port, and I'm planning to use QB4.5 to read from it, I
>know
>> the port is at 378h, so I assume I can use a% = INP(&H378) to read a
>> byte from it. How do I then interpret the byte though?
>> Can I use something as simple as;
>> IF a% = 01100100 THEN PRINT "A"
>> if a% = 10010001 THEN ...?

>No BASIC that I know supports binary constants.

Several BASIC flavours do, but the Microsoft BASIC's don't appear to
support it. In powerbasic for instance, you can use something like this:

IF A%=&B00101010 then...
--
Marc van den Dikkenberg
-----------------------
The PowerBasic Archives
http://www.xs4all.nl/~excel/pb.html



Mon, 16 Oct 2000 03:00:00 GMT  
 How do I read from LPT1?


Quote:
>In PowerBasic for instance, you can use something like this:

>IF A%=&B00101010 then...

Thanx.  Yet another reason to move to PB as soon as I can afford it.

If it's spam, it's a scam.  Don't do business with Net abusers.



Mon, 16 Oct 2000 03:00:00 GMT  
 How do I read from LPT1?

Quote:
> >     I am looking into building something to interface with a
> > standard parallel port...
> The port will give you a number from 0 to 255 not the actual binary
> number. I'm not sure how to convert them into numbers (i.e 10011010,
> etc) as I have had no need for that.  I did manage to send data out
> through the port to light light up bulbs and work motors but I
> suppose that doesn't help much.

Thanks for your replies, (especially Benjamin Hayhurst(?)) I have now
successfully figured out what I wanted to do.

In case anyone else is interested, I found that I needed a
Bi-directional port to read from the data pins, and should use the
following (In QBasic);

OUT &H37A, 0        'Clears control registers
OUT &H37A, 32       'Sets Control Bit 5 to enable reading from the port
a% = INP(&H378)    
REM 'a%' will then contain the values on the data pins in the format
REM explained by Mr Hayhurst.

(With just a standard port (SPP) You can have 5 inputs from the
status pins anyway)
Use these three lines everytime you need to read from the port.

Simon.



Wed, 18 Oct 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Reading data coming in through LPT1

2. Read data from LPT1 as like LL3.exe

3. Read port LPT1:

4. Read memory on LPT1

5. Read port LPT1:

6. read byte from lpt1

7. Need help to read LPT1 pins from a VB app

8. Read from LPT1 in VB

9. how do i write/read to/from LPT1

10. reading spikes or is the os doing it (jinu)

11. reading binary files, can't be done

12. reading spikes or is the os doing it (jinu)

 

 
Powered by phpBB® Forum Software