Jump to content

MIDIO128 - help with toggle code in DIN


Recommended Posts

Hi

I'm new to MIOS and it's a long time since I've worked with any assembler but it's great fun.

I'm trying to develop code so that the MIDI command sent by a button will always act in the opposite sense to it's corresponding DOUT.  This is so the MIDI software on a PC (Miditzer) will get an off code when the DOUT is active and vice versa.  The DOUTs will be controlled from the PC and not using FORWARDIO

I have three questions if someone would be kind enough to answer them.

1)  When I get the state of a DOUT with MIDIO_DOUT_Get and it returns zero, does that mean that the DOUT pin is at 0V or is it in the non-active state (as defined in the .ini file, which could be 5V if invert is enabled)?

2)  What variable holds the invert flag if I need to take it into account?

3)  I lifted the code that gets the DIN status from another section on the MIDIO128 code.  Is this piece of code the one to use?

Also, my congratulations on the quality of the code.  I use it as an example for my students of high qualty internal documentation.

Thanks

Graham

Here is my code so far:

MIDIO_DIN_Toggle
	;; when on: toggle between 0x00 and the DIN value defined in dump
	;; when off: send nothing
	IFSET	TMP1, 0, rgoto MIDIO_DIN_NotifyChangeEnd

	;; get the state of the DOUT corresponding to the current DIN
	movf	MIDIO_CURRENT_DIN, W
	call	MIDIO_DOUT_Get
	movwf	TMP1

	;; TMP1 will now be 0 or non-zero depending on state of DOUT
	;; I'm not sure which way around it is

	;; get DIN status
	call	MIDIO_FSR_DINValue
	movff	MIDIO_CURRENT_DIN, WREG
	call	MIOS_HLP_GetBitORMask
	andwf	INDF0, W

	;; W will now be 0 if the DIN will send an ON command
	;; when it gets to MIDIO_DIN_Send

	iorlw	TMP1

	;; W now holds 0 if the values are the both 0
	;; so the next statement may be bnz rather than bz - not sure which
	;; If an OFF DOUT returns zero then we need bz to turn it on.
	;; we may also need to consider whether any INVERT flags are set by the .ini file
      ;; or whether the DOUT_Get takes that into account.

	bz MIDIO_DIN_Send			; skip the toggle

	;; toggle appr. bit in DIN_VALUE register
	call	MIDIO_FSR_DINValue
	SET_BSR	MIDIO_BASE
	movf	MIDIO_CURRENT_DIN, W, BANKED
	call	MIOS_HLP_GetBitORMask
	xorwf	INDF0, F


MIDIO_DIN_Send

Link to comment
Share on other sites

Hi Graham,

1)  When I get the state of a DOUT with MIDIO_DOUT_Get and it returns zero, does that mean that the DOUT pin is at 0V or is it in the non-active state (as defined in the .ini file, which could be 5V if invert is enabled)?

DOUTs are high-active (5V: LED on, 0V: LED off), buttons are low-active (5V: button depressed, 0V: button pressed).

So, yes: for DOUTs a 0 means that the LED is off

2)  What variable holds the invert flag if I need to take it into account?

For DOUT its the flag: MIDIO_CFG0, MIDIO_CFG0_INVERSE_DOUT

For DIN: MIDIO_CFG0, MIDIO_CFG0_INVERSE_DIN

3)  I lifted the code that gets the DIN status from another section on the MIDIO128 code.  Is this piece of code the one to use?

Yes, it's the right location. After you've copied the new value into TMP1, it should be ok to branch to MIDIO_DIN_OnOff (or to duplicate the "rcall MIDIO_DIN_Hlp_SaveStat" and "rgoto MIDIO_DIN_Send").

SaveStat stores the new value into the MIDIO_DIN_VALUES array, and MIDO_DIN_Send will send the MIDI event

Best Regards, Thorsten.

Link to comment
Share on other sites

Thanks so much Thorsten.

If I understand correctly the code below is what I need.

Regards

Graham

MIDIO_DIN_Toggle
	;; when on: toggle between 0x00 and the DIN value defined in dump
	;; when off: send nothing
	IFSET	TMP1, 0, rgoto MIDIO_DIN_NotifyChangeEnd

	;; get the state of the DOUT corresponding to the current DIN
	movf	MIDIO_CURRENT_DIN, W
	call	MIDIO_DOUT_Get
	movwf	TMP1

	;; save new status of DIN and send
	rcall	MIDIO_DIN_Hlp_SaveStat
	rgoto	MIDIO_DIN_Send

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...