Jump to content

Flashing Led


Recommended Posts

humm I think it will use more RAM... the simple is to make a flip-flop : a very easy schematic (2 NAND gate, a resistor and a caps) wich make blinking. But with Mios, you have to know when you light the led (or not), if : it has to be light... so you would have another bit of ram for each blinking led....

By the way, I think it's AN EXCELLENT IDEA! so I'm going to try with as soon as I can!!! ;D

Link to comment
Share on other sites

The problem is certainly not the RAM, I think. More the question is, if there's a free timer Interrupt left in the PIC. And the only man who can answer this is... tadaaaaa.... Thosrsten!!

So, what do you say, TK?

Link to comment
Share on other sites

Just use the USER_SR_Service_Prepare hook which is called periodically before the DOUT registers are loaded. The update frequency is 1 mS by default.

Example:

in app_defines.h following variables have to be assigned to free addresses:

DOUT_LED_CTR - a counter which will be incremented on every update cycle

DOUT_LED_FLASH_ENABLE - this register holds the information if the LED should flash or not. Up to 8 flags for 8 LEDs can be stored here, if more flags are required, an array should be used (not shown here)

Code (untested, but should work)

USER_SR_Service_Prepare
LED_FLASH_Handler
      ;; increment counter
      incf      DOUT_LED_CTR, F

      ;; skip next block if LED should not flash
      IFCLR      DOUT_LED_FLASH_ENABLE, 0, rgoto LED_FLASH_Handler_Skip0
      ;; skip if DOUT counter < 128 (bit #7 not set), this leads to a
      ;; flashing frequency of 1 / (128 * update_cycle) = 1 / (128 * 1 mS) = ca. 8 Hz
      IFCLR      DOUT_LED_CTR, 7, rgoto LED_FLASH_Handler_Skip0
      ;; get value of LED at DOUT #0
      movlw      0x00
      call      MIOS_DOUT_PinGet
      ;; result in MIOS_PARAMETER1, invert it
      comf      MIOS_PARAMETER1, F
      ;; write back result to DOUT #0
      movlw      0x00
      call      MIOS_DOUT_PinSet
LED_FLASH_Handler_Skip0

      ;; thats all
      return

Best Regards, Thorsten.

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