From: "Jean-Yves Avenard" <avenar_j@epita.fr>
Subject: Re: ML IR Question
Date: 13 Feb 1998 00:00:00 GMT
Message-ID: <34e3dfe0.0@isoit370.bbn.hp.com>
X-Disclaimer: All opinions expressed herein are of personal nature and do not reflect the opinion of third parties.
References: <34E0A7C7.EBCCAC08@club-internet.fr> <Pine.LNX.3.96.980212163939.3129A-100000@casal.upc.es>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Newsgroups: comp.sys.hp48


Hello.

I think that you are wrong... The only thing your program will do if it
follows your explanations, is just to turn on the IR led, it won't send any
nibbles.

First, you can't send just one nibble. At least a byte.

The IR can work in two modes:
The first mode allow you to control directly the LED (you turn it on or off)
The second one, is called RS232 mode. There's no difference with this mode
if you want to send a byte using the Wire connector, or the IR.

I think Julien, for what you want to do, is to use the second mode.
First turn off all interruptions (ST=0.15 or GOSBVL 01115)
If you don't turn off the interruptions, then you won't be able to control
the IR (the interruption handler will run, and will stop your program.)

Before sending the byte, you must configure first the I/O, and set the IR
mode in RS232 mode.
Here are the explanations on some bits:
in # 0011A:
Bit no:
0: If set, an IR interruption has just occured
1: If set, you allow the IR circuit to generate an interruption
2: If set you are in RS232 mode
3: If set, you are receiving infra-red

Set the bit 1 and the bit 2.

Now you have to control the RS232 mode, you do that using the #00110
address:
Bit no:
0: If set, will generate an interruption when you are receiving a character
1: If set, will generate an interruption when you have finished to receive a
character
2: If set, will generate an interruption when you have finished to send a
character
3: If set, then the wire is on.

You will have to clear all these bits (until you don't plan to manage the IR
by rewriting the interrupt handler)

In #00111, you find some informations on the RS232 read state:
Bit no:
0: If set, a character is present in the buffer (#00114)
1: If set, the HP is receiving a character
2: If set, an error has occured
3: Not used

Remarks: As soon as you read the buffer (in #00114) then the bit 0 wil be
clear.
To clear the bit 2, you use the address # 00113 (see below)

In #00112, you find some informations on the RS232 write state:
Bit no:
0: If set, a character is still in the sending buffer  (#00116)
1: If set, the HP is sending the character.
2: not used
3: not used

Remarks: The bit 0 will be clear, when you write a character in the sending
buffer
This bit will be clear, as soon as the character was effectively send.

In #00113h, if you write any nibble there, then you will clear the bit 2 in
#00111

Incoming buffer: #00114: You will find the character you want to receive
Sending buffer : #00116: you will write here the character you want to send.

Well, here you have all the informations to use the I/O. I found all this
information in the excellent book:
Voyage au centre de la HP48GX by Paul Courbis. Anyway, in this book there
are some mistakes, and the informations you find here are correct.

Well, an example in always better than theory.
Here is a short ML program, to send a data using the IR, and an other one,
the receive a character.

First, you will have to open the IO. For my point of view, the best way (and
the shortest) to do that, is to call the RPL command OPENIO, just before
your program.
Don't worry if you are in Wire or IR mode, because the ML program will set
the speed and the mode.
Also, I will set up the connection of the IR to 7500bps, which is the
fastest speed you can use with the IR. The normal XMIT command can't exceed
2400bps

Well:
Here is the initialization program: I used the MetaKernel ML, or the HPASM
(which you find in the ADS (even if I wrote it...))
We assume that you call OPENIO before this program:
*INIT
% We close the IO before setting the speed
D0= 00110
C=0 B
DAT0=C B
%We set the IO to use the IR
D0= 1A
LC 4    %to set the bit 2 in 0011A
DAT0=C B
% Now we will set the speed to 7500bps
D0= 0010D
LC 5
A=DAT0 B
?ABIT=0.3
GOYES S1.INIT
CBIT=1.3 %We mustn't change the bit 3, in 0010D
*S1.INIT
DAT0=C 1
%We will open the IO
D0= 10
LC 88
DAT0=C B
RTNCC %WE EXIT, THE INITIALIZATION IS FINISH

*SENDBYTE
%THIS SUBROUTINE, WILL SEND THE CHARACTER IN A FIELD B
% NOW WE WILL WAIT UNTIL THE CIRCUIT IS READY TO SEND
D1= 00112
*B1.SENDBYTE
C=DAT1 B
?CBIT=1 1 %IS THE HP IS SENDING A PREVIOUS CHARACTER?
GOYES B1.SENDBYTE %YES? THEN WAIT
% NOW WE SEND THE CHARACTER ! AT LEAST...
D1= 16
DAT1= A B
% WE WILL TURN ON THE SEND INDICATOR
D1= 0B
C=DAT1 B
CBIT=1 5
DAT1=C B
D1= 12
*B2.SENDBYTE
C=DAT1 B
?CBIT=1 1 %IwE WAIT UNTIL THE CHARACTER WAS EFFECTIVELY SEND
GOYES B2.SENDBYTE %YES? THEN WAIT
%NOW WE TURN OFF THE SEND INDICATOR:
D1= 0B
C=DAT1 B
CBIT=0 5
DAT1=C B
RTNCC %THAT'S ALL FOLKS...

*READBYTE
%this sub-program will wait for a character, and will return it in the
register A field B and we clear the carry
%if everything is fine, if the carry is set, an error has occured.
ST=0 0 %To know if an error has occured
*B1.READBYTE
%now we check if an error has occured:
D1= 00111
C=DAT1 B
?CBIT=0 2
GOYES S1.READBYTE  %ooops, there was an error
%WE WILL CLEAR THE ERROR BIT FLAG
D1= 13
LC F
DAT1=C 1
D1= 11
C=DAT1 B
ST=1 0
*S1.READBYTE
D1= 11
C=DAT1 B
?CBIT=0 0
GOYES B1.READBYTE %Nothing to read
D1= 14
A=DAT1 B %We read the byte in the buffer..
?ST=1 0
RTNYES %Finish
RTNCC

Well, as you can see, it's not too difficult, as soon as you have the good
information.
The main problem of these programs, is that you have to wait until you have
really something to read, or to write. It means, that you can't do something
else while you are waiting for a character.

It is quite easy to fix that.
Before calling the SENDBYTE program, just check if the bit 0 in #00112 is
clear. If yes, you can write a character
Before calling the READBYTE program, check if the bit 0 in #00111 is set. It
means , a character is waiting for you.

Anyway, the best way to manage the IO, is to rewrite the Interrupt handler.
It will be as multi-tasking. You can do whatever you want, without any
problems, and don't have to check quite often if a character is effectively
here.


Hope you will find here all the information you need.
Otherwise, just post in this group, it will be a pleasure to help you

Jean-Yves
Proud member of MDG


Victor Achiaga wrote in message ...
>On Tue, 10 Feb 1998, Julien MEYER - SunHP wrote:
>
>> Hi,
>>
>> I need some help in order to transfer by IR a number "quartet"..
>  Emission infra-rouge, c'est a la memoire vive a l'adresse #0011Ch
>bit 0 a 1 Le buffer IR (#0011Dh) est plein
>    1 a 1 Le circuit est occupe a transmettre
>    2 a 1 Autorise les interruptions buffer vide
>    3 a 1 Allume l diode d'emision
>Pour emettre il faut donc ecrire le 1ere quartet au buffer #0011Dh
>et allumer le bit 3 de l'adresse 0011Ch
>Ateindre a la fin d'emision et paser au suivante.
>

