Multi-Threading


Results 1 to 23 of 23

Thread: Multi-Threading

Threaded View

  1. #5
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Read and understand

    Hi,

    If you look at the second post in this thread :

    http://www.picbasic.co.uk/forum/show...stant+interupt

    you will see a code snippet that ALMOST does what you want to do. It has a main loop where it is just performing a pause and then a timer is setup to toggle the led.

    This is very close to what you are asking for.. just enable the interupt before entering your task (so the led will start to flash) and when you exit your task disable it again.

    If you change the preloaded value (and prescaler if you have to) for the timer you can have different fast flashing led depending what task you are performing...


    This is not difficult because of the EXCELLENT code provided by DT.


    Code:
    LED1   VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    
    
    goto main
    
    my_task:
    T1CON = $31                ; Prescaler = 8, TMR1ON to desice how fast we will flash
    
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    ;do all the stuff you want to do here
    
    @ INT_DISABLE  TMR1_INT     ; DISABLE Timer 1 interrupts
    
    RETURN
    
    
    Main:
      GOSUB my_task 
      PAUSE 10
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    This might ( I didn't compile and test it, and I am not sure if it is the right register for your PIC) work and should flash the LED while you are performing my_task only.. just remember if my_task is very fast you might come out of it before we flash since the LED is flashing once per sec or something now.

    also we will go back to my_task every 10 sek... but what you do in your main loop I leave to you to decide.

    /me
    Last edited by Jumper; - 10th August 2008 at 16:50.

Similar Threads

  1. Multi Slow speed PWM and Instant Interrupts
    By DaveC3 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2010, 12:50
  2. multi functions button press
    By malwww in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th May 2009, 00:12
  3. 16-48 pin Multi slow PWM
    By krohtech in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th March 2009, 03:28
  4. Multi diomencinal array
    By morphyn in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th February 2009, 21:19
  5. parallel port multi pic programmer?
    By SuB-ZeRo in forum Schematics
    Replies: 8
    Last Post: - 25th June 2005, 10:20

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts