Jump to content

How to code "IF BIGGER, THEN..." ?


mb944
 Share

Recommended Posts

Hello midiboxers!

I am really getting envolved in midiboxing and having enjoyed all the physical hardware developement side of it,

I'm having some fun with Coding.

What I am triying to do here is to Light a red led when an encoder approaches its maximum absolute value (above 100).

I am using enc_example2_v1_3  as a skelletton for my little project.

I noticed that Just before sending the encoder value (third midi byte), MIOS moves it from TMP1 to W

I assumed I could insert my code here and compare W with the WARNING_LEVEL...

Here's what I'm wrote:

;; send the third MIDI byte

movf TMP1, W ; value from 0x00 to 0x7f

movlw 0x64 ; ABOVE THIS VALUE,LIGHT WARNING LED

movwf WARNING_LEVEL

movf TMP1, W ; value from 0x00 to 0x7f

CPFSGT WARNING_LEVEL; COMPARE ENCODER VALUE WITH WARNING_LEVEL

movlw 0x14

CALL MIOS_DOUT_PinSet1; LIGHT WARNING LED

Call MIOS_MIDI_TxBufferPut

At the moment, PINSET1 is being called every time I move the encoder.

Can I make CPFSGT skip two lines? Better still, can I use something like:

IF w>100 then

movlw 0x14

CALL MIOS_DOUT_PinSet1

end if

Thanks for any suggestions!

Best regards,

Alex

Link to comment
Share on other sites

     CPFSGT WARNING_LEVEL; COMPARE ENCODER VALUE WITH WARNING_LEVEL
     goto No_Warning
     movlw   0x14
     CALL MIOS_DOUT_PinSet1; LIGHT WARNING LED
No_Warning
     Call   MIOS_MIDI_TxBufferPut

I think this works...

Link to comment
Share on other sites

The 'skip' instructions only skip the next instruction, so you were only skipping "movlw   0x14" :)

You could probably also do something like:

CPFSGT WARNING_LEVEL; COMPARE ENCODER VALUE WITH WARNING_LEVEL

CALL USER_WARNING_LED; LIGHT WARNING LED SUBROUTINE

CALL MIOS_MIDI_TxBufferPut

And have

;; --------------------------------------------------------------------------

;;  FUNCTION: USER_WARNING_LED

;;  DESCRIPTION: Lights the warning LED

;;  IN: -

;;  OUT:  -

;;  USES: W

;;

;; --------------------------------------------------------------------------

USER_WARNING_LED

     movlw   USER_WARNING_LED0_PIN ; Set Warning LED Pin Value

     CALL MIOS_DOUT_PinSet1; LIGHT WARNING LED

     RETURN

Included elsewhere. Don;t forget to define USER_WARNING_LED0_PIN somewhere too.

Makes it usable in other areas of code, more modular, etc...

Of course if you want more than one warning LED it may be better to pass the values of the pins prior to calling subroutine, like you did it...

It's 4:30am and I am very very tired, I hope I haven't missed something here heheheh  :)

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