HI, can anyone help me with the below code snippet :-
;; now toggle the appr. DOUT LED
movf TMP3, W ; button number has been saved in TMP3. This is also the LED number
IFCLR TMP4, 0, call MIOS_DOUT_PinSet1 ; if button has been pressed (value = 0V = CLR): LED on
IFSET TMP4, 0, call MIOS_DOUT_PinSet0 ; if button has been depressed (value = 5V = SET): LED off
;; thats all
return
As coded the led will not latch. How do i code it to get the led to latch, i.e. when button is pressed (0V) led lights up. When button is released (5V) led is still lit. On next button press (0V) led is off and so on.
this snippet works with some temporary registers which have been preinitialized before. So, it won’t work in another context.
However, toggling a LED is quite easy. Just get the DOUT pin status, invert it, and write it back whenever the button has been pressed.
Example:
;; --------------------------------------------------------------------------
;; This function is called by MIOS when an button has been toggled
;; Input:
;; o Button number in WREG and MIOS_PARAMETER1
;; o Button value MIOS_PARAMETER2:
;; - 1 if button has been released (=5V)
;; - 0 if button has been pressed (=0V)
;; --------------------------------------------------------------------------
USER_DIN_NotifyToggle
;; exit if button has been depressed
IFSET MIOS_PARAMETER2, 0, return
;; store button number in TMP1
movff MIOS_PARAMETER1, TMP1
;; toggle LED which corresponds to the button number
movf TMP1, W ; button/LED number in TMP1
call MIOS_DOUT_PinGet ; get LED status
xorlw 0xff ; invert status
movwf MIOS_PARAMETER1 ; store new status in MIOS_PARAMETER1
movf TMP1, W ; button/LED number in TMP1
call MIOS_DOUT_PinSet ; set new LED value (expects value in MIOS_PARAMETER1)
return