I just completed the electronics to my first MIOS project. ;D ;D ;D It is a controller for NI B4 organ. I used the AIN 64 DIN 128 DOUT128 program as an example for my MIOS programming. All is fine with the exection of button functioning. How do you set the button mode to toggle in MIOS. If anyone can post an example of how to change that for me I would great;y appreciate the help.
you have to store the button state in a register, it has to be inverted every time the button is pressed.
Possible modification for the AIN64_DIN128_DOUT128 application (untested) - replace
USER_DIN_NotifyToggle
;; a button has been pressed or depressed.
;; Send value which has been defined in MIOS_MPROC_EVENT_TABLE
;; save button number in TMP3 - we use it later to print out a message
movff MIOS_PARAMETER1, TMP3
;; save button value in TMP4
movff MIOS_PARAMETER2, TMP4
by:
USER_DIN_NotifyToggle
;; a button has been pressed or depressed.
;; Send value which has been defined in MIOS_MPROC_EVENT_TABLE
;; don't continue if button has been depressed
IFSET MIOS_PARAMETER2, 0, return
;; toggle button state
btf BUTTON_STATE, 0
;; save button number in TMP3 - we use it later to print out a message
movff MIOS_PARAMETER1, TMP3
;; save button value in TMP4
movff BUTTON_STATE, TMP4
the BUTTON_STATE variable has to be located to a free address in app_defines.h If you want to use more than one toggle button, you could store up to 8 states in this register:
USER_DIN_NotifyToggle
;; a button has been pressed or depressed.
;; Send value which has been defined in MIOS_MPROC_EVENT_TABLE
;; don't continue if button has been depressed
IFSET MIOS_PARAMETER2, 0, return
;; save button number in TMP3 - we use it later to print out a message
movff MIOS_PARAMETER1, TMP3
;; toggle state of button 0 to 7
movf MIOS_PARAMETER1, W ; get button number
call MIOS_HLP_GetBitORMask ; get mask - here for XOR (invert) function
xorwf BUTTON_STATE, F ; invert the appr. flag
;; set TMP4 (the button value) depending on flag
setf TMP4 ; by default it's set (0x00 will be sent)
movf MIOS_PARAMETER1, W ; get button number
call MIOS_HLP_GetBitANDMask ; get AND mask
andwf BUTTON_STATE, W ; mask out the appr. flag
skpz ; skip if flag is zero
clrf TMP4 ; else clear TMP4 (0x7f will be sent)
More than 8 buttons w/ toggle function can be realized with an array. And if you want to select the toggle function, you need to add a “enable” flag. However, the upcoming migrated MIDIbox64 application will support this on a more comfotable way
or any free location correct. I am really not a programmer, but I figure that I can figure out a little. Let me know if I am correct or incorrect. Thanks, and you are brilliant TK. By the way how long before MB 64 is converted to MIOS?
yes, thats correct. But you should use capitalized letters for all constants (register names), just for consistency reasons.
Migration of MB64: I’m unsure, although it wouldn’t take longer than one day, it’s just a low-priority task for me. It could happen in one week or in one month…
you have to insert a blank (space or tab character) before the “btg” instruction, otherwise the assembler assumes that “btg” is a label and “BUTTON_STATE” the instruction.