Jump to content

Setting Buttton to Toggle mode in MIOS


Recommended Posts

Hi everyone,

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.

Link to comment
Share on other sites

Hi Jeroddumas,

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 :)

Best Regards, Thorsten.

Link to comment
Share on other sites

So Thorston I would enter in app_define.h

Button_state      equ   0x010

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?

Link to comment
Share on other sites

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...

Best Regards, Thorsten.

Link to comment
Share on other sites

Okay Thorston two problems here, if you can help.  First on the one button toggle,  I cannot get the build to work MBLAB comes badck with this error:

Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p18F452 "main.asm" /l"main.lst" /e"main.err"

Error[122]   C:\WINDOWS\DESKTOP\MY MIOS PROJECTS\COPY OF AIN64_DIN128_DOUT128_V1_1\AIN64_DIN128_DOUT128_V1_1\MAIN.ASM 230 : Illegal opcode (BUTTON_STATE)

Halting build on first failure as requested.

BUILD FAILED

The second example builds fine, but the buttons don't toggle, they co to )) and stay there.  Thanks for your help.

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...